2021-01-29 00:20:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe BulkImports::Importers::GroupImporter do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:bulk_import) { create(:bulk_import) }
|
2021-03-08 18:12:59 +05:30
|
|
|
let(:bulk_import_entity) { create(:bulk_import_entity, :started, bulk_import: bulk_import) }
|
2021-01-29 00:20:46 +05:30
|
|
|
let(:bulk_import_configuration) { create(:bulk_import_configuration, bulk_import: bulk_import) }
|
|
|
|
let(:context) do
|
|
|
|
BulkImports::Pipeline::Context.new(
|
|
|
|
current_user: user,
|
|
|
|
entity: bulk_import_entity,
|
|
|
|
configuration: bulk_import_configuration
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.new(bulk_import_entity) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(BulkImports::Pipeline::Context).to receive(:new).and_return(context)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#execute' do
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'starts the entity and run its pipelines' do
|
2021-01-29 00:20:46 +05:30
|
|
|
expect_to_run_pipeline BulkImports::Groups::Pipelines::GroupPipeline, context: context
|
2021-03-08 18:12:59 +05:30
|
|
|
expect_to_run_pipeline('EE::BulkImports::Groups::Pipelines::EpicsPipeline'.constantize, context: context) if Gitlab.ee?
|
2021-01-29 00:20:46 +05:30
|
|
|
expect_to_run_pipeline BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline, context: context
|
|
|
|
|
|
|
|
subject.execute
|
|
|
|
|
|
|
|
expect(bulk_import_entity.reload).to be_finished
|
|
|
|
end
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
context 'when failed' do
|
|
|
|
let(:bulk_import_entity) { create(:bulk_import_entity, :failed, bulk_import: bulk_import) }
|
|
|
|
|
|
|
|
it 'does not transition entity to finished state' do
|
|
|
|
allow(bulk_import_entity).to receive(:start!)
|
|
|
|
|
|
|
|
subject.execute
|
|
|
|
|
|
|
|
expect(bulk_import_entity.reload).to be_failed
|
|
|
|
end
|
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def expect_to_run_pipeline(klass, context:)
|
|
|
|
expect_next_instance_of(klass) do |pipeline|
|
|
|
|
expect(pipeline).to receive(:run).with(context)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|