Skip to content

Commit

Permalink
IS-2720: Ktor 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
geir-waagboe committed Dec 20, 2024
1 parent 5d580f8 commit 0fd5b04
Show file tree
Hide file tree
Showing 6 changed files with 602 additions and 701 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,6 @@ object BehandlerdialogPersonoversiktStatusApiV2Spek : Spek({
)
val url = "$personOversiktApiV2Path/enhet/$NAV_ENHET"

fun ApplicationTestBuilder.setupApiAndClient(): HttpClient {
application {
testApiModule(
externalMockEnvironment = ExternalMockEnvironment.instance,
)
}
val client = createClient {
install(ContentNegotiation) {
jackson { configure() }
}
}
return client
}

beforeEachTest {
database.dropData()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,138 +1,124 @@
package no.nav.syfo.personstatus.api.v2

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import io.ktor.client.call.*
import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.server.testing.*
import io.ktor.util.*
import no.nav.syfo.dialogmotestatusendring.domain.DialogmoteStatusendringType
import no.nav.syfo.personstatus.api.v2.endpoints.personOversiktApiV2Path
import no.nav.syfo.personstatus.api.v2.model.PersonOversiktStatusDTO
import no.nav.syfo.testutil.*
import no.nav.syfo.testutil.UserConstants.ARBEIDSTAKER_FNR
import no.nav.syfo.testutil.database.*
import no.nav.syfo.testutil.mock.behandlendeEnhetDTO
import no.nav.syfo.util.bearerHeader
import no.nav.syfo.util.configuredJacksonMapper
import org.amshove.kluent.*
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
import java.time.OffsetDateTime

object DialogmotekandidatPersonoversiktStatusApiV2Spek : Spek({
val objectMapper: ObjectMapper = configuredJacksonMapper()

describe("Get dialogmotekandidater from personoversiktstatus") {

with(TestApplicationEngine()) {
start()
val externalMockEnvironment = setupExternalMockEnvironment(application)
val database = externalMockEnvironment.database
val validToken = generateJWT(
audience = externalMockEnvironment.environment.azure.appClientId,
issuer = externalMockEnvironment.wellKnownVeilederV2.issuer,
navIdent = UserConstants.VEILEDER_ID,
)
beforeEachTest {
database.dropData()
}
val externalMockEnvironment = ExternalMockEnvironment.instance
val database = externalMockEnvironment.database
val validToken = generateJWT(
audience = externalMockEnvironment.environment.azure.appClientId,
issuer = externalMockEnvironment.wellKnownVeilederV2.issuer,
navIdent = UserConstants.VEILEDER_ID,
)

beforeEachTest {
database.dropData()
}

describe("Get dm2-kandidater for enhet") {
val url = "$personOversiktApiV2Path/enhet/${UserConstants.NAV_ENHET}"
describe("Get dm2-kandidater for enhet") {
val url = "$personOversiktApiV2Path/enhet/${UserConstants.NAV_ENHET}"

it("returns NoContent for a person with a tilfelle, who is kandidat, but has an open DM2 invitation") {
it("returns NoContent for a person with a tilfelle, who is kandidat, but has an open DM2 invitation") {
testApplication {
val client = setupApiAndClient()
createPersonoversiktStatusWithTilfelle(database)
setAsKandidat(database)
setDialogmotestatus(database, DialogmoteStatusendringType.INNKALT)
setTildeltEnhet(database)

with(
handleRequest(HttpMethod.Get, url) {
addHeader(HttpHeaders.Authorization, bearerHeader(validToken))
}
) {
response.status() shouldBeEqualTo HttpStatusCode.NoContent
val response = client.get(url) {
bearerAuth(validToken)
}
response.status shouldBeEqualTo HttpStatusCode.NoContent
}
}

it("return NoContent for a person with a tilfelle, who is kandidat, but it's historic") {
it("return NoContent for a person with a tilfelle, who is kandidat, but it's historic") {
testApplication {
val client = setupApiAndClient()
createPersonoversiktStatusWithTilfelle(database)
setAsKandidat(database, kandidatGeneratedAt = OffsetDateTime.now().minusDays(365))
setTildeltEnhet(database)

with(
handleRequest(HttpMethod.Get, url) {
addHeader(HttpHeaders.Authorization, bearerHeader(validToken))
}
) {
response.status() shouldBeEqualTo HttpStatusCode.NoContent
val response = client.get(url) {
bearerAuth(validToken)
}
response.status shouldBeEqualTo HttpStatusCode.NoContent
}
}

it("return NoContent for a person with a tilfelle, who is kandidat, but the delay of 7 days has NOT passed") {
it("return NoContent for a person with a tilfelle, who is kandidat, but the delay of 7 days has NOT passed") {
testApplication {
val client = setupApiAndClient()
createPersonoversiktStatusWithTilfelle(database)
setAsKandidat(database, kandidatGeneratedAt = OffsetDateTime.now().minusDays(6))
setTildeltEnhet(database)

with(
handleRequest(HttpMethod.Get, url) {
addHeader(HttpHeaders.Authorization, bearerHeader(validToken))
}
) {
response.status() shouldBeEqualTo HttpStatusCode.NoContent
val response = client.get(url) {
bearerAuth(validToken)
}
response.status shouldBeEqualTo HttpStatusCode.NoContent
}
}

it("returns kandidat if they have a tilfelle, is kandidat, and a delay of 7 days has passed") {
it("returns kandidat if they have a tilfelle, is kandidat, and a delay of 7 days has passed") {
testApplication {
val client = setupApiAndClient()
createPersonoversiktStatusWithTilfelle(database)
setAsKandidat(database, kandidatGeneratedAt = OffsetDateTime.now().minusDays(10))
setTildeltEnhet(database)

with(
handleRequest(HttpMethod.Get, url) {
addHeader(HttpHeaders.Authorization, bearerHeader(validToken))
}
) {
response.status() shouldBeEqualTo HttpStatusCode.OK
val personOversiktStatus =
objectMapper.readValue<List<PersonOversiktStatusDTO>>(response.content!!).first()
personOversiktStatus.shouldNotBeNull()
personOversiktStatus.veilederIdent shouldBeEqualTo null
personOversiktStatus.fnr shouldBeEqualTo ARBEIDSTAKER_FNR
personOversiktStatus.enhet shouldBeEqualTo behandlendeEnhetDTO().enhetId
personOversiktStatus.motebehovUbehandlet.shouldBeNull()
personOversiktStatus.oppfolgingsplanLPSBistandUbehandlet.shouldBeNull()
personOversiktStatus.dialogmotesvarUbehandlet shouldBeEqualTo false
personOversiktStatus.dialogmotekandidat shouldBeEqualTo true
personOversiktStatus.aktivitetskravvurdering.shouldBeNull()
val response = client.get(url) {
bearerAuth(validToken)
}
response.status shouldBeEqualTo HttpStatusCode.OK
val personOversiktStatus = response.body<List<PersonOversiktStatusDTO>>().first()
personOversiktStatus.shouldNotBeNull()
personOversiktStatus.veilederIdent shouldBeEqualTo null
personOversiktStatus.fnr shouldBeEqualTo ARBEIDSTAKER_FNR
personOversiktStatus.enhet shouldBeEqualTo behandlendeEnhetDTO().enhetId
personOversiktStatus.motebehovUbehandlet.shouldBeNull()
personOversiktStatus.oppfolgingsplanLPSBistandUbehandlet.shouldBeNull()
personOversiktStatus.dialogmotesvarUbehandlet shouldBeEqualTo false
personOversiktStatus.dialogmotekandidat shouldBeEqualTo true
personOversiktStatus.aktivitetskravvurdering.shouldBeNull()
}
}

it("returns person who is kandidat if they have a tilfelle, is kandidat, and a cancelled dm2") {
it("returns person who is kandidat if they have a tilfelle, is kandidat, and a cancelled dm2") {
testApplication {
val client = setupApiAndClient()
createPersonoversiktStatusWithTilfelle(database)
setAsKandidat(database)
setDialogmotestatus(database, DialogmoteStatusendringType.AVLYST)
setTildeltEnhet(database)

with(
handleRequest(HttpMethod.Get, url) {
addHeader(HttpHeaders.Authorization, bearerHeader(validToken))
}
) {
response.status() shouldBeEqualTo HttpStatusCode.OK
val personOversiktStatus =
objectMapper.readValue<List<PersonOversiktStatusDTO>>(response.content!!).first()
personOversiktStatus.shouldNotBeNull()
personOversiktStatus.veilederIdent shouldBeEqualTo null
personOversiktStatus.fnr shouldBeEqualTo ARBEIDSTAKER_FNR
personOversiktStatus.enhet shouldBeEqualTo behandlendeEnhetDTO().enhetId
personOversiktStatus.motebehovUbehandlet.shouldBeNull()
personOversiktStatus.oppfolgingsplanLPSBistandUbehandlet.shouldBeNull()
personOversiktStatus.dialogmotesvarUbehandlet shouldBeEqualTo false
personOversiktStatus.dialogmotekandidat shouldBeEqualTo true
personOversiktStatus.motestatus shouldBeEqualTo DialogmoteStatusendringType.AVLYST.name
personOversiktStatus.aktivitetskravvurdering.shouldBeNull()
val response = client.get(url) {
bearerAuth(validToken)
}
response.status shouldBeEqualTo HttpStatusCode.OK
val personOversiktStatus = response.body<List<PersonOversiktStatusDTO>>().first()
personOversiktStatus.shouldNotBeNull()
personOversiktStatus.veilederIdent shouldBeEqualTo null
personOversiktStatus.fnr shouldBeEqualTo ARBEIDSTAKER_FNR
personOversiktStatus.enhet shouldBeEqualTo behandlendeEnhetDTO().enhetId
personOversiktStatus.motebehovUbehandlet.shouldBeNull()
personOversiktStatus.oppfolgingsplanLPSBistandUbehandlet.shouldBeNull()
personOversiktStatus.dialogmotesvarUbehandlet shouldBeEqualTo false
personOversiktStatus.dialogmotekandidat shouldBeEqualTo true
personOversiktStatus.motestatus shouldBeEqualTo DialogmoteStatusendringType.AVLYST.name
personOversiktStatus.aktivitetskravvurdering.shouldBeNull()
}
}
}
Expand Down
Loading

0 comments on commit 0fd5b04

Please sign in to comment.