hruan
05/04/2022, 9:53 AM415
when 201
is expected. Running the app and calling the same endpoint via curl works as expected, leading me to believe that I’ve done something wrong with the test client setup. Any pointers would be appreciated. Details in thread.testApplication {
// ... test application setup ...
val testClient = createClient {
install(ContentNegotiation) {
json(Json { DefaultJson })
}
install(Auth) {
bearer {
loadTokens {
BearerTokens(jwt, "nope")
}
}
}
}
<http://testClient.post|testClient.post>("/some-post-endpoint") {
accept(ContentType.Application.Json)
contentType(ContentType.Application.Json)
setBody(CreationRequest("test", listOf("test"), "testOrg", "testId"))
}.apply {
assertEquals(HttpStatusCode.Created, status)
}
}
ContentNegotiation
plugin config match the server.createClient
bit and doing the post manually
<http://client.post|client.post>("/some-post-endpoint") {
accept(ContentType.Application.Json)
contentType(ContentType.Application.Json)
header(HttpHeaders.Authorization, "Bearer $jwt")
setBody(
"""
{
... some raw json ...
}
""".trimIndent()
)
}.apply {
assertEquals(HttpStatusCode.Created, status)
}
Still returns 415 Unsupported Media Type
. What am I missing here?testApplication
🤦