Skip to content

Commit

Permalink
Start testing request header processing
Browse files Browse the repository at this point in the history
  • Loading branch information
noelwelsh committed Jul 10, 2024
1 parent 8f65f2d commit 57e2d02
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions core/jvm/src/test/scala/krop/route/RequestHeaderSuite.scala
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 57e2d02

Please sign in to comment.