summaryrefslogtreecommitdiff
path: root/spec/graphql/types/range_input_type_spec.rb
blob: dbfcf4a41c720168973cca156e9fbb8fe0a5a8c2 (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 ::Types::RangeInputType do
  let(:of_integer) { ::GraphQL::Types::Int }

  context 'parameterized on Integer' do
    let(:type) { described_class[of_integer] }

    it 'accepts start and end' do
      input = { start: 1, end: 10 }
      output = { start: 1, end: 10 }

      expect(type.coerce_isolated_input(input)).to eq(output)
    end

    it 'rejects inverted ranges' do
      input = { start: 10, end: 1 }

      expect { type.coerce_isolated_input(input) }.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
    end
  end

  it 'follows expected subtyping relationships for instances' do
    context = GraphQL::Query::Context.new(
      query: GraphQL::Query.new(GitlabSchema),
      values: {},
      object: nil
    )
    instance = described_class[of_integer].new(context: context, defaults_used: [], ruby_kwargs: {})

    expect(instance).to be_a_kind_of(described_class)
    expect(instance).to be_a_kind_of(described_class[of_integer])
    expect(instance).not_to be_a_kind_of(described_class[GraphQL::Types::ID])
  end

  it 'follows expected subtyping relationships for classes' do
    expect(described_class[of_integer]).to be < described_class
    expect(described_class[of_integer]).not_to be < described_class[GraphQL::Types::ID]
    expect(described_class[of_integer]).not_to be < described_class[of_integer, false]
  end
end