Skip to content

Add a bit more test coverage #394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ final class DocumentErrorTests: XCTestCase {
let openAPIError = OpenAPI.Error(from: error)

XCTAssertEqual(openAPIError.localizedDescription, "Expected to find `openapi` key in the root Document object but it is missing.")
XCTAssertEqual(openAPIError.localizedDescription, openAPIError.description)
XCTAssertEqual(openAPIError.codingPath.map { $0.stringValue }, [])
}
}
Expand Down
12 changes: 11 additions & 1 deletion Tests/OpenAPIKit30Tests/Document/DereferencedDocumentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ final class DereferencedDocumentTests: XCTestCase {
servers: [.init(url: URL(string: "http://website.com")!)],
paths: [
"/hello/world": .init(
servers: [.init(urlTemplate: URLTemplate(rawValue: "http://{domain}.com")!, variables: ["domain": .init(default: "other")])],
get: .init(
operationId: "hi",
responses: [
200: .response(description: "success")
]
)
)
],
components: .noComponents
components: .noComponents,
tags: ["hi"]
).locallyDereferenced()

XCTAssertEqual(t1.paths.count, 1)
Expand All @@ -51,6 +54,13 @@ final class DereferencedDocumentTests: XCTestCase {
t1.resolvedEndpointsByPath().keys,
["/hello/world"]
)

XCTAssertEqual(t1.allOperationIds, ["hi"])
XCTAssertEqual(t1.allServers, [
.init(url: URL(string: "http://website.com")!),
.init(urlTemplate: URLTemplate(rawValue: "http://{domain}.com")!, variables: ["domain": .init(default: "other")]),
])
XCTAssertEqual(t1.allTags, ["hi"])
}

func test_noSecurityReferencedResponseInPath() throws {
Expand Down
6 changes: 6 additions & 0 deletions Tests/OpenAPIKit30Tests/Validator/ValidatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,12 @@ final class ValidatorTests: XCTestCase {
"Inconsistency encountered when parsing ``: \'gzip\' could not be parsed as a Content Type. Content Types should have the format \'<type>/<subtype>\'."
)
XCTAssertEqual(warnings.first?.codingPathString, ".paths[\'/test\'].get.responses.200.content")
XCTAssertNotNil(warnings.first?.underlyingError)
XCTAssertNotNil(warnings.first?.errorCategory)
XCTAssertEqual(warnings.first?.subjectName, "")
XCTAssertEqual(warnings.first?.contextString, "")

XCTAssertEqual(warnings.first?.localizedDescription, warnings.first?.description)
}

func test_collectsContentTypeWarningStrict() throws {
Expand Down
6 changes: 3 additions & 3 deletions Tests/OpenAPIKitCoreTests/CallbackURLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import OpenAPIKitCore
import XCTest

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

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

let result = try orderUnstableTestStringFromEncoding(of: url)
Expand All @@ -32,7 +32,7 @@ final class CallbackURLTests: XCTestCase {
)
}

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

Expand Down
40 changes: 40 additions & 0 deletions Tests/OpenAPIKitCoreTests/ComponentKeyTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// ComponentKeyTests.swift
// OpenAPIKit
//
// Created by Mathew Polzin on 2/16/25.
//

import OpenAPIKitCore
import XCTest

final class ComponentKeyTests: XCTestCase {
func test_init() throws {
let t1 : Shared.ComponentKey = "abcd"
XCTAssertEqual(t1.rawValue, "abcd")

let t2 = Shared.ComponentKey(rawValue: "abcd")
XCTAssertEqual(t2?.rawValue, "abcd")

let t3 = Shared.ComponentKey(rawValue: "")
XCTAssertNil(t3)

let t4 = Shared.ComponentKey(rawValue: "(abcd)")
XCTAssertNil(t4)

let t5 = try Shared.ComponentKey.forceInit(rawValue: "abcd")
XCTAssertEqual(t5.rawValue, "abcd")

XCTAssertThrowsError(try Shared.ComponentKey.forceInit(rawValue: nil))
XCTAssertThrowsError(try Shared.ComponentKey.forceInit(rawValue: "(abcd)"))
}

func test_problemString() {
let message = Shared.ComponentKey.problem(with: "(abcd)")

XCTAssertEqual(message, "Keys for components in the Components Object must conform to the regex `^[a-zA-Z0-9\\.\\-_]+$`. '(abcd)' does not..")

let nonProblem = Shared.ComponentKey.problem(with: "abcd")
XCTAssertNil(nonProblem)
}
}
12 changes: 11 additions & 1 deletion Tests/OpenAPIKitTests/Document/DereferencedDocumentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ final class DereferencedDocumentTests: XCTestCase {
servers: [.init(url: URL(string: "http://website.com")!)],
paths: [
"/hello/world": .init(
servers: [.init(urlTemplate: URLTemplate(rawValue: "http://{domain}.com")!, variables: ["domain": .init(default: "other")])],
get: .init(
operationId: "hi",
responses: [
200: .response(description: "success")
]
)
)
],
components: .noComponents
components: .noComponents,
tags: ["hi"]
).locallyDereferenced()

XCTAssertEqual(t1.paths.count, 1)
Expand All @@ -51,6 +54,13 @@ final class DereferencedDocumentTests: XCTestCase {
t1.resolvedEndpointsByPath().keys,
["/hello/world"]
)

XCTAssertEqual(t1.allOperationIds, ["hi"])
XCTAssertEqual(t1.allServers, [
.init(url: URL(string: "http://website.com")!),
.init(urlTemplate: URLTemplate(rawValue: "http://{domain}.com")!, variables: ["domain": .init(default: "other")]),
])
XCTAssertEqual(t1.allTags, ["hi"])
}

func test_noSecurityReferencedResponseInPath() throws {
Expand Down