Skip to content

Commit e5b0ff8

Browse files
test: Adds SDL validation test utilities
1 parent 70b7dbd commit e5b0ff8

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Tests/GraphQLTests/ValidationTests/ValidationTests.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,30 @@ class ValidationTestCase: XCTestCase {
129129
XCTAssertEqual(errorPath, path, "Unexpected error path", file: testFile, line: testLine)
130130
}
131131
}
132+
133+
class SDLValidationTestCase: XCTestCase {
134+
typealias Rule = (SDLValidationContext) -> Visitor
135+
136+
var rule: Rule!
137+
138+
func assertValidationErrors(
139+
_ sdlStr: String,
140+
schema: GraphQLSchema? = nil,
141+
_ errors: [GraphQLError],
142+
testFile _: StaticString = #file,
143+
testLine _: UInt = #line
144+
) throws {
145+
let doc = try parse(source: sdlStr)
146+
let validationErrors = validateSDL(documentAST: doc, schemaToExtend: schema, rules: [rule])
147+
148+
XCTAssertEqual(
149+
validationErrors.map(\.message),
150+
errors.map(\.message)
151+
)
152+
153+
XCTAssertEqual(
154+
validationErrors.map(\.locations),
155+
errors.map(\.locations)
156+
)
157+
}
158+
}

0 commit comments

Comments
 (0)