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 ...@@ -37,7 +37,7 @@ class Import::BulkImportsController < ApplicationController
end end
def create def create
response = BulkImportService.new(current_user, create_params, credentials).execute response = ::BulkImports::CreateService.new(current_user, create_params, credentials).execute
if response.success? if response.success?
render json: response.payload.to_json(only: [:id]) render json: response.payload.to_json(only: [:id])
......
...@@ -23,9 +23,10 @@ ...@@ -23,9 +23,10 @@
# - For each group to be imported (BulkImport::Entity.with_status(:created)) # - For each group to be imported (BulkImport::Entity.with_status(:created))
# - Import the group data # - Import the group data
# - Create entities for each subgroup of the imported group # - 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 attr_reader :current_user, :params, :credentials
def initialize(current_user, params, credentials) def initialize(current_user, params, credentials)
...@@ -67,4 +68,5 @@ class BulkImportService ...@@ -67,4 +68,5 @@ class BulkImportService
bulk_import bulk_import
end end
end end
end
end end
...@@ -51,7 +51,7 @@ module API ...@@ -51,7 +51,7 @@ module API
end end
end end
post do post do
response = BulkImportService.new( response = ::BulkImports::CreateService.new(
current_user, current_user,
params[:entities], params[:entities],
url: params[:configuration][:url], url: params[:configuration][:url],
......
...@@ -199,9 +199,9 @@ RSpec.describe Import::BulkImportsController do ...@@ -199,9 +199,9 @@ RSpec.describe Import::BulkImportsController do
session[:bulk_import_gitlab_url] = instance_url session[:bulk_import_gitlab_url] = instance_url
end end
it 'executes BulkImportService' do it 'executes BulkImpors::CreatetService' do
expect_next_instance_of( 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)) allow(service).to receive(:execute).and_return(ServiceResponse.success(payload: bulk_import))
end end
...@@ -214,7 +214,7 @@ RSpec.describe Import::BulkImportsController do ...@@ -214,7 +214,7 @@ RSpec.describe Import::BulkImportsController do
it 'returns error when validation fails' do it 'returns error when validation fails' do
error_response = ServiceResponse.error(message: 'Record invalid', http_status: :unprocessable_entity) error_response = ServiceResponse.error(message: 'Record invalid', http_status: :unprocessable_entity)
expect_next_instance_of( 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) allow(service).to receive(:execute).and_return(error_response)
end end
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe BulkImportService do RSpec.describe BulkImports::CreateService do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:credentials) { { url: 'http://gitlab.example', access_token: 'token' } } let(:credentials) { { url: 'http://gitlab.example', access_token: 'token' } }
let(:params) do 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