|
| 1 | +@testable import GraphQL |
| 2 | +import XCTest |
| 3 | + |
| 4 | +class KnownArgumentNamesTests : ValidationTestCase { |
| 5 | + override func setUp() { |
| 6 | + rule = KnownArgumentNames |
| 7 | + } |
| 8 | + |
| 9 | + func testValidWithObjectWithoutArguments() throws { |
| 10 | + try assertValid( |
| 11 | + "fragment objectFieldSelection on Dog { __typename name }" |
| 12 | + ) |
| 13 | + } |
| 14 | + |
| 15 | + func testValidWithCorrectArgumentNames() throws { |
| 16 | + try assertValid( |
| 17 | + "fragment objectFieldSelection on Dog { __typename isHousetrained(atOtherHomes: true) }" |
| 18 | + ) |
| 19 | + } |
| 20 | + |
| 21 | + func testInvalidWithSlightlyMisspelledArgument() throws { |
| 22 | + let errors = try assertInvalid( |
| 23 | + errorCount: 1, |
| 24 | + query: "fragment objectFieldSelection on Dog { __typename isHousetrained(atOtherHomees: true) }" |
| 25 | + ) |
| 26 | + |
| 27 | + try assertValidationError( |
| 28 | + error: errors.first, line: 1, column: 66, |
| 29 | + message: #"Field "isHousetrained" on type "Dog" does not have argument "atOtherHomees". Did you mean "atOtherHomes"?"# |
| 30 | + ) |
| 31 | + } |
| 32 | + |
| 33 | + func testInvalidWithUnrelatedArgument() throws { |
| 34 | + let errors = try assertInvalid( |
| 35 | + errorCount: 1, |
| 36 | + query: "fragment objectFieldSelection on Dog { __typename name(uppercased: true) }" |
| 37 | + ) |
| 38 | + |
| 39 | + try assertValidationError( |
| 40 | + error: errors.first, line: 1, column: 56, |
| 41 | + message: #"Field "name" on type "Dog" does not have argument "uppercased"."# |
| 42 | + ) |
| 43 | + } |
| 44 | + |
| 45 | +} |
| 46 | + |
| 47 | +extension KnownArgumentNamesTests { |
| 48 | + static var allTests: [(String, (KnownArgumentNamesTests) -> () throws -> Void)] { |
| 49 | + return [ |
| 50 | + ("testValidWithObjectWithoutArguments", testValidWithObjectWithoutArguments), |
| 51 | + ("testValidWithCorrectArgumentNames", testValidWithCorrectArgumentNames), |
| 52 | + ("testInvalidWithSlightlyMisspelledArgument", testInvalidWithSlightlyMisspelledArgument), |
| 53 | + ("testInvalidWithUnrelatedArgument", testInvalidWithUnrelatedArgument), |
| 54 | + ] |
| 55 | + } |
| 56 | +} |
0 commit comments