File: variable_validation_error_spec.rb

package info (click to toggle)
ruby-graphql 2.2.17-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,584 kB
  • sloc: ruby: 67,505; ansic: 1,753; yacc: 831; javascript: 331; makefile: 6
file content (51 lines) | stat: -rw-r--r-- 1,627 bytes parent folder | download
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
# frozen_string_literal: true
require "spec_helper"

describe GraphQL::Query::VariableValidationError do
  let(:ast) { Struct.new(:name, :line, :col).new('input', 1, 2) }
  let(:type) { Struct.new(:to_type_signature).new('TestType') }
  let(:error_value) { 'some value' }
  let(:problems) { [{'path' => ['path-to-problem'], 'explanation' => 'it broke'}] }
  let(:validation_result) { Struct.new(:problems).new(problems) }
  let(:subject) do
    Class.new(GraphQL::Query::VariableValidationError) do
      def extensions
        {
          code: 'ERROR',
        }
      end
    end
  end

  describe '#to_h' do
    it 'includes value and problems in extensions' do
      error = subject.new(ast, type, error_value, validation_result)

      as_hash = {
        'message' => 'Variable $input of type TestType was provided invalid value for path-to-problem (it broke)',
        'locations' => [ {'line' => 1, 'column' => 2} ],
        'extensions' => {
          'code' => 'ERROR',
          'value' => error_value,
          'problems' => problems
        }
      }
      assert_equal error.to_h, as_hash
    end

    it 'when msg param is passed it overwrites the message and adds validation result message' do
      error = subject.new(ast, type, error_value, validation_result, msg: "test")

      as_hash = {
        'message' => 'test for path-to-problem (it broke)',
        'locations' => [ {'line' => 1, 'column' => 2} ],
        'extensions' => {
          'code' => 'ERROR',
          'value' => error_value,
          'problems' => problems
        }
      }
      assert_equal error.to_h, as_hash
    end
  end
end