Skip to content

Commit

Permalink
Merge pull request #1 from guizmaii/fix_context_provider_middleware_w…
Browse files Browse the repository at this point in the history
…ith_routes

Add a test of a middleware providing a context to a `Routes`
  • Loading branch information
guizmaii authored Oct 18, 2023
2 parents 553bc83 + 1fd4957 commit e878506
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ object AuthSpec extends ZIOHttpSpec with HttpAppTestExtensions {
test("Extract username via context with Routes") {
val app = {
Routes(
Method.GET / "context" ->
Handler.fromFunction[(AuthContext, Request)] { case (c, _) => Response.text(c.value) },
) @@ basicAuthContextM
Method.GET / "context" -> basicAuthContextM ->
Handler.fromFunction[(AuthContext, Request)] { case (c: AuthContext, _) => Response.text(c.value) }
)
}.toHttpApp
assertZIO(app.runZIO(Request.get(URL.root / "context").copy(headers = successBasicHeader)))(equalTo("user"))
assertZIO(
app
.runZIO(Request.get(URL.root / "context").copy(headers = successBasicHeader))
.flatMap(_.body.asString)
)(equalTo("user"))
},
),
suite("basicAuthZIO")(
Expand Down

0 comments on commit e878506

Please sign in to comment.