Skip to content

Commit 1699d07

Browse files
committed
improve test coverage for some additional easy cases
1 parent 1d1f322 commit 1699d07

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
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/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+
}

0 commit comments

Comments
 (0)