diff --git a/Tests/LeafErrorMiddlewareTests/CustomGeneratorTests.swift b/Tests/LeafErrorMiddlewareTests/CustomGeneratorTests.swift index 72bb4a7..5307e5f 100644 --- a/Tests/LeafErrorMiddlewareTests/CustomGeneratorTests.swift +++ b/Tests/LeafErrorMiddlewareTests/CustomGeneratorTests.swift @@ -38,6 +38,10 @@ class CustomGeneratorTests: XCTestCase { .notFound } + router.get("403") { _ -> Response in + throw Abort(.forbidden) + } + router.get("serverError") { _ -> Response in throw Abort(.internalServerError) } @@ -139,6 +143,12 @@ class CustomGeneratorTests: XCTestCase { XCTAssertEqual(viewRenderer.leafPath, "404") } + func testThat403IsCaughtCorrectly() throws { + let response = try app.getResponse(to: "/403") + XCTAssertEqual(response.status, .forbidden) + XCTAssertEqual(viewRenderer.leafPath, "serverError") + } + func testContextGeneratedOn404Page() throws { let response = try app.getResponse(to: "/404") XCTAssertEqual(response.status, .notFound) diff --git a/Tests/LeafErrorMiddlewareTests/DefaultLeafErrorMiddlewareTests.swift b/Tests/LeafErrorMiddlewareTests/DefaultLeafErrorMiddlewareTests.swift index 73b843c..1766b18 100644 --- a/Tests/LeafErrorMiddlewareTests/DefaultLeafErrorMiddlewareTests.swift +++ b/Tests/LeafErrorMiddlewareTests/DefaultLeafErrorMiddlewareTests.swift @@ -34,6 +34,10 @@ class DefaultLeafErrorMiddlewareTests: XCTestCase { throw Abort(.notFound) } + router.get("403") { _ -> Response in + throw Abort(.forbidden) + } + router.get("serverError") { _ -> Response in throw Abort(.internalServerError) } @@ -144,6 +148,12 @@ class DefaultLeafErrorMiddlewareTests: XCTestCase { XCTAssertEqual(viewRenderer.leafPath, "404") } + func testThat403IsCaughtCorrectly() throws { + let response = try app.getResponse(to: "/403") + XCTAssertEqual(response.status, .forbidden) + XCTAssertEqual(viewRenderer.leafPath, "serverError") + } + func testAddingMiddlewareToRouteGroup() throws { app.shutdown() app = Application(.testing, .shared(eventLoopGroup))