File: input_object_names_are_unique_spec.rb

package info (click to toggle)
ruby-graphql 2.5.19-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 13,868 kB
  • sloc: ruby: 80,420; ansic: 1,808; yacc: 845; javascript: 480; makefile: 6
file content (64 lines) | stat: -rw-r--r-- 2,160 bytes parent folder | download | duplicates (3)
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
# frozen_string_literal: true
require "spec_helper"

describe GraphQL::StaticValidation::InputObjectNamesAreUnique do
  include StaticValidationHelpers

  let(:query_string) {%|
    query getCheese {
      validInputObjectName: searchDairy(product: [{source: YAK}]) { __typename }
      duplicateInputObjectNames: searchDairy(product: [{source: YAK, source: YAK}]) { __typename }
    }
  |}

  describe "when queries contain duplicate input fields" do
    duplicate_input_field_error =  {
      "message" => 'There can be only one input field named "source"',
      "locations"=>[{ "line" => 4, "column" => 57 }, { "line" => 4, "column" => 70 }],
      "path" => ["query getCheese", "duplicateInputObjectNames", "product", 0],
      "extensions" => { "code" => "inputFieldNotUnique", "name" => "source" }
    }

    it "returns errors in the response" do
      assert_includes(errors, duplicate_input_field_error)
    end
  end

  describe "with error limiting" do
    let(:query_string) {%|
      query getCheese {
        validInputObjectName: searchDairy(product: [{source: YAK}]) { __typename }
        duplicateInputObjectNames: searchDairy(product: [{source: YAK, source: YAK}]) { __typename }
        moreDuplicateInputObjectNames: searchDairy(product: [{fatContent: YAK, fatContent: YAK, source: COW}]) { __typename }
      }
    |}

    describe("disabled") do
      let(:args) {
        { max_errors: nil }
      }

      it "does not limit the number of errors" do
        assert_equal(error_messages.length, 3)
        assert_equal(error_messages, [
          "There can be only one input field named \"source\"",
          "There can be only one input field named \"fatContent\"",
          "Argument 'fatContent' on InputObject 'DairyProductInput' has an invalid value (YAK). Expected type 'Float'."
        ])
      end
    end

    describe("enabled") do
      let(:args) {
        { max_errors: 1 }
      }

      it "does limit the number of errors" do
        assert_equal(error_messages.length, 1)
        assert_equal(error_messages, [
          "There can be only one input field named \"source\"",
        ])
      end
    end
  end
end