Commit 69086674 authored by Tetiana Chupryna's avatar Tetiana Chupryna

Merge branch 'jcunha-extrac-controller-logic-to-service' into 'master'

Move the BulkImportService to BulkImports::CreateService

See merge request gitlab-org/gitlab!71494
parents d002e7f3 05071f04
......@@ -37,7 +37,7 @@ class Import::BulkImportsController < ApplicationController
end
def create
response = BulkImportService.new(current_user, create_params, credentials).execute
response = ::BulkImports::CreateService.new(current_user, create_params, credentials).execute
if response.success?
render json: response.payload.to_json(only: [:id])
......
......@@ -23,9 +23,10 @@
# - For each group to be imported (BulkImport::Entity.with_status(:created))
# - Import the group data
# - Create entities for each subgroup of the imported group
# - Enqueue a BulkImportService job (Pn) to import the new entities (subgroups)
# - Enqueue a BulkImports::CreateService job (Pn) to import the new entities (subgroups)
#
class BulkImportService
module BulkImports
class CreateService
attr_reader :current_user, :params, :credentials
def initialize(current_user, params, credentials)
......@@ -67,4 +68,5 @@ class BulkImportService
bulk_import
end
end
end
end
......@@ -51,7 +51,7 @@ module API
end
end
post do
response = BulkImportService.new(
response = ::BulkImports::CreateService.new(
current_user,
params[:entities],
url: params[:configuration][:url],
......
......@@ -199,9 +199,9 @@ RSpec.describe Import::BulkImportsController do
session[:bulk_import_gitlab_url] = instance_url
end
it 'executes BulkImportService' do
it 'executes BulkImpors::CreatetService' do
expect_next_instance_of(
BulkImportService, user, bulk_import_params, { url: instance_url, access_token: pat }) do |service|
::BulkImports::CreateService, user, bulk_import_params, { url: instance_url, access_token: pat }) do |service|
allow(service).to receive(:execute).and_return(ServiceResponse.success(payload: bulk_import))
end
......@@ -214,7 +214,7 @@ RSpec.describe Import::BulkImportsController do
it 'returns error when validation fails' do
error_response = ServiceResponse.error(message: 'Record invalid', http_status: :unprocessable_entity)
expect_next_instance_of(
BulkImportService, user, bulk_import_params, { url: instance_url, access_token: pat }) do |service|
::BulkImports::CreateService, user, bulk_import_params, { url: instance_url, access_token: pat }) do |service|
allow(service).to receive(:execute).and_return(error_response)
end
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe BulkImportService do
RSpec.describe BulkImports::CreateService do
let(:user) { create(:user) }
let(:credentials) { { url: 'http://gitlab.example', access_token: 'token' } }
let(:params) do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment