Skip to content

Commit d247cb8

Browse files
committed
unwrap and lookup validation helper test case.
1 parent e744087 commit d247cb8

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Tests/OpenAPIKitTests/Validator/Validation+ConvenienceTests.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,48 @@ final class ValidationConvenienceTests: XCTestCase {
315315
)
316316
}
317317

318+
func test_subject_unwrapAndlookup() {
319+
let v = Validation<OpenAPI.Parameter>(
320+
description: "parameter is named test",
321+
check: \.name == "test"
322+
)
323+
324+
let document = OpenAPI.Document(
325+
info: .init(title: "test", version: "1.0"),
326+
servers: [],
327+
paths: [
328+
"/test": .init(
329+
parameters: [
330+
.reference(.component(named: "test1")), // passes validation
331+
.reference(.component(named: "test2")), // wrong name
332+
.reference(.component(named: "test3")) // not found
333+
]
334+
)
335+
],
336+
components: .init(
337+
parameters: [
338+
"test1": .init(name: "test", context: .header, content: [:]),
339+
"test2": .init(name: "test2", context: .query, content: [:])
340+
]
341+
)
342+
)
343+
344+
let context = ValidationContext<OpenAPI.Document>(document: document, subject: document, codingPath: [])
345+
346+
XCTAssertTrue(
347+
unwrapAndLookup(\OpenAPI.Document.paths["/test"]?.parameters[0], thenApply: v)(context).isEmpty
348+
)
349+
XCTAssertFalse(
350+
unwrapAndLookup(\OpenAPI.Document.paths["/test"]?.parameters[1], thenApply: v)(context).isEmpty
351+
)
352+
XCTAssertFalse(
353+
unwrapAndLookup(\OpenAPI.Document.paths["/test"]?.parameters[2], thenApply: v)(context).isEmpty
354+
)
355+
XCTAssertFalse(
356+
unwrapAndLookup(\OpenAPI.Document.paths["/test2"]?.parameters.first, thenApply: v)(context).isEmpty
357+
)
358+
}
359+
318360
func test_allCombinator() {
319361
let v1 = Validation<String>(
320362
description: "String is more than 5 characters",

0 commit comments

Comments
 (0)