Skip to content

Commit

Permalink
Add 403 endpoint test
Browse files Browse the repository at this point in the history
  • Loading branch information
ptoffy committed Dec 20, 2021
1 parent 3365c97 commit 6b06aff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Tests/LeafErrorMiddlewareTests/CustomGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class CustomGeneratorTests: XCTestCase {
.notFound
}

router.get("403") { _ -> Response in
throw Abort(.forbidden)
}

router.get("serverError") { _ -> Response in
throw Abort(.internalServerError)
}
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 6b06aff

Please sign in to comment.