2021-01-29 00:20:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline do
|
2021-04-17 20:07:23 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:group) { create(:group, path: 'group') }
|
|
|
|
let_it_be(:parent) { create(:group, name: 'imported-group', path: 'imported-group') }
|
2021-04-29 21:17:54 +05:30
|
|
|
let_it_be(:parent_entity) { create(:bulk_import_entity, destination_namespace: parent.full_path, group: parent) }
|
|
|
|
let_it_be(:tracker) { create(:bulk_import_tracker, entity: parent_entity) }
|
|
|
|
let_it_be(:context) { BulkImports::Pipeline::Context.new(tracker) }
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
subject { described_class.new(context) }
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
let(:extracted_data) do
|
|
|
|
BulkImports::Pipeline::ExtractedData.new(data: {
|
|
|
|
'name' => 'subgroup',
|
|
|
|
'full_path' => 'parent/subgroup'
|
|
|
|
})
|
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
describe '#run' do
|
2021-01-29 00:20:46 +05:30
|
|
|
before do
|
|
|
|
allow_next_instance_of(BulkImports::Groups::Extractors::SubgroupsExtractor) do |extractor|
|
2021-04-29 21:17:54 +05:30
|
|
|
allow(extractor).to receive(:extract).and_return(extracted_data)
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
parent.add_owner(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates entities for the subgroups' do
|
2021-03-11 19:13:27 +05:30
|
|
|
expect { subject.run }.to change(BulkImports::Entity, :count).by(1)
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe '#load' do
|
|
|
|
let(:parent_entity) { create(:bulk_import_entity, group: group, bulk_import: create(:bulk_import)) }
|
|
|
|
|
|
|
|
it 'creates entities for the given data' do
|
|
|
|
data = {
|
|
|
|
source_type: :group_entity,
|
|
|
|
source_full_path: 'parent/subgroup',
|
|
|
|
destination_name: 'subgroup',
|
|
|
|
destination_namespace: parent_entity.group.full_path,
|
|
|
|
parent_id: parent_entity.id
|
|
|
|
}
|
|
|
|
|
|
|
|
expect { subject.load(context, data) }.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 'group'
|
|
|
|
expect(subgroup_entity.destination_name).to eq 'subgroup'
|
|
|
|
expect(subgroup_entity.parent_id).to eq parent_entity.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
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
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(described_class.get_extractor).to eq(klass: BulkImports::Groups::Extractors::SubgroupsExtractor, options: nil)
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'has transformers' do
|
|
|
|
expect(described_class.transformers).to contain_exactly(
|
2021-02-22 17:27:13 +05:30
|
|
|
{ klass: BulkImports::Common::Transformers::ProhibitedAttributesTransformer, options: nil },
|
|
|
|
{ klass: BulkImports::Groups::Transformers::SubgroupToEntityTransformer, options: nil }
|
2021-01-29 00:20:46 +05:30
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|