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
|
# frozen_string_literal: true
require "spec_helper"
describe GraphQL::StaticValidation::VariableNamesAreUnique do
include StaticValidationHelpers
let(:query_string) { <<-GRAPHQL
query GetStuff($var1: Int!, $var2: Int!, $var1: Int!, $var2: Int!, $var3: Int!) {
c1: cheese(id: $var1) { flavor }
c2: cheese(id: $var2) { flavor }
c3: cheese(id: $var3) { flavor }
}
GRAPHQL
}
it "finds duplicate variable names" do
assert_equal 2, errors.size
last_err = errors.last
assert_equal 'There can only be one variable named "var2"', last_err["message"]
assert_equal 2, last_err["locations"].size
end
describe "with error limiting" do
describe("disabled") do
let(:args) {
{ max_errors: nil }
}
it "does not limit the number of errors" do
assert_equal(error_messages.length, 2)
assert_equal(error_messages, [
"There can only be one variable named \"var1\"",
"There can only be one variable named \"var2\""
])
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 only be one variable named \"var1\"",
])
end
end
end
end
|