Welcome to mirror list, hosted at ThFree Co, Russian Federation.

relation_export_worker_spec.rb « bulk_imports « workers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f91db0388a41a39675a863d114def91ba9f23858 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe BulkImports::RelationExportWorker, feature_category: :importers do
  let_it_be(:jid) { 'jid' }
  let_it_be(:user) { create(:user) }
  let_it_be(:group) { create(:group) }

  let(:batched) { false }
  let(:relation) { 'labels' }
  let(:job_args) { [user.id, group.id, group.class.name, relation, batched] }

  describe '#perform' do
    include_examples 'an idempotent worker' do
      context 'when export record does not exist' do
        let(:another_group) { create(:group) }
        let(:job_args) { [user.id, another_group.id, another_group.class.name, relation, batched] }

        it 'creates export record' do
          another_group.add_owner(user)

          expect { perform_multiple(job_args) }
            .to change { another_group.bulk_import_exports.count }
            .from(0)
            .to(1)
        end
      end

      shared_examples 'export service' do |export_service|
        it 'executes export service' do
          group.add_owner(user)

          service = instance_double(export_service)

          expect(export_service)
            .to receive(:new)
            .with(user, group, relation, anything)
            .twice
            .and_return(service)
          expect(service).to receive(:execute).twice

          perform_multiple(job_args)
        end
      end

      context 'when export is batched' do
        let(:batched) { true }

        context 'when bulk_imports_batched_import_export feature flag is disabled' do
          before do
            stub_feature_flags(bulk_imports_batched_import_export: false)
          end

          include_examples 'export service', BulkImports::RelationExportService
        end

        context 'when bulk_imports_batched_import_export feature flag is enabled' do
          before do
            stub_feature_flags(bulk_imports_batched_import_export: true)
          end

          context 'when relation is batchable' do
            include_examples 'export service', BulkImports::BatchedRelationExportService
          end

          context 'when relation is not batchable' do
            let(:relation) { 'namespace_settings' }

            include_examples 'export service', BulkImports::RelationExportService
          end
        end
      end

      context 'when export is not batched' do
        include_examples 'export service', BulkImports::RelationExportService
      end
    end
  end
end