From 57e2d02ec30b6a8b2d03e834872a082775d3ee13 Mon Sep 17 00:00:00 2001 From: Noel Welsh Date: Wed, 10 Jul 2024 21:09:17 +0100 Subject: [PATCH] Start testing request header processing --- .../scala/krop/route/RequestHeaderSuite.scala | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 core/jvm/src/test/scala/krop/route/RequestHeaderSuite.scala diff --git a/core/jvm/src/test/scala/krop/route/RequestHeaderSuite.scala b/core/jvm/src/test/scala/krop/route/RequestHeaderSuite.scala new file mode 100644 index 0000000..edb7587 --- /dev/null +++ b/core/jvm/src/test/scala/krop/route/RequestHeaderSuite.scala @@ -0,0 +1,35 @@ +package krop.route + +import krop.raise.Raise +import munit.CatsEffectSuite +import org.http4s.Method +import org.http4s.Uri +import org.http4s.implicits.* +import org.http4s.{Request as Http4sRequest} +import org.http4s.headers.`Content-Type` +import org.http4s.MediaType +import org.http4s.Headers + +class RequestHeaderSuite extends CatsEffectSuite { + test("Ensure header fails if header does not exist") { + val req = Request + .get(Path.root) + .ensureHeader(`Content-Type`(MediaType.application.json)) + val request = + Http4sRequest(method = Method.GET, uri = uri"http://example.org/") + + req.parse(request)(using Raise.toOption).map(_.isEmpty).assert + } + + test("Ensure header succeeds if header does exist") { + val header = `Content-Type`(MediaType.application.json) + val req = Request.get(Path.root).ensureHeader(header) + val request = Http4sRequest( + method = Method.GET, + uri = uri"http://example.org/", + headers = Headers(header) + ) + + req.parse(request)(using Raise.toOption).map(_.isDefined).assert + } +}