blob: 2abd3df20fde97471896ef63d7126aa9ae27105b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# frozen_string_literal: true
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(:context) do
instance_double(
BulkImports::Pipeline::Context,
entity: import_entity
)
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
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(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, {})
subject.extract(context).first
end
end
end
end
|