diff options
Diffstat (limited to 'spec/lib/bulk_imports/groups/pipelines')
4 files changed, 161 insertions, 8 deletions
diff --git a/spec/lib/bulk_imports/groups/pipelines/group_attributes_pipeline_spec.rb b/spec/lib/bulk_imports/groups/pipelines/group_attributes_pipeline_spec.rb new file mode 100644 index 00000000000..7ac417afa0b --- /dev/null +++ b/spec/lib/bulk_imports/groups/pipelines/group_attributes_pipeline_spec.rb @@ -0,0 +1,80 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BulkImports::Groups::Pipelines::GroupAttributesPipeline do + subject(:pipeline) { described_class.new(context) } + + let_it_be(:user) { create(:user) } + let_it_be(:group) { create(:group) } + let_it_be(:bulk_import) { create(:bulk_import, user: user) } + let_it_be(:entity) { create(:bulk_import_entity, :group_entity, group: group, bulk_import: bulk_import) } + let_it_be(:tracker) { create(:bulk_import_tracker, entity: entity) } + let_it_be(:context) { BulkImports::Pipeline::Context.new(tracker) } + + let(:group_attributes) do + { + 'id' => 1, + 'name' => 'Group name', + 'path' => 'group-path', + 'description' => 'description', + 'avatar' => { + 'url' => nil + }, + 'membership_lock' => true, + 'traversal_ids' => [ + 2 + ] + } + end + + describe '#run' do + before do + allow_next_instance_of(BulkImports::Common::Extractors::JsonExtractor) do |extractor| + allow(extractor).to receive(:extract).and_return( + BulkImports::Pipeline::ExtractedData.new(data: group_attributes) + ) + end + end + + it 'imports allowed group attributes' do + expect(Groups::UpdateService).to receive(:new).with(group, user, { membership_lock: true }).and_call_original + + pipeline.run + + expect(group).to have_attributes(membership_lock: true) + end + end + + describe '#transform' do + it 'fetches only allowed attributes and symbolize keys' do + transformed_data = pipeline.transform(context, group_attributes) + + expect(transformed_data).to eq({ membership_lock: true }) + end + + context 'when there is no data to transform' do + let(:group_attributes) { nil } + + it do + transformed_data = pipeline.transform(context, group_attributes) + + expect(transformed_data).to eq(nil) + end + end + end + + describe '#after_run' do + it 'calls extractor#remove_tmpdir' do + expect_next_instance_of(BulkImports::Common::Extractors::JsonExtractor) do |extractor| + expect(extractor).to receive(:remove_tmpdir) + end + + pipeline.after_run(nil) + end + end + + describe '.relation' do + it { expect(described_class.relation).to eq('self') } + end +end diff --git a/spec/lib/bulk_imports/groups/pipelines/group_pipeline_spec.rb b/spec/lib/bulk_imports/groups/pipelines/group_pipeline_spec.rb index 39e782dc093..441a34b0c74 100644 --- a/spec/lib/bulk_imports/groups/pipelines/group_pipeline_spec.rb +++ b/spec/lib/bulk_imports/groups/pipelines/group_pipeline_spec.rb @@ -23,7 +23,7 @@ RSpec.describe BulkImports::Groups::Pipelines::GroupPipeline do let(:group_data) do { - 'name' => 'source_name', + 'name' => 'Source Group Name', 'full_path' => 'source/full/path', 'visibility' => 'private', 'project_creation_level' => 'developer', diff --git a/spec/lib/bulk_imports/groups/pipelines/namespace_settings_pipeline_spec.rb b/spec/lib/bulk_imports/groups/pipelines/namespace_settings_pipeline_spec.rb new file mode 100644 index 00000000000..90b63453b88 --- /dev/null +++ b/spec/lib/bulk_imports/groups/pipelines/namespace_settings_pipeline_spec.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BulkImports::Groups::Pipelines::NamespaceSettingsPipeline do + subject(:pipeline) { described_class.new(context) } + + let_it_be(:user) { create(:user) } + let_it_be(:group) { create(:group, namespace_settings: create(:namespace_settings) ) } + let_it_be(:bulk_import) { create(:bulk_import, user: user) } + let_it_be(:entity) { create(:bulk_import_entity, :group_entity, group: group, bulk_import: bulk_import) } + let_it_be(:tracker) { create(:bulk_import_tracker, entity: entity) } + let_it_be(:context) { BulkImports::Pipeline::Context.new(tracker) } + + before do + group.add_owner(user) + end + + describe '#run' do + before do + allow_next_instance_of(BulkImports::Common::Extractors::NdjsonExtractor) do |extractor| + namespace_settings_attributes = { + 'namespace_id' => 22, + 'prevent_forking_outside_group' => true, + 'prevent_sharing_groups_outside_hierarchy' => true + } + allow(extractor).to receive(:extract).and_return( + BulkImports::Pipeline::ExtractedData.new(data: [[namespace_settings_attributes, 0]]) + ) + end + end + + it 'imports allowed namespace settings attributes' do + expect(Groups::UpdateService).to receive(:new).with( + group, user, { prevent_sharing_groups_outside_hierarchy: true } + ).and_call_original + + pipeline.run + + expect(group.namespace_settings).to have_attributes(prevent_sharing_groups_outside_hierarchy: true) + end + end + + describe '#transform' do + it 'fetches only allowed attributes and symbolize keys' do + all_model_attributes = NamespaceSetting.new.attributes + + transformed_data = pipeline.transform(context, [all_model_attributes, 0]) + + expect(transformed_data.keys).to match_array([:prevent_sharing_groups_outside_hierarchy]) + end + + context 'when there is no data to transform' do + it do + namespace_settings_attributes = nil + + transformed_data = pipeline.transform(context, namespace_settings_attributes) + + expect(transformed_data).to eq(nil) + end + end + end + + describe '#after_run' do + it 'calls extractor#remove_tmpdir' do + expect_next_instance_of(BulkImports::Common::Extractors::NdjsonExtractor) do |extractor| + expect(extractor).to receive(:remove_tmpdir) + end + + context = instance_double(BulkImports::Pipeline::Context) + + pipeline.after_run(context) + end + end +end diff --git a/spec/lib/bulk_imports/groups/pipelines/subgroup_entities_pipeline_spec.rb b/spec/lib/bulk_imports/groups/pipelines/subgroup_entities_pipeline_spec.rb index e4a41428dd2..6949ac59948 100644 --- a/spec/lib/bulk_imports/groups/pipelines/subgroup_entities_pipeline_spec.rb +++ b/spec/lib/bulk_imports/groups/pipelines/subgroup_entities_pipeline_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' RSpec.describe BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline do 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') } + let_it_be(:parent) { create(:group, name: 'Imported Group', path: 'imported-group') } 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) } @@ -14,8 +14,8 @@ RSpec.describe BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline do let(:extracted_data) do BulkImports::Pipeline::ExtractedData.new(data: { - 'name' => 'subgroup', - 'full_path' => 'parent/subgroup' + 'path' => 'sub-group', + 'full_path' => 'parent/sub-group' }) end @@ -33,9 +33,9 @@ RSpec.describe BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline do subgroup_entity = BulkImports::Entity.last - expect(subgroup_entity.source_full_path).to eq 'parent/subgroup' + expect(subgroup_entity.source_full_path).to eq 'parent/sub-group' expect(subgroup_entity.destination_namespace).to eq 'imported-group' - expect(subgroup_entity.destination_name).to eq 'subgroup' + expect(subgroup_entity.destination_name).to eq 'sub-group' expect(subgroup_entity.parent_id).to eq parent_entity.id end end @@ -51,9 +51,7 @@ RSpec.describe BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline do 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' |