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

field_call_count_spec.rb « limit « graphql « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5858986dfc87e8b19c7924a3518728eee8171c6c (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
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe Gitlab::Graphql::Limit::FieldCallCount do
  include GraphqlHelpers

  let(:field_args) { {} }
  let(:owner) { fresh_object_type }
  let(:field) do
    ::Types::BaseField.new(name: 'value', type: GraphQL::Types::String, null: true, owner: owner) do
      extension(::Gitlab::Graphql::Limit::FieldCallCount, limit: 1)
    end
  end

  let(:query) do
    GraphQL::Query.new(GitlabSchema)
  end

  def resolve_value
    resolve_field(field, { value: 'foo' }, object_type: owner, query: query)
  end

  it 'allows the call' do
    expect { resolve_value }.not_to raise_error
  end

  it 'executes the extension' do
    expect(described_class).to receive(:new).and_call_original

    resolve_value
  end

  it 'returns an error when the field is called multiple times' do
    resolve_value

    expect(resolve_value).to be_an_instance_of(Gitlab::Graphql::Errors::LimitError)
  end

  context 'when limit is not specified' do
    let(:field) do
      ::Types::BaseField.new(name: 'value', type: GraphQL::Types::String, null: true, owner: owner) do
        extension(::Gitlab::Graphql::Limit::FieldCallCount)
      end
    end

    it 'returns an error' do
      expect(resolve_value).to be_an_instance_of(Gitlab::Graphql::Errors::ArgumentError)
    end
  end

  context 'when the field is not extended' do
    let(:field) do
      ::Types::BaseField.new(name: 'value', type: GraphQL::Types::String, null: true, owner: owner)
    end

    it 'allows the call' do
      expect { resolve_value }.not_to raise_error
    end

    it 'does not execute the extension' do
      expect(described_class).not_to receive(:new)

      resolve_value
    end
  end
end