summaryrefslogtreecommitdiff
path: root/spec/lib/bulk_imports
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/bulk_imports')
-rw-r--r--spec/lib/bulk_imports/common/extractors/graphql_extractor_spec.rb7
-rw-r--r--spec/lib/bulk_imports/common/transformers/graphql_cleaner_transformer_spec.rb88
-rw-r--r--spec/lib/bulk_imports/common/transformers/hash_key_digger_spec.rb28
-rw-r--r--spec/lib/bulk_imports/groups/pipelines/group_pipeline_spec.rb10
-rw-r--r--spec/lib/bulk_imports/groups/pipelines/subgroup_entities_pipeline_spec.rb1
-rw-r--r--spec/lib/bulk_imports/importers/group_importer_spec.rb16
-rw-r--r--spec/lib/bulk_imports/pipeline_spec.rb (renamed from spec/lib/bulk_imports/pipeline/attributes_spec.rb)4
7 files changed, 40 insertions, 114 deletions
diff --git a/spec/lib/bulk_imports/common/extractors/graphql_extractor_spec.rb b/spec/lib/bulk_imports/common/extractors/graphql_extractor_spec.rb
index cde8e2d5c18..a7a19fb73fc 100644
--- a/spec/lib/bulk_imports/common/extractors/graphql_extractor_spec.rb
+++ b/spec/lib/bulk_imports/common/extractors/graphql_extractor_spec.rb
@@ -41,12 +41,11 @@ RSpec.describe BulkImports::Common::Extractors::GraphqlExtractor do
end
context 'when variables are present' do
- let(:query) { { query: double(to_s: 'test', variables: { full_path: :source_full_path }) } }
+ let(:variables) { { foo: :bar } }
+ let(:query) { { query: double(to_s: 'test', variables: variables) } }
it 'builds graphql query variables for import entity' do
- expected_variables = { full_path: import_entity.source_full_path }
-
- expect(graphql_client).to receive(:execute).with(anything, expected_variables)
+ expect(graphql_client).to receive(:execute).with(anything, variables)
subject.extract(context).first
end
diff --git a/spec/lib/bulk_imports/common/transformers/graphql_cleaner_transformer_spec.rb b/spec/lib/bulk_imports/common/transformers/graphql_cleaner_transformer_spec.rb
deleted file mode 100644
index 8f39b6e7c93..00000000000
--- a/spec/lib/bulk_imports/common/transformers/graphql_cleaner_transformer_spec.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe BulkImports::Common::Transformers::GraphqlCleanerTransformer do
- describe '#transform' do
- let_it_be(:expected_output) do
- {
- 'name' => 'test',
- 'fullName' => 'test',
- 'description' => 'test',
- 'labels' => [
- { 'title' => 'label1' },
- { 'title' => 'label2' },
- { 'title' => 'label3' }
- ]
- }
- end
-
- it 'deep cleans hash from GraphQL keys' do
- data = {
- 'data' => {
- 'group' => {
- 'name' => 'test',
- 'fullName' => 'test',
- 'description' => 'test',
- 'labels' => {
- 'edges' => [
- { 'node' => { 'title' => 'label1' } },
- { 'node' => { 'title' => 'label2' } },
- { 'node' => { 'title' => 'label3' } }
- ]
- }
- }
- }
- }
-
- transformed_data = described_class.new.transform(nil, data)
-
- expect(transformed_data).to eq(expected_output)
- end
-
- context 'when data does not have data/group nesting' do
- it 'deep cleans hash from GraphQL keys' do
- data = {
- 'name' => 'test',
- 'fullName' => 'test',
- 'description' => 'test',
- 'labels' => {
- 'edges' => [
- { 'node' => { 'title' => 'label1' } },
- { 'node' => { 'title' => 'label2' } },
- { 'node' => { 'title' => 'label3' } }
- ]
- }
- }
-
- transformed_data = described_class.new.transform(nil, data)
-
- expect(transformed_data).to eq(expected_output)
- end
- end
-
- context 'when data is not a hash' do
- it 'does not perform transformation' do
- data = 'test'
-
- transformed_data = described_class.new.transform(nil, data)
-
- expect(transformed_data).to eq(data)
- end
- end
-
- context 'when nested data is not an array or hash' do
- it 'only removes top level data/group keys' do
- data = {
- 'data' => {
- 'group' => 'test'
- }
- }
-
- transformed_data = described_class.new.transform(nil, data)
-
- expect(transformed_data).to eq('test')
- end
- end
- end
-end
diff --git a/spec/lib/bulk_imports/common/transformers/hash_key_digger_spec.rb b/spec/lib/bulk_imports/common/transformers/hash_key_digger_spec.rb
new file mode 100644
index 00000000000..2b33701653e
--- /dev/null
+++ b/spec/lib/bulk_imports/common/transformers/hash_key_digger_spec.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe BulkImports::Common::Transformers::HashKeyDigger do
+ describe '#transform' do
+ it 'when the key_path is an array' do
+ data = { foo: { bar: :value } }
+ key_path = %i[foo bar]
+ transformed = described_class.new(key_path: key_path).transform(nil, data)
+
+ expect(transformed).to eq(:value)
+ end
+
+ it 'when the key_path is not an array' do
+ data = { foo: { bar: :value } }
+ key_path = :foo
+ transformed = described_class.new(key_path: key_path).transform(nil, data)
+
+ expect(transformed).to eq({ bar: :value })
+ end
+
+ it "when the data is not a hash" do
+ expect { described_class.new(key_path: nil).transform(nil, nil) }
+ .to raise_error(ArgumentError, "Given data must be a Hash")
+ end
+ 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 3949dd23b49..a132e964141 100644
--- a/spec/lib/bulk_imports/groups/pipelines/group_pipeline_spec.rb
+++ b/spec/lib/bulk_imports/groups/pipelines/group_pipeline_spec.rb
@@ -72,7 +72,6 @@ RSpec.describe BulkImports::Groups::Pipelines::GroupPipeline do
describe 'pipeline parts' do
it { expect(described_class).to include_module(BulkImports::Pipeline) }
- it { expect(described_class).to include_module(BulkImports::Pipeline::Attributes) }
it { expect(described_class).to include_module(BulkImports::Pipeline::Runner) }
it 'has extractors' do
@@ -90,13 +89,16 @@ RSpec.describe BulkImports::Groups::Pipelines::GroupPipeline do
it 'has transformers' do
expect(described_class.transformers)
.to contain_exactly(
- { klass: BulkImports::Common::Transformers::GraphqlCleanerTransformer, options: nil },
+ { klass: BulkImports::Common::Transformers::HashKeyDigger, options: { key_path: %w[data group] } },
{ klass: BulkImports::Common::Transformers::UnderscorifyKeysTransformer, options: nil },
- { klass: BulkImports::Groups::Transformers::GroupAttributesTransformer, options: nil })
+ { klass: BulkImports::Groups::Transformers::GroupAttributesTransformer, options: nil }
+ )
end
it 'has loaders' do
- expect(described_class.loaders).to contain_exactly({ klass: BulkImports::Groups::Loaders::GroupLoader, options: nil })
+ expect(described_class.loaders).to contain_exactly({
+ klass: BulkImports::Groups::Loaders::GroupLoader, options: nil
+ })
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 60a4a796682..ace8eb4d9f6 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
@@ -55,7 +55,6 @@ RSpec.describe BulkImports::Groups::Pipelines::SubgroupEntitiesPipeline do
describe 'pipeline parts' do
it { expect(described_class).to include_module(BulkImports::Pipeline) }
- it { expect(described_class).to include_module(BulkImports::Pipeline::Attributes) }
it { expect(described_class).to include_module(BulkImports::Pipeline::Runner) }
it 'has extractors' do
diff --git a/spec/lib/bulk_imports/importers/group_importer_spec.rb b/spec/lib/bulk_imports/importers/group_importer_spec.rb
index 95ac5925c97..7fec3b79179 100644
--- a/spec/lib/bulk_imports/importers/group_importer_spec.rb
+++ b/spec/lib/bulk_imports/importers/group_importer_spec.rb
@@ -18,8 +18,8 @@ RSpec.describe BulkImports::Importers::GroupImporter do
subject { described_class.new(bulk_import_entity) }
before do
+ allow(Gitlab).to receive(:ee?).and_return(false)
allow(BulkImports::Pipeline::Context).to receive(:new).and_return(context)
- stub_http_requests
end
describe '#execute' do
@@ -39,18 +39,4 @@ RSpec.describe BulkImports::Importers::GroupImporter do
expect(pipeline).to receive(:run).with(context)
end
end
-
- def stub_http_requests
- double_response = double(
- code: 200,
- success?: true,
- parsed_response: {},
- headers: {}
- )
-
- allow_next_instance_of(BulkImports::Clients::Http) do |client|
- allow(client).to receive(:get).and_return(double_response)
- allow(client).to receive(:post).and_return(double_response)
- end
- end
end
diff --git a/spec/lib/bulk_imports/pipeline/attributes_spec.rb b/spec/lib/bulk_imports/pipeline_spec.rb
index 54c5dbd4cae..ba7bcf8788f 100644
--- a/spec/lib/bulk_imports/pipeline/attributes_spec.rb
+++ b/spec/lib/bulk_imports/pipeline_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe BulkImports::Pipeline::Attributes do
+RSpec.describe BulkImports::Pipeline do
describe 'pipeline attributes' do
before do
stub_const('BulkImports::Extractor', Class.new)
@@ -10,7 +10,7 @@ RSpec.describe BulkImports::Pipeline::Attributes do
stub_const('BulkImports::Loader', Class.new)
klass = Class.new do
- include BulkImports::Pipeline::Attributes
+ include BulkImports::Pipeline
extractor BulkImports::Extractor, { foo: :bar }
transformer BulkImports::Transformer, { foo: :bar }