File: argument_names_are_unique_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 (78 lines) | stat: -rw-r--r-- 2,155 bytes parent folder | download | duplicates (2)
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
67
68
69
70
71
72
73
74
75
76
77
78
# frozen_string_literal: true
require "spec_helper"

describe GraphQL::StaticValidation::ArgumentNamesAreUnique do
  include StaticValidationHelpers

  describe "field arguments" do
    let(:query_string) { <<-GRAPHQL
    query GetStuff {
      c1: cheese(id: 1, id: 2) { flavor }
      c2: cheese(id: 2) { flavor }
    }
    GRAPHQL
    }

    it "finds duplicate names" do
      assert_equal 1, errors.size

      error = errors.first
      assert_equal 'There can be only one argument named "id"', error["message"]
      assert_equal [{ "line" => 2, "column" => 18}, { "line" => 2, "column" => 25 }], error["locations"]
      assert_equal ["query GetStuff", "c1"], error["path"]
    end
  end

  describe "directive arguments" do
    let(:query_string) { <<-GRAPHQL
    query GetStuff {
      c1: cheese(id: 1) @include(if: true, if: true) { flavor }
      c2: cheese(id: 2) @include(if: true) { flavor }
    }
    GRAPHQL
    }

    it "finds duplicate names" do
      assert_equal 1, errors.size

      error = errors.first
      assert_equal 'There can be only one argument named "if"', error["message"]
      assert_equal [{ "line" => 2, "column" => 34}, { "line" => 2, "column" => 44 }], error["locations"]
      assert_equal ["query GetStuff", "c1"], error["path"]
    end
  end

  describe "with error limiting" do
    let(:query_string) { <<-GRAPHQL
    query GetStuff {
      c1: cheese(id: 1, id: 2) @include(if: true, if: true) { flavor }
      c2: cheese(id: 3, id: 3) @include(if: true) { flavor }
    }
    GRAPHQL
    }

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

      it "does not limit the number of errors" do
        assert_equal(error_messages, [
          "There can be only one argument named \"id\"",
          "There can be only one argument named \"if\"",
          "There can be only one argument named \"id\""
        ])
      end
    end

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

      it "does limit the number of errors" do
        assert_equal(error_messages, [ "There can be only one argument named \"id\"" ])
      end
    end
  end
end