Skip to content

Commit 893c138

Browse files
authored
Merge pull request #394 from mattpolzin/4_0-test-coverage
2 parents 1d1f322 + 4cf25fc commit 893c138

File tree

6 files changed

+72
-5
lines changed

6 files changed

+72
-5
lines changed

Tests/OpenAPIKit30ErrorReportingTests/DocumentErrorTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ final class DocumentErrorTests: XCTestCase {
2626
let openAPIError = OpenAPI.Error(from: error)
2727

2828
XCTAssertEqual(openAPIError.localizedDescription, "Expected to find `openapi` key in the root Document object but it is missing.")
29+
XCTAssertEqual(openAPIError.localizedDescription, openAPIError.description)
2930
XCTAssertEqual(openAPIError.codingPath.map { $0.stringValue }, [])
3031
}
3132
}

Tests/OpenAPIKit30Tests/Document/DereferencedDocumentTests.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ final class DereferencedDocumentTests: XCTestCase {
2828
servers: [.init(url: URL(string: "http://website.com")!)],
2929
paths: [
3030
"/hello/world": .init(
31+
servers: [.init(urlTemplate: URLTemplate(rawValue: "http://{domain}.com")!, variables: ["domain": .init(default: "other")])],
3132
get: .init(
33+
operationId: "hi",
3234
responses: [
3335
200: .response(description: "success")
3436
]
3537
)
3638
)
3739
],
38-
components: .noComponents
40+
components: .noComponents,
41+
tags: ["hi"]
3942
).locallyDereferenced()
4043

4144
XCTAssertEqual(t1.paths.count, 1)
@@ -51,6 +54,13 @@ final class DereferencedDocumentTests: XCTestCase {
5154
t1.resolvedEndpointsByPath().keys,
5255
["/hello/world"]
5356
)
57+
58+
XCTAssertEqual(t1.allOperationIds, ["hi"])
59+
XCTAssertEqual(t1.allServers, [
60+
.init(url: URL(string: "http://website.com")!),
61+
.init(urlTemplate: URLTemplate(rawValue: "http://{domain}.com")!, variables: ["domain": .init(default: "other")]),
62+
])
63+
XCTAssertEqual(t1.allTags, ["hi"])
5464
}
5565

5666
func test_noSecurityReferencedResponseInPath() throws {

Tests/OpenAPIKit30Tests/Validator/ValidatorTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,12 @@ final class ValidatorTests: XCTestCase {
14441444
"Inconsistency encountered when parsing ``: \'gzip\' could not be parsed as a Content Type. Content Types should have the format \'<type>/<subtype>\'."
14451445
)
14461446
XCTAssertEqual(warnings.first?.codingPathString, ".paths[\'/test\'].get.responses.200.content")
1447+
XCTAssertNotNil(warnings.first?.underlyingError)
1448+
XCTAssertNotNil(warnings.first?.errorCategory)
1449+
XCTAssertEqual(warnings.first?.subjectName, "")
1450+
XCTAssertEqual(warnings.first?.contextString, "")
1451+
1452+
XCTAssertEqual(warnings.first?.localizedDescription, warnings.first?.description)
14471453
}
14481454

14491455
func test_collectsContentTypeWarningStrict() throws {

Tests/OpenAPIKitCoreTests/CallbackURLTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import OpenAPIKitCore
99
import XCTest
1010

1111
final class CallbackURLTests: XCTestCase {
12-
func testInit() {
12+
func test_init() {
1313
let plainUrl = Shared.CallbackURL(url: URL(string: "https://hello.com")!)
1414
XCTAssertEqual(plainUrl.url, URL(string: "https://hello.com")!)
1515
XCTAssertEqual(plainUrl.template.variables.count, 0)
@@ -19,7 +19,7 @@ final class CallbackURLTests: XCTestCase {
1919
XCTAssertEqual(templateUrl?.template.variables, ["$request.path.id"])
2020
}
2121

22-
func testEncode() throws {
22+
func test_encode() throws {
2323
let url = Shared.CallbackURL(rawValue: "https://hello.com/item/{$request.path.id}")
2424

2525
let result = try orderUnstableTestStringFromEncoding(of: url)
@@ -32,7 +32,7 @@ final class CallbackURLTests: XCTestCase {
3232
)
3333
}
3434

35-
func testDecode() throws {
35+
func test_decode() throws {
3636
let json = #""https://hello.com/item/{$request.path.id}""#
3737
let data = json.data(using: .utf8)!
3838

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// ComponentKeyTests.swift
3+
// OpenAPIKit
4+
//
5+
// Created by Mathew Polzin on 2/16/25.
6+
//
7+
8+
import OpenAPIKitCore
9+
import XCTest
10+
11+
final class ComponentKeyTests: XCTestCase {
12+
func test_init() throws {
13+
let t1 : Shared.ComponentKey = "abcd"
14+
XCTAssertEqual(t1.rawValue, "abcd")
15+
16+
let t2 = Shared.ComponentKey(rawValue: "abcd")
17+
XCTAssertEqual(t2?.rawValue, "abcd")
18+
19+
let t3 = Shared.ComponentKey(rawValue: "")
20+
XCTAssertNil(t3)
21+
22+
let t4 = Shared.ComponentKey(rawValue: "(abcd)")
23+
XCTAssertNil(t4)
24+
25+
let t5 = try Shared.ComponentKey.forceInit(rawValue: "abcd")
26+
XCTAssertEqual(t5.rawValue, "abcd")
27+
28+
XCTAssertThrowsError(try Shared.ComponentKey.forceInit(rawValue: nil))
29+
XCTAssertThrowsError(try Shared.ComponentKey.forceInit(rawValue: "(abcd)"))
30+
}
31+
32+
func test_problemString() {
33+
let message = Shared.ComponentKey.problem(with: "(abcd)")
34+
35+
XCTAssertEqual(message, "Keys for components in the Components Object must conform to the regex `^[a-zA-Z0-9\\.\\-_]+$`. '(abcd)' does not..")
36+
37+
let nonProblem = Shared.ComponentKey.problem(with: "abcd")
38+
XCTAssertNil(nonProblem)
39+
}
40+
}

Tests/OpenAPIKitTests/Document/DereferencedDocumentTests.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ final class DereferencedDocumentTests: XCTestCase {
2828
servers: [.init(url: URL(string: "http://website.com")!)],
2929
paths: [
3030
"/hello/world": .init(
31+
servers: [.init(urlTemplate: URLTemplate(rawValue: "http://{domain}.com")!, variables: ["domain": .init(default: "other")])],
3132
get: .init(
33+
operationId: "hi",
3234
responses: [
3335
200: .response(description: "success")
3436
]
3537
)
3638
)
3739
],
38-
components: .noComponents
40+
components: .noComponents,
41+
tags: ["hi"]
3942
).locallyDereferenced()
4043

4144
XCTAssertEqual(t1.paths.count, 1)
@@ -51,6 +54,13 @@ final class DereferencedDocumentTests: XCTestCase {
5154
t1.resolvedEndpointsByPath().keys,
5255
["/hello/world"]
5356
)
57+
58+
XCTAssertEqual(t1.allOperationIds, ["hi"])
59+
XCTAssertEqual(t1.allServers, [
60+
.init(url: URL(string: "http://website.com")!),
61+
.init(urlTemplate: URLTemplate(rawValue: "http://{domain}.com")!, variables: ["domain": .init(default: "other")]),
62+
])
63+
XCTAssertEqual(t1.allTags, ["hi"])
5464
}
5565

5666
func test_noSecurityReferencedResponseInPath() throws {

0 commit comments

Comments
 (0)