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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/bulk_imports/common/extractors/json_extractor_spec.rb')
-rw-r--r--spec/lib/bulk_imports/common/extractors/json_extractor_spec.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/spec/lib/bulk_imports/common/extractors/json_extractor_spec.rb b/spec/lib/bulk_imports/common/extractors/json_extractor_spec.rb
new file mode 100644
index 00000000000..2c167cc485c
--- /dev/null
+++ b/spec/lib/bulk_imports/common/extractors/json_extractor_spec.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require 'zlib'
+
+RSpec.describe BulkImports::Common::Extractors::JsonExtractor do
+ subject { described_class.new(relation: 'self') }
+
+ let_it_be(:tmpdir) { Dir.mktmpdir }
+ let_it_be(:import) { create(:bulk_import) }
+ let_it_be(:config) { create(:bulk_import_configuration, bulk_import: import) }
+ let_it_be(:entity) { create(:bulk_import_entity, bulk_import: import) }
+ let_it_be(:tracker) { create(:bulk_import_tracker, entity: entity) }
+ let_it_be(:context) { BulkImports::Pipeline::Context.new(tracker) }
+
+ before do
+ allow(FileUtils).to receive(:remove_entry).with(any_args).and_call_original
+
+ subject.instance_variable_set(:@tmpdir, tmpdir)
+ end
+
+ after(:all) do
+ FileUtils.remove_entry(tmpdir) if File.directory?(tmpdir)
+ end
+
+ describe '#extract' do
+ before do
+ Zlib::GzipWriter.open(File.join(tmpdir, 'self.json.gz')) do |gz|
+ gz.write '{"name": "Name","description": "Description","avatar":{"url":null}}'
+ end
+
+ expect(BulkImports::FileDownloadService).to receive(:new)
+ .with(
+ configuration: context.configuration,
+ relative_url: entity.relation_download_url_path('self'),
+ tmpdir: tmpdir,
+ filename: 'self.json.gz')
+ .and_return(instance_double(BulkImports::FileDownloadService, execute: nil))
+ end
+
+ it 'returns ExtractedData', :aggregate_failures do
+ extracted_data = subject.extract(context)
+
+ expect(extracted_data).to be_instance_of(BulkImports::Pipeline::ExtractedData)
+ expect(extracted_data.data).to contain_exactly(
+ { 'name' => 'Name', 'description' => 'Description', 'avatar' => { 'url' => nil } }
+ )
+ end
+ end
+
+ describe '#remove_tmpdir' do
+ it 'removes tmp dir' do
+ expect(FileUtils).to receive(:remove_entry).with(tmpdir).once
+
+ subject.remove_tmpdir
+ end
+ end
+end