Skip to content

Commit

Permalink
Add test to ensure middleware works on route group
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTim committed Apr 6, 2020
1 parent 2abac30 commit 2047b10
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Tests/LeafErrorMiddlewareTests/LeafErrorMiddlewareTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,26 @@ class LeafErrorMiddlewareTests: XCTestCase {
XCTAssertEqual(response.status, .seeOther)
XCTAssertEqual(response.headers[.location].first, "ok")
}

func testAddingMiddlewareToRouteGroup() throws {
app.shutdown()
app = Application(.testing, .shared(eventLoopGroup))
app.views.use { _ in
return self.viewRenderer
}
let middlewareGroup = app.grouped(LeafErrorMiddleware(environment: app.environment))
middlewareGroup.get("404") { req -> EventLoopFuture<Response> in
req.eventLoop.makeFailedFuture(Abort(.notFound))
}
middlewareGroup.get("ok") { req in
return "OK"
}
let validResponse = try app.getResponse(to: "ok")
XCTAssertEqual(validResponse.status, .ok)
let response = try app.getResponse(to: "404")
XCTAssertEqual(response.status, .notFound)
XCTAssertEqual(viewRenderer.leafPath, "404")
}
}

extension Application {
Expand Down

0 comments on commit 2047b10

Please sign in to comment.