Skip to content

Commit

Permalink
Improve test and aktivitetskravClient mock (#437)
Browse files Browse the repository at this point in the history
* Improve mock in test

* Move files to correct package
  • Loading branch information
andersrognstad authored Oct 15, 2024
1 parent b683bd5 commit ad98bc2
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/no/nav/syfo/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import no.nav.syfo.application.cache.RedisStore
import no.nav.syfo.personstatus.PersonoversiktStatusService
import no.nav.syfo.personstatus.api.v2.apiModule
import no.nav.syfo.personstatus.api.v2.auth.getWellKnown
import no.nav.syfo.personstatus.infrastructure.clients.AktivitetskravClient
import no.nav.syfo.personstatus.infrastructure.clients.aktivitetskrav.AktivitetskravClient
import no.nav.syfo.personstatus.infrastructure.clients.arbeidsuforhet.ArbeidsuforhetvurderingClient
import no.nav.syfo.personstatus.infrastructure.clients.arbeidsuforhet.ManglendeMedvirkningClient
import no.nav.syfo.personstatus.infrastructure.clients.manglendemedvirkning.ManglendeMedvirkningClient
import no.nav.syfo.personstatus.infrastructure.clients.azuread.AzureAdClient
import no.nav.syfo.personstatus.infrastructure.clients.behandlendeenhet.BehandlendeEnhetClient
import no.nav.syfo.personstatus.infrastructure.clients.oppfolgingsoppgave.OppfolgingsoppgaveClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import no.nav.syfo.personstatus.domain.PersonIdent
import no.nav.syfo.oppfolgingstilfelle.domain.PersonOppfolgingstilfelleVirksomhet
import no.nav.syfo.personoppgavehendelse.kafka.*
import no.nav.syfo.personstatus.api.v2.model.PersonOversiktStatusDTO
import no.nav.syfo.personstatus.application.GetAktivitetskravForPersonsResponseDTO
import no.nav.syfo.personstatus.application.IAktivitetskravClient
import no.nav.syfo.personstatus.application.aktivitetskrav.GetAktivitetskravForPersonsResponseDTO
import no.nav.syfo.personstatus.application.aktivitetskrav.IAktivitetskravClient
import no.nav.syfo.personstatus.application.IPersonOversiktStatusRepository
import no.nav.syfo.personstatus.application.arbeidsuforhet.ArbeidsuforhetvurderingerResponseDTO
import no.nav.syfo.personstatus.application.arbeidsuforhet.IArbeidsuforhetvurderingClient
Expand Down Expand Up @@ -50,7 +50,7 @@ class PersonoversiktStatusService(
?: emptyList()
it.toPersonOversiktStatus(personOppfolgingstilfelleVirksomhetList)
}.filter { personOversiktStatus ->
personOversiktStatus.hasActiveOppgave() // TODO: Trenger vi denne når db-spørringen henter ut bare aktive personer?
personOversiktStatus.hasActiveOppgave()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package no.nav.syfo.personstatus.api.v2.model

import no.nav.syfo.personstatus.application.AktivitetskravDTO
import no.nav.syfo.personstatus.application.aktivitetskrav.AktivitetskravDTO
import no.nav.syfo.personstatus.application.arbeidsuforhet.ArbeidsuforhetvurderingDTO
import no.nav.syfo.personstatus.application.manglendemedvirkning.ManglendeMedvirkningDTO
import no.nav.syfo.personstatus.application.oppfolgingsoppgave.OppfolgingsoppgaveDTO
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.syfo.personstatus.application
package no.nav.syfo.personstatus.application.aktivitetskrav

import java.time.LocalDate
import java.time.LocalDateTime
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.syfo.personstatus.application
package no.nav.syfo.personstatus.application.aktivitetskrav

import no.nav.syfo.personstatus.domain.PersonIdent

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import no.nav.syfo.dialogmotestatusendring.domain.DialogmoteStatusendringType
import no.nav.syfo.oppfolgingstilfelle.domain.Oppfolgingstilfelle
import no.nav.syfo.oppfolgingstilfelle.domain.toPersonOppfolgingstilfelleDTO
import no.nav.syfo.personstatus.api.v2.model.PersonOversiktStatusDTO
import no.nav.syfo.personstatus.application.AktivitetskravDTO
import no.nav.syfo.personstatus.application.aktivitetskrav.AktivitetskravDTO
import no.nav.syfo.personstatus.application.arbeidsuforhet.ArbeidsuforhetvurderingDTO
import no.nav.syfo.personstatus.application.manglendemedvirkning.ManglendeMedvirkningDTO
import no.nav.syfo.personstatus.application.oppfolgingsoppgave.OppfolgingsoppgaveDTO
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.syfo.personstatus.infrastructure.clients
package no.nav.syfo.personstatus.infrastructure.clients.aktivitetskrav

import io.ktor.client.*
import io.ktor.client.call.body
Expand All @@ -12,10 +12,12 @@ import io.ktor.client.statement.HttpResponse
import io.ktor.http.*
import net.logstash.logback.argument.StructuredArguments
import no.nav.syfo.personstatus.domain.PersonIdent
import no.nav.syfo.personstatus.application.AktivitetskravRequestDTO
import no.nav.syfo.personstatus.application.GetAktivitetskravForPersonsResponseDTO
import no.nav.syfo.personstatus.application.IAktivitetskravClient
import no.nav.syfo.personstatus.application.aktivitetskrav.AktivitetskravRequestDTO
import no.nav.syfo.personstatus.application.aktivitetskrav.GetAktivitetskravForPersonsResponseDTO
import no.nav.syfo.personstatus.application.aktivitetskrav.IAktivitetskravClient
import no.nav.syfo.personstatus.infrastructure.clients.ClientEnvironment
import no.nav.syfo.personstatus.infrastructure.clients.azuread.AzureAdClient
import no.nav.syfo.personstatus.infrastructure.clients.httpClientDefault
import no.nav.syfo.util.NAV_CALL_ID_HEADER
import no.nav.syfo.util.bearerHeader
import no.nav.syfo.util.callIdArgument
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.syfo.personstatus.infrastructure.clients.arbeidsuforhet
package no.nav.syfo.personstatus.infrastructure.clients.manglendemedvirkning

import io.ktor.client.*
import io.ktor.client.call.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.mockk.*
import no.nav.syfo.aktivitetskravvurdering.domain.AktivitetskravStatus
import no.nav.syfo.oppfolgingstilfelle.kafka.toPersonOversiktStatus
import no.nav.syfo.personstatus.PersonoversiktStatusService
import no.nav.syfo.personstatus.application.IAktivitetskravClient
import no.nav.syfo.personstatus.application.aktivitetskrav.IAktivitetskravClient
import no.nav.syfo.personstatus.application.arbeidsuforhet.IArbeidsuforhetvurderingClient
import no.nav.syfo.personstatus.application.manglendemedvirkning.IManglendeMedvirkningClient
import no.nav.syfo.personstatus.application.oppfolgingsoppgave.IOppfolgingsoppgaveClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,7 @@ object PersonoversiktStatusApiV2Spek : Spek({
objectMapper.readValue<List<PersonOversiktStatusDTO>>(response.content!!).first()
personOversiktStatus.fnr shouldBeEqualTo personident
personOversiktStatus.enhet shouldBeEqualTo NAV_ENHET
personOversiktStatus.aktivitetskravvurdering shouldNotBe null
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.mockk.every
import io.mockk.mockk
import no.nav.syfo.personstatus.domain.PersonIdent
import no.nav.syfo.personstatus.PersonoversiktStatusService
import no.nav.syfo.personstatus.application.IAktivitetskravClient
import no.nav.syfo.personstatus.application.aktivitetskrav.IAktivitetskravClient
import no.nav.syfo.personstatus.application.arbeidsuforhet.IArbeidsuforhetvurderingClient
import no.nav.syfo.personstatus.application.manglendemedvirkning.IManglendeMedvirkningClient
import no.nav.syfo.personstatus.application.oppfolgingsoppgave.IOppfolgingsoppgaveClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import no.nav.syfo.personstatus.PersonoversiktStatusService
import no.nav.syfo.personstatus.application.IAktivitetskravClient
import no.nav.syfo.personstatus.application.aktivitetskrav.IAktivitetskravClient
import no.nav.syfo.personstatus.application.arbeidsuforhet.IArbeidsuforhetvurderingClient
import no.nav.syfo.personstatus.application.manglendemedvirkning.IManglendeMedvirkningClient
import no.nav.syfo.personstatus.application.oppfolgingsoppgave.IOppfolgingsoppgaveClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import no.nav.syfo.personstatus.PersonoversiktStatusService
import no.nav.syfo.personstatus.application.IAktivitetskravClient
import no.nav.syfo.personstatus.application.aktivitetskrav.IAktivitetskravClient
import no.nav.syfo.personstatus.application.arbeidsuforhet.IArbeidsuforhetvurderingClient
import no.nav.syfo.personstatus.application.manglendemedvirkning.IManglendeMedvirkningClient
import no.nav.syfo.personstatus.application.oppfolgingsoppgave.IOppfolgingsoppgaveClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import no.nav.syfo.personstatus.infrastructure.cronjob.behandlendeenhet.PersonBe
import no.nav.syfo.personstatus.infrastructure.cronjob.virksomhetsnavn.PersonOppfolgingstilfelleVirksomhetnavnCronjob
import no.nav.syfo.personstatus.infrastructure.cronjob.virksomhetsnavn.PersonOppfolgingstilfelleVirksomhetsnavnService
import no.nav.syfo.personstatus.PersonoversiktStatusService
import no.nav.syfo.personstatus.infrastructure.clients.AktivitetskravClient
import no.nav.syfo.personstatus.infrastructure.clients.aktivitetskrav.AktivitetskravClient
import no.nav.syfo.personstatus.infrastructure.clients.arbeidsuforhet.ArbeidsuforhetvurderingClient
import no.nav.syfo.personstatus.infrastructure.clients.arbeidsuforhet.ManglendeMedvirkningClient
import no.nav.syfo.personstatus.infrastructure.clients.manglendemedvirkning.ManglendeMedvirkningClient
import no.nav.syfo.personstatus.infrastructure.clients.azuread.AzureAdClient
import no.nav.syfo.personstatus.infrastructure.clients.oppfolgingsoppgave.OppfolgingsoppgaveClient
import no.nav.syfo.personstatus.infrastructure.database.repository.PersonOversiktStatusRepository
Expand Down
11 changes: 8 additions & 3 deletions src/test/kotlin/no/nav/syfo/testutil/TestApiModule.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package no.nav.syfo.testutil

import io.ktor.server.application.*
import io.mockk.mockk
import no.nav.syfo.application.cache.RedisStore
import no.nav.syfo.personstatus.infrastructure.clients.pdl.PdlClient
import no.nav.syfo.personstatus.PersonoversiktStatusService
import no.nav.syfo.personstatus.api.v2.apiModule
import no.nav.syfo.personstatus.infrastructure.clients.aktivitetskrav.AktivitetskravClient
import no.nav.syfo.personstatus.infrastructure.clients.arbeidsuforhet.ArbeidsuforhetvurderingClient
import no.nav.syfo.personstatus.infrastructure.clients.arbeidsuforhet.ManglendeMedvirkningClient
import no.nav.syfo.personstatus.infrastructure.clients.manglendemedvirkning.ManglendeMedvirkningClient
import no.nav.syfo.personstatus.infrastructure.clients.oppfolgingsoppgave.OppfolgingsoppgaveClient
import no.nav.syfo.personstatus.infrastructure.clients.azuread.AzureAdClient
import no.nav.syfo.personstatus.infrastructure.clients.veiledertilgang.VeilederTilgangskontrollClient
Expand Down Expand Up @@ -43,6 +43,11 @@ fun Application.testApiModule(
clientEnvironment = externalMockEnvironment.environment.clients.ishuskelapp,
httpClient = externalMockEnvironment.mockHttpClient
)
val aktivitetskravClient = AktivitetskravClient(
azureAdClient = azureAdClient,
clientEnvironment = externalMockEnvironment.environment.clients.aktivitetskrav,
httpClient = externalMockEnvironment.mockHttpClient
)
val veilederTilgangskontrollClient = VeilederTilgangskontrollClient(
azureAdClient = azureAdClient,
istilgangskontrollEnv = externalMockEnvironment.environment.clients.istilgangskontroll,
Expand All @@ -56,7 +61,7 @@ fun Application.testApiModule(
arbeidsuforhetvurderingClient = arbeidsuforhetvurderingClient,
manglendeMedvirkningClient = manglendeMedvirkningClient,
oppfolgingsoppgaveClient = oppfolgingsoppgaveClient,
aktivitetskravClient = mockk(relaxed = true),
aktivitetskravClient = aktivitetskravClient,
)

this.apiModule(
Expand Down
27 changes: 27 additions & 0 deletions src/test/kotlin/no/nav/syfo/testutil/mock/AktivitetskravMock.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package no.nav.syfo.testutil.mock

import io.ktor.client.engine.mock.*
import io.ktor.client.request.*
import no.nav.syfo.personstatus.application.aktivitetskrav.AktivitetskravDTO
import no.nav.syfo.personstatus.application.aktivitetskrav.AktivitetskravStatus
import no.nav.syfo.personstatus.application.aktivitetskrav.GetAktivitetskravForPersonsResponseDTO
import no.nav.syfo.testutil.UserConstants
import java.time.LocalDateTime
import java.util.UUID

fun MockRequestHandleScope.aktivitetskravMockResponse(): HttpResponseData =
respondOk(
GetAktivitetskravForPersonsResponseDTO(
mapOf(
Pair(
UserConstants.ARBEIDSTAKER_FNR,
AktivitetskravDTO(
uuid = UUID.randomUUID().toString(),
createdAt = LocalDateTime.now(),
status = AktivitetskravStatus.NY,
vurderinger = emptyList(),
),
),
),
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fun mockHttpClient(environment: Environment) = HttpClient(MockEngine) {
requestUrl.startsWith("/${environment.clients.arbeidsuforhetvurdering.baseUrl}") -> arbeidsuforhetVurderingMockResponse()
requestUrl.startsWith("/${environment.clients.ishuskelapp.baseUrl}") -> oppfolgingsoppgaveMockResponse()
requestUrl.startsWith("/${environment.clients.manglendeMedvirkning.baseUrl}") -> manglendeMedvirkningMockResponse()
requestUrl.startsWith("/${environment.clients.aktivitetskrav.baseUrl}") -> aktivitetskravMockResponse()

else -> error("Unhandled ${request.url.encodedPath}")
}
Expand Down

0 comments on commit ad98bc2

Please sign in to comment.