Skip to content

Commit

Permalink
Confirm RuntimeErrors to HTTPResponseConvertible
Browse files Browse the repository at this point in the history
  • Loading branch information
Gayathri Sairamkrishnan committed Dec 18, 2024
1 parent cd80496 commit f440264
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions Tests/OpenAPIRuntimeTests/Errors/Test_RuntimeError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,6 @@ struct MockRuntimeErrorHandler: Sendable {
}

final class Test_RuntimeError: XCTestCase {
func testRuntimeError_returnsCorrectStatusCode() async throws {

let server = UniversalServer(handler: MockRuntimeErrorHandler(failWithError: RuntimeError.invalidServerURL("Invalid server URL")),
middlewares: [ErrorHandlingMiddleware()])
let response = try await server.handle(
request: .init(soar_path: "/", method: .post),
requestBody: MockHandler.requestBody,
metadata: .init(),
forOperation: "op",
using: { MockRuntimeErrorHandler.greet($0) },
deserializer: { request, body, metadata in
let body = try XCTUnwrap(body)
return try await String(collecting: body, upTo: 10)
},
serializer: { output, _ in fatalError() }
)
XCTAssertEqual(response.0.status, .notFound)
}

func testRuntimeError_withUnderlyingErrorNotConfirming_returns500() async throws {

Expand All @@ -67,7 +49,7 @@ final class Test_RuntimeError: XCTestCase {
XCTAssertEqual(response.0.status, .internalServerError)
}

func testRuntimeError_withUnderlyingErrorConfirming_returns500() async throws {
func testRuntimeError_withUnderlyingErrorConfirming_returnsCorrectStatusCode() async throws {

let server = UniversalServer(handler: MockRuntimeErrorHandler(failWithError: TestErrorConvertible.testError("Test Error")),
middlewares: [ErrorHandlingMiddleware()])
Expand All @@ -90,6 +72,7 @@ final class Test_RuntimeError: XCTestCase {
enum TestErrorConvertible: Error, HTTPResponseConvertible {
case testError(String)

/// HTTP status code for error cases
public var httpStatus: HTTPTypes.HTTPResponse.Status {
.badGateway
}
Expand Down

0 comments on commit f440264

Please sign in to comment.