File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
Tests/LeafErrorMiddlewareTests Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,10 @@ class CustomGeneratorTests: XCTestCase {
3838 . notFound
3939 }
4040
41+ router. get ( " 403 " ) { _ -> Response in
42+ throw Abort ( . forbidden)
43+ }
44+
4145 router. get ( " serverError " ) { _ -> Response in
4246 throw Abort ( . internalServerError)
4347 }
@@ -139,6 +143,12 @@ class CustomGeneratorTests: XCTestCase {
139143 XCTAssertEqual ( viewRenderer. leafPath, " 404 " )
140144 }
141145
146+ func testThat403IsCaughtCorrectly( ) throws {
147+ let response = try app. getResponse ( to: " /403 " )
148+ XCTAssertEqual ( response. status, . forbidden)
149+ XCTAssertEqual ( viewRenderer. leafPath, " serverError " )
150+ }
151+
142152 func testContextGeneratedOn404Page( ) throws {
143153 let response = try app. getResponse ( to: " /404 " )
144154 XCTAssertEqual ( response. status, . notFound)
Original file line number Diff line number Diff line change @@ -34,6 +34,10 @@ class DefaultLeafErrorMiddlewareTests: XCTestCase {
3434 throw Abort ( . notFound)
3535 }
3636
37+ router. get ( " 403 " ) { _ -> Response in
38+ throw Abort ( . forbidden)
39+ }
40+
3741 router. get ( " serverError " ) { _ -> Response in
3842 throw Abort ( . internalServerError)
3943 }
@@ -144,6 +148,12 @@ class DefaultLeafErrorMiddlewareTests: XCTestCase {
144148 XCTAssertEqual ( viewRenderer. leafPath, " 404 " )
145149 }
146150
151+ func testThat403IsCaughtCorrectly( ) throws {
152+ let response = try app. getResponse ( to: " /403 " )
153+ XCTAssertEqual ( response. status, . forbidden)
154+ XCTAssertEqual ( viewRenderer. leafPath, " serverError " )
155+ }
156+
147157 func testAddingMiddlewareToRouteGroup( ) throws {
148158 app. shutdown ( )
149159 app = Application ( . testing, . shared( eventLoopGroup) )
You can’t perform that action at this time.
0 commit comments