Skip to content

Commit e744087

Browse files
committed
Add lookup validation helper test
1 parent 19eda4b commit e744087

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Tests/OpenAPIKitTests/Validator/Validation+ConvenienceTests.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,45 @@ final class ValidationConvenienceTests: XCTestCase {
276276
)
277277
}
278278

279+
func test_subject_lookup() {
280+
let v = Validation<OpenAPI.Parameter>(
281+
description: "parameter is named test",
282+
check: \.name == "test"
283+
)
284+
285+
let document = OpenAPI.Document(
286+
info: .init(title: "test", version: "1.0"),
287+
servers: [],
288+
paths: [
289+
"/test": .init(
290+
parameters: [
291+
.reference(.component(named: "test1")), // passes validation
292+
.reference(.component(named: "test2")), // wrong name
293+
.reference(.component(named: "test3")) // not found
294+
]
295+
)
296+
],
297+
components: .init(
298+
parameters: [
299+
"test1": .init(name: "test", context: .header, content: [:]),
300+
"test2": .init(name: "test2", context: .query, content: [:])
301+
]
302+
)
303+
)
304+
305+
let context = ValidationContext<OpenAPI.PathItem>(document: document, subject: document.paths["/test"]!, codingPath: [])
306+
307+
XCTAssertTrue(
308+
lookup(\OpenAPI.PathItem.parameters[0], thenApply: v)(context).isEmpty
309+
)
310+
XCTAssertFalse(
311+
lookup(\OpenAPI.PathItem.parameters[1], thenApply: v)(context).isEmpty
312+
)
313+
XCTAssertFalse(
314+
lookup(\OpenAPI.PathItem.parameters[2], thenApply: v)(context).isEmpty
315+
)
316+
}
317+
279318
func test_allCombinator() {
280319
let v1 = Validation<String>(
281320
description: "String is more than 5 characters",

0 commit comments

Comments
 (0)