From 1fd4957a327d91e382dfb1c2d38e826212e5fa00 Mon Sep 17 00:00:00 2001 From: jules Ivanic Date: Wed, 18 Oct 2023 16:12:44 +0400 Subject: [PATCH] Add a test of a middleware providing a context to a `Routes` --- .../zio/http/internal/middlewares/AuthSpec.scala | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/zio-http/src/test/scala/zio/http/internal/middlewares/AuthSpec.scala b/zio-http/src/test/scala/zio/http/internal/middlewares/AuthSpec.scala index 7bdab111a5..51915786f4 100644 --- a/zio-http/src/test/scala/zio/http/internal/middlewares/AuthSpec.scala +++ b/zio-http/src/test/scala/zio/http/internal/middlewares/AuthSpec.scala @@ -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")(