Skip to content

Commit

Permalink
fikse og legge til test
Browse files Browse the repository at this point in the history
  • Loading branch information
Watercolours committed Dec 12, 2024
1 parent ea65b22 commit 1743db7
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion apps/etterlatte-behandling/src/test/kotlin/sak/SakRoutesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.http.contentType
import io.ktor.server.testing.testApplication
import io.mockk.Called
import io.mockk.clearAllMocks
import io.mockk.coEvery
import io.mockk.every
Expand Down Expand Up @@ -242,9 +243,10 @@ internal class SakRoutesTest {

withTestApplication { client ->
val response =
client.post("/api/sak/$sakId/oppdater-ident?hendelseId=$hendelseId") {
client.post("/api/sak/$sakId/oppdater-ident") {
header(HttpHeaders.Authorization, "Bearer $token")
contentType(ContentType.Application.Json)
setBody(OppdaterIdentRequest(hendelseId))
}
assertEquals(200, response.status.value)
}
Expand All @@ -263,6 +265,49 @@ internal class SakRoutesTest {
}
}

@Test
fun `Oppdater ident på sak - uten hendelse`() {
val nyIdent = KONTANT_FOT
val sakId = SakId(Random.nextLong())
val sak =
Sak(
"ident",
SakType.OMSTILLINGSSTOENAD,
sakId,
Enheter.defaultEnhet.enhetNr,
)

every { sakService.finnSak(any()) } returns sak
every { sakService.oppdaterIdentForSak(any(), any()) } returns sak.copy(ident = nyIdent.value)
val behandlingOgSak = BehandlingOgSak(UUID.randomUUID(), sakId)
every { behandlingService.hentAapneBehandlingerForSak(sakId) } returns listOf(behandlingOgSak)

withTestApplication { client ->
val response =
client.post("/api/sak/$sakId/oppdater-ident") {
header(HttpHeaders.Authorization, "Bearer $token")
contentType(ContentType.Application.Json)
setBody(OppdaterIdentRequest(null, utenHendelse = true))
}
assertEquals(200, response.status.value)
}

verify(exactly = 1) {
sakService.finnSak(sakId)
sakService.oppdaterIdentForSak(sak, any())
behandlingService.hentAapneBehandlingerForSak(sakId)
behandlingService.avbrytBehandling(
behandlingOgSak.behandlingId,
any(),
AarsakTilAvbrytelse.ENDRET_FOLKEREGISTERIDENT,
any(),
)
}
verify {
grunnlagsendringshendelseService wasNot Called
}
}

private fun withTestApplication(block: suspend (client: HttpClient) -> Unit) {
val user =
mockk<SaksbehandlerMedEnheterOgRoller>().also { every { it.name() } returns this::class.java.simpleName }
Expand Down

0 comments on commit 1743db7

Please sign in to comment.