-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start testing request header processing
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
core/jvm/src/test/scala/krop/route/RequestHeaderSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |