Skip to content

Commit

Permalink
EY-4277 Fikse essi sak hent endepunkt
Browse files Browse the repository at this point in the history
  • Loading branch information
sebassonav committed Nov 27, 2024
1 parent 9c2a361 commit 5d95fd4
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ private fun generateRoles(config: Config): Set<String> {
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"
}

Expand Down Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -207,14 +211,104 @@ class BehandlingSakRoutesTest {
)
}
response.status shouldBe HttpStatusCode.OK
println(response.bodyAsText())
val sakliste: List<SakId> = response.body()

sakliste shouldBe sakIdListesvar

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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 5d95fd4

Please sign in to comment.