mercredi 2 août 2017

Playframework test. FakeRequest sent with empty body always (scala)

I've been struggling several hours and every time I send a FakeRequest, it seems that the FakeApplication receives an empty body. However, if I try to run the play application and I send a normal request to localhost, everything works as expected, I receive the text I sent as a response.

My test code looks like:

      val controller = app.injector.instanceOf(classOf[CreateRecordController])
  val js = Json.obj()
  val result = controller.apply().apply(
    FakeRequest(POST, "/api/v1/record/")
      .withHeaders(Headers(CONTENT_TYPE -> "text/plain"))
      .withTextBody(js.toString())
  )

  val content = contentAsString(result)

  info.apply(s"content was $content")

The last statement prints: "content was" . Nothing else.

Am I missing something?

Play version: 2.6.2

Aucun commentaire:

Enregistrer un commentaire