I'm trying to test my web api using ScalaTest and I can't get the API to execute my siteData()
action. The following code results in a 400
, but running the same payload from the outside works just fine.
class DeviceApiSpec extends TestEnvironmentSpec with Results {
"DeviceApi#siteData()" should {
val api = new DeviceApi(...) // new up the controller
"accept a valid location" in {
val apikey = ...
val location = Json.obj(...)
val request = FakeRequest(POST, "/api/device")
.withHeaders(apikey)
.withHeaders("Content-Type" -> "application/json")
.withJsonBody(location)
val result = api.siteData().apply(request).run()
// do some assertions once I get it working
}
}
}
The headers and body are correct. I'm not sure that I'm setting up the test properly though, so wondering if someone can spot a hopefully obvious error.