Skip to content

Commit

Permalink
Sett content-type på responsen.
Browse files Browse the repository at this point in the history
  • Loading branch information
geiralund committed Dec 2, 2024
1 parent b48b986 commit 9b0f451
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ internal fun Route.subsumsjon(store: SubsumsjonStore) {
get("/{behovid}") {
withContext(Dispatchers.IO) {
val behovid = BehovId(call.parameters["behovid"] ?: throw MissingRequestParameterException("behovid"))
store.getSubsumsjon(behovid).toJson().let {
store.getSubsumsjon(behovid).let {
call.respond(HttpStatusCode.OK, it)
}
}
}
get("/result/{subsumsjonsid}") {
withContext(Dispatchers.IO) {
val subsumsjonsId = SubsumsjonId(call.parameters["subsumsjonsid"] ?: throw MissingRequestParameterException("behovid"))
store.getSubsumsjonByResult(subsumsjonsId).toJson().let {
store.getSubsumsjonByResult(subsumsjonsId).let {
call.respond(HttpStatusCode.OK, it)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.kotest.matchers.string.shouldNotEndWith
import io.kotest.matchers.string.shouldStartWith
import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.http.HttpMethod
import io.ktor.http.HttpStatusCode
Expand Down Expand Up @@ -121,6 +122,7 @@ class BehovRouteTest {
)
}.apply {
response.status() shouldBe HttpStatusCode.Accepted
response.headers["Content-Type"] shouldBe ContentType.Application.Json.toString()
response.headers.contains(HttpHeaders.Location) shouldBe true
response.headers[HttpHeaders.Location]?.let { location ->
location shouldStartWith "/behov/status/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.kotest.matchers.string.shouldNotEndWith
import io.kotest.matchers.string.shouldStartWith
import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.http.HttpMethod
import io.ktor.http.HttpStatusCode
Expand Down Expand Up @@ -62,6 +63,7 @@ class BehovRouteV1Test {
handleAuthenticatedAzureAdRequest(HttpMethod.Get, "v1/behov/status/01DSFG6P7969DP56BPW2EDS1RN")
.apply {
response.status() shouldBe HttpStatusCode.OK
response.headers["Content-Type"] shouldBe ContentType.Application.Json.toString()
response.content shouldNotBe null
response.content shouldBe """{"status":"PENDING"}"""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package no.nav.dagpenger.regel.api.routing

import de.huxhorn.sulky.ulid.ULID
import io.kotest.matchers.shouldBe
import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.http.HttpMethod
import io.ktor.http.HttpStatusCode
Expand Down Expand Up @@ -75,7 +76,7 @@ class LovverkRouteTest {
testApplicationRequest(subsumsjonStore)
.apply {
response.status() shouldBe HttpStatusCode.OK

response.headers["Content-Type"] shouldBe ContentType.Application.Json.toString()
response.content shouldBe """{"nyVurdering":false}"""
verify {
subsumsjonStore.getSubsumsjonerByResults(
Expand All @@ -98,7 +99,7 @@ class LovverkRouteTest {
testApplicationRequest(subsumsjonStore)
.apply {
response.status() shouldBe HttpStatusCode.OK

response.headers["Content-Type"] shouldBe ContentType.Application.Json.toString()
response.content shouldBe """{"nyVurdering":true}"""
verify {
subsumsjonStore.getSubsumsjonerByResults(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package no.nav.dagpenger.regel.api.routing
import de.huxhorn.sulky.ulid.ULID
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.ktor.http.ContentType
import io.ktor.http.HttpMethod
import io.ktor.http.HttpStatusCode
import io.ktor.server.testing.handleRequest
Expand Down Expand Up @@ -60,6 +61,7 @@ internal class SubsumsjonRouteTest {
handleAuthenticatedAzureAdRequest(HttpMethod.Get, "/subsumsjon/01DSFGFVF3C1D1QQR69C7BRJT5")
.apply {
response.status() shouldBe HttpStatusCode.OK
response.headers["Content-Type"] shouldBe ContentType.Application.Json.toString()
response.content shouldNotBe null
response.content?.let {
JsonAdapter.fromJson(it) shouldBe subsumsjon
Expand Down Expand Up @@ -99,6 +101,7 @@ internal class SubsumsjonRouteTest {
handleAuthenticatedAzureAdRequest(HttpMethod.Get, "/subsumsjon/result/$id")
.apply {
response.status() shouldBe HttpStatusCode.OK
response.headers["Content-Type"] shouldBe ContentType.Application.Json.toString()
response.content shouldNotBe null
response.content?.let {
JsonAdapter.fromJson(it) shouldBe subsumsjon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package no.nav.dagpenger.regel.api.routing
import de.huxhorn.sulky.ulid.ULID
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.http.HttpMethod
import io.ktor.http.HttpStatusCode
Expand Down Expand Up @@ -61,6 +62,7 @@ internal class SubsumsjonRouteV1Test {
handleAuthenticatedAzureAdRequest(HttpMethod.Get, "v1/subsumsjon/01DSFGFVF3C1D1QQR69C7BRJT5")
.apply {
response.status() shouldBe HttpStatusCode.OK
response.headers["Content-Type"] shouldBe ContentType.Application.Json.toString()
response.content shouldNotBe null
response.content?.let {
JsonAdapter.fromJson(it) shouldBe subsumsjon
Expand Down Expand Up @@ -100,6 +102,7 @@ internal class SubsumsjonRouteV1Test {
handleAuthenticatedAzureAdRequest(HttpMethod.Get, "v1/subsumsjon/result/$id")
.apply {
response.status() shouldBe HttpStatusCode.OK
response.headers["Content-Type"] shouldBe ContentType.Application.Json.toString()
response.content shouldNotBe null
response.content?.let {
JsonAdapter.fromJson(it) shouldBe subsumsjon
Expand Down

0 comments on commit 9b0f451

Please sign in to comment.