Created
August 26, 2017 18:59
-
-
Save marcintustin/64bd6ca385932c027408529f0fbda5cc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| "POST -> /hello/bobo" should "say hello with the greeting specified in the body json" in { | |
| // org.http4s.Request.withBody returns a task that can be run to generate the request | |
| val request = org.http4s.Request(Method.POST, uri("/hello/bobo")).withBody( | |
| """{"greeting": "hola"}""").run | |
| // run runs the service against the request | |
| // Note the return type | |
| val responseTask: scalaz.concurrent.Task[org.http4s.Response] = HelloWorld.service.run(request) | |
| // the first run gets the org.http4s.Request, which has a body; | |
| // the body is an org.http4s.EntityBody which is really a scalaz.stream.Process | |
| // accordingly, to get the value from it, runLast, which itself returns a Task | |
| // the task needs to be run to obtain an Option of the body as a bytevector | |
| val response: Option[scodec.bits.ByteVector] = responseTask.run.body.runLast.run | |
| // Obviously, only use get in test code. decodeUtf8 decodes to an either of a String | |
| response.get.decodeUtf8.right.get shouldEqual """{"message":"hola, bobo"}""" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment