diff --git a/apps/etterlatte-api/src/main/kotlin/no/nav/etterlatte/samordning/sak/BehandlingSakRoutes.kt b/apps/etterlatte-api/src/main/kotlin/no/nav/etterlatte/samordning/sak/BehandlingSakRoutes.kt index 914b3f09b45..57e5a368ccd 100644 --- a/apps/etterlatte-api/src/main/kotlin/no/nav/etterlatte/samordning/sak/BehandlingSakRoutes.kt +++ b/apps/etterlatte-api/src/main/kotlin/no/nav/etterlatte/samordning/sak/BehandlingSakRoutes.kt @@ -22,6 +22,7 @@ private fun generateRoles(config: Config): Set { config.getString("roller.pensjon-saksbehandler"), config.getString("roller.gjenny-saksbehandler"), ) + // TODO: les-oms-sak-for-person kan fjernes siden de kaller oss med OBO...... return defaultRoles + "les-oms-sak-for-person" } @@ -55,7 +56,7 @@ fun Route.behandlingSakRoutes( } } - route("/${SAKID_CALL_PARAMETER}") { + route("/{$SAKID_CALL_PARAMETER}") { install(AuthorizationPlugin) { accessPolicyRolesEllerAdGrupper = setOf("les-bp-sak", "les-oms-sak") } diff --git a/apps/etterlatte-api/src/test/kotlin/no/nav/etterlatte/samordning/sak/BehandlingSakRoutesTest.kt b/apps/etterlatte-api/src/test/kotlin/no/nav/etterlatte/samordning/sak/BehandlingSakRoutesTest.kt index c096bddee1c..68f30a34295 100644 --- a/apps/etterlatte-api/src/test/kotlin/no/nav/etterlatte/samordning/sak/BehandlingSakRoutesTest.kt +++ b/apps/etterlatte-api/src/test/kotlin/no/nav/etterlatte/samordning/sak/BehandlingSakRoutesTest.kt @@ -5,6 +5,7 @@ import com.typesafe.config.ConfigFactory import io.kotest.matchers.shouldBe import io.ktor.client.call.body import io.ktor.client.plugins.contentnegotiation.ContentNegotiation +import io.ktor.client.request.get import io.ktor.client.request.header import io.ktor.client.request.post import io.ktor.client.request.setBody @@ -25,7 +26,10 @@ import no.nav.etterlatte.behandling.sakId1 import no.nav.etterlatte.ktor.startRandomPort import no.nav.etterlatte.ktor.token.CLIENT_ID import no.nav.etterlatte.ktor.token.issueSaksbehandlerToken +import no.nav.etterlatte.libs.common.Enhetsnummer +import no.nav.etterlatte.libs.common.behandling.SakType import no.nav.etterlatte.libs.common.objectMapper +import no.nav.etterlatte.libs.common.sak.Sak import no.nav.etterlatte.libs.common.sak.SakId import no.nav.etterlatte.libs.common.toJson import no.nav.etterlatte.libs.ktor.restModule @@ -207,7 +211,6 @@ class BehandlingSakRoutesTest { ) } response.status shouldBe HttpStatusCode.OK - println(response.bodyAsText()) val sakliste: List = response.body() sakliste shouldBe sakIdListesvar @@ -215,6 +218,97 @@ class BehandlingSakRoutesTest { coVerify(exactly = 1) { behandlingService.hentSakforPerson(requestFnr) } } } + + @Test + fun `Kan hente sak men sak er null og kaster da kastes exception IkkeFunnetException men logges `() { + val pensjonSaksbehandler = UUID.randomUUID().toString() + val conff = config(mockOAuth2Server.config.httpServer.port(), Issuer.AZURE.issuerName, pensjonSaksbehandler = pensjonSaksbehandler) + applicationConfig = HoconApplicationConfig(conff) + coEvery { behandlingService.hentSak(any()) } returns null + testApplication { + environment { config = applicationConfig } + application { + restModule(routeLogger) { + behandlingSakRoutes( + behandlingService = behandlingService, + config = conff, + ) + } + } + val client = + createClient { + install(ContentNegotiation) { + register(ContentType.Application.Json, JacksonConverter(objectMapper)) + } + } + + val response = + client.get("/api/sak/25895819") { + contentType(ContentType.Application.Json) + header( + HttpHeaders.Authorization, + "Bearer ${mockOAuth2Server.issueSaksbehandlerToken(groups = listOf("les-oms-sak"))}", + ) + } + response.status shouldBe HttpStatusCode.OK + println(response.bodyAsText()) + val sakliste: Sak? = response.body() + + sakliste shouldBe null + + coVerify(exactly = 1) { behandlingService.hentSak(any()) } + } + } + + @Test + fun `Kan hente sak, verifiserer at den blir returnert`() { + val pensjonSaksbehandler = UUID.randomUUID().toString() + val conff = config(mockOAuth2Server.config.httpServer.port(), Issuer.AZURE.issuerName, pensjonSaksbehandler = pensjonSaksbehandler) + applicationConfig = HoconApplicationConfig(conff) + val sakId: Long = 12 + val funnetSak = + Sak( + "ident", + SakType.OMSTILLINGSSTOENAD, + SakId(sakId), + Enhetsnummer( + "4808", + ), + ) + coEvery { behandlingService.hentSak(any()) } returns funnetSak + testApplication { + environment { config = applicationConfig } + application { + restModule(routeLogger) { + behandlingSakRoutes( + behandlingService = behandlingService, + config = conff, + ) + } + } + val client = + createClient { + install(ContentNegotiation) { + register(ContentType.Application.Json, JacksonConverter(objectMapper)) + } + } + + val response = + client.get("/api/sak/$sakId") { + contentType(ContentType.Application.Json) + header( + HttpHeaders.Authorization, + "Bearer ${mockOAuth2Server.issueSaksbehandlerToken(groups = listOf("les-oms-sak"))}", + ) + } + response.status shouldBe HttpStatusCode.OK + val hentetSak: Sak? = response.body() + + hentetSak shouldBe funnetSak + + coVerify(exactly = 1) { behandlingService.hentSak(SakId(sakId)) } + } + } } private fun config( diff --git a/apps/etterlatte-behandling/src/main/kotlin/oppgave/OppgaveService.kt b/apps/etterlatte-behandling/src/main/kotlin/oppgave/OppgaveService.kt index 34167ec8e4c..469bc02165a 100644 --- a/apps/etterlatte-behandling/src/main/kotlin/oppgave/OppgaveService.kt +++ b/apps/etterlatte-behandling/src/main/kotlin/oppgave/OppgaveService.kt @@ -41,6 +41,7 @@ class OppgaveService( ) { private val logger: Logger = LoggerFactory.getLogger(this.javaClass.name) + // TODO: hvorfor ikke ha med oppgavetype? fun finnOppgaverForBruker( bruker: SaksbehandlerMedEnheterOgRoller, oppgaveStatuser: List, diff --git a/apps/etterlatte-vedtaksvurdering/src/main/kotlin/no/nav/etterlatte/vedtaksvurdering/AutomatiskBehandlingRoutes.kt b/apps/etterlatte-vedtaksvurdering/src/main/kotlin/no/nav/etterlatte/vedtaksvurdering/AutomatiskBehandlingRoutes.kt index 1264b957d8b..5ef88377fb4 100644 --- a/apps/etterlatte-vedtaksvurdering/src/main/kotlin/no/nav/etterlatte/vedtaksvurdering/AutomatiskBehandlingRoutes.kt +++ b/apps/etterlatte-vedtaksvurdering/src/main/kotlin/no/nav/etterlatte/vedtaksvurdering/AutomatiskBehandlingRoutes.kt @@ -6,6 +6,7 @@ import io.ktor.server.response.respond import io.ktor.server.routing.Route import io.ktor.server.routing.post import io.ktor.server.routing.route +import no.nav.etterlatte.common.Enheter import no.nav.etterlatte.libs.ktor.route.BEHANDLINGID_CALL_PARAMETER import no.nav.etterlatte.libs.ktor.route.SAKID_CALL_PARAMETER import no.nav.etterlatte.libs.ktor.route.sakId @@ -24,6 +25,7 @@ fun Route.automatiskBehandlingRoutes( post("/{$SAKID_CALL_PARAMETER}/{$BEHANDLINGID_CALL_PARAMETER}/automatisk") { withBehandlingId(behandlingKlient, skrivetilgang = true) { behandlingId -> + Enheter.defaultEnhet logger.info("Håndterer behandling $behandlingId") val nyttVedtak = service.vedtakStegvis(behandlingId, sakId, brukerTokenInfo, MigreringKjoringVariant.FULL_KJORING)