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

graphql_extractor_spec.rb « extractors « common « bulk_imports « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 80607485b6eb09443c285bd095236bb455782524 (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
# 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: { '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,
      entity: import_entity
    )
  end

  subject { described_class.new(options) }

  describe '#extract' 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

    it 'returns ExtractedData' do
      extracted_data = subject.extract(context)

      expect(extracted_data).to be_instance_of(BulkImports::Pipeline::ExtractedData)
      expect(extracted_data.data).to contain_exactly('bar')
    end
  end
end