diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/lib/bulk_imports/common/extractors/graphql_extractor_spec.rb | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/lib/bulk_imports/common/extractors/graphql_extractor_spec.rb')
-rw-r--r-- | spec/lib/bulk_imports/common/extractors/graphql_extractor_spec.rb | 66 |
1 files changed, 19 insertions, 47 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 2abd3df20fd..80607485b6e 100644 --- a/spec/lib/bulk_imports/common/extractors/graphql_extractor_spec.rb +++ b/spec/lib/bulk_imports/common/extractors/graphql_extractor_spec.rb @@ -5,8 +5,18 @@ require 'spec_helper' RSpec.describe BulkImports::Common::Extractors::GraphqlExtractor do let(:graphql_client) { instance_double(BulkImports::Clients::Graphql) } let(:import_entity) { create(:bulk_import_entity) } - let(:response) { double(original_hash: { foo: :bar }) } - let(:query) { { query: double(to_s: 'test', variables: {}) } } + let(:response) { double(original_hash: { 'data' => { 'foo' => 'bar' }, 'page_info' => {} }) } + let(:options) do + { + query: double( + to_s: 'test', + variables: {}, + data_path: %w[data foo], + page_info_path: %w[data page_info] + ) + } + end + let(:context) do instance_double( BulkImports::Pipeline::Context, @@ -14,58 +24,20 @@ RSpec.describe BulkImports::Common::Extractors::GraphqlExtractor do ) end - subject { described_class.new(query) } - - before do - allow(subject).to receive(:graphql_client).and_return(graphql_client) - allow(graphql_client).to receive(:parse) - end + subject { described_class.new(options) } describe '#extract' do before do - allow(subject).to receive(:query_variables).and_return({}) - allow(graphql_client).to receive(:execute).and_return(response) - end - - it 'returns original hash' do - expect(subject.extract(context)).to eq({ foo: :bar }) - end - end - - describe 'query variables' do - before do + allow(subject).to receive(:graphql_client).and_return(graphql_client) + allow(graphql_client).to receive(:parse) allow(graphql_client).to receive(:execute).and_return(response) end - context 'when variables are present' do - let(:variables) { { foo: :bar } } - let(:query) { { query: double(to_s: 'test', variables: variables) } } - - it 'builds graphql query variables for import entity' do - expect(graphql_client).to receive(:execute).with(anything, variables) - - subject.extract(context).first - end - end - - context 'when no variables are present' do - let(:query) { { query: double(to_s: 'test', variables: nil) } } - - it 'returns empty hash' do - expect(graphql_client).to receive(:execute).with(anything, nil) - - subject.extract(context).first - end - end - - context 'when variables are empty hash' do - let(:query) { { query: double(to_s: 'test', variables: {}) } } - - it 'makes graphql request with empty hash' do - expect(graphql_client).to receive(:execute).with(anything, {}) + it 'returns ExtractedData' do + extracted_data = subject.extract(context) - subject.extract(context).first - end + expect(extracted_data).to be_instance_of(BulkImports::Pipeline::ExtractedData) + expect(extracted_data.data).to contain_exactly('bar') end end end |