summaryrefslogtreecommitdiff
path: root/spec/lib/bulk_imports/importers/group_importer_spec.rb
blob: b4fdb7b5e5b871d9b914a380d4a5347c2098d09d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe BulkImports::Importers::GroupImporter do
  let(:user) { create(:user) }
  let(:group) { create(:group) }
  let(:bulk_import) { create(:bulk_import) }
  let(:bulk_import_entity) { create(:bulk_import_entity, :started, bulk_import: bulk_import, group: group) }
  let(:bulk_import_configuration) { create(:bulk_import_configuration, bulk_import: bulk_import) }
  let(:context) { BulkImports::Pipeline::Context.new(bulk_import_entity) }

  before do
    allow(BulkImports::Pipeline::Context).to receive(:new).and_return(context)
  end

  subject { described_class.new(bulk_import_entity) }

  describe '#execute' do
    it 'starts the entity and run its pipelines' do
      expect_to_run_pipeline BulkImports::Groups::Pipelines::GroupPipeline, context: context
      expect_to_run_pipeline BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline, context: context
      expect_to_run_pipeline BulkImports::Groups::Pipelines::MembersPipeline, context: context
      expect_to_run_pipeline BulkImports::Groups::Pipelines::LabelsPipeline, context: context

      if Gitlab.ee?
        expect_to_run_pipeline('EE::BulkImports::Groups::Pipelines::EpicsPipeline'.constantize, context: context)
        expect_to_run_pipeline('EE::BulkImports::Groups::Pipelines::EpicAwardEmojiPipeline'.constantize, context: context)
      end

      subject.execute

      expect(bulk_import_entity.reload).to be_finished
    end

    context 'when failed' do
      let(:bulk_import_entity) { create(:bulk_import_entity, :failed, bulk_import: bulk_import, group: group) }

      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
  end

  def expect_to_run_pipeline(klass, context:)
    expect_next_instance_of(klass, context) do |pipeline|
      expect(pipeline).to receive(:run)
    end
  end
end