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

subgroup_entities_pipeline_spec.rb « pipelines « groups « bulk_imports « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e5a8ed7f47da51ea73ae416b30a62b7dc4063f42 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline do
  describe '#run' do
    let_it_be(:user) { create(:user) }
    let(:parent) { create(:group, name: 'imported-group', path: 'imported-group') }
    let!(:parent_entity) do
      create(
        :bulk_import_entity,
        destination_namespace: parent.full_path,
        group: parent
      )
    end

    let(:context) do
      instance_double(
        BulkImports::Pipeline::Context,
        current_user: user,
        entity: parent_entity
      )
    end

    let(:subgroup_data) do
      [
        {
          "name" => "subgroup",
          "full_path" => "parent/subgroup"
        }
      ]
    end

    subject { described_class.new }

    before do
      allow_next_instance_of(BulkImports::Groups::Extractors::SubgroupsExtractor) do |extractor|
        allow(extractor).to receive(:extract).and_return(subgroup_data)
      end

      parent.add_owner(user)
    end

    it 'creates entities for the subgroups' do
      expect { subject.run(context) }.to change(BulkImports::Entity, :count).by(1)

      subgroup_entity = BulkImports::Entity.last

      expect(subgroup_entity.source_full_path).to eq 'parent/subgroup'
      expect(subgroup_entity.destination_namespace).to eq 'imported-group'
      expect(subgroup_entity.destination_name).to eq 'subgroup'
      expect(subgroup_entity.parent_id).to eq parent_entity.id
    end
  end

  describe 'pipeline parts' do
    it { expect(described_class).to include_module(BulkImports::Pipeline) }
    it { expect(described_class).to include_module(BulkImports::Pipeline::Runner) }

    it 'has extractors' do
      expect(described_class.get_extractor).to eq(klass: BulkImports::Groups::Extractors::SubgroupsExtractor, options: nil)
    end

    it 'has transformers' do
      expect(described_class.transformers).to contain_exactly(
        { klass: BulkImports::Common::Transformers::ProhibitedAttributesTransformer, options: nil },
        { klass: BulkImports::Groups::Transformers::SubgroupToEntityTransformer, options: nil }
      )
    end

    it 'has loaders' do
      expect(described_class.get_loader).to eq(klass: BulkImports::Common::Loaders::EntityLoader, options: nil)
    end
  end
end