Skip to content

Commit

Permalink
Simplify job that sends notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
kaja-nav committed Nov 8, 2023
1 parent a48c243 commit 0f6571b
Showing 1 changed file with 23 additions and 36 deletions.
59 changes: 23 additions & 36 deletions src/test/kotlin/no/nav/syfo/api/JobApiSpek.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package no.nav.syfo.api

import io.kotest.core.spec.style.DescribeSpec
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.plugins.contentnegotiation.*
import io.ktor.server.routing.*
import io.ktor.server.testing.*
import io.ktor.http.HttpMethod
import io.ktor.http.isSuccess
import io.ktor.server.application.install
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
import io.ktor.server.routing.routing
import io.ktor.server.testing.TestApplicationEngine
import io.ktor.server.testing.handleRequest
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.justRun
Expand All @@ -14,32 +16,36 @@ import no.nav.syfo.api.job.registerJobTriggerApi
import no.nav.syfo.api.job.urlPathJobTrigger
import no.nav.syfo.db.domain.PPlanlagtVarsel
import no.nav.syfo.db.domain.VarselType
import no.nav.syfo.getTestEnv
import no.nav.syfo.job.VarselSender
import no.nav.syfo.kafka.producers.brukernotifikasjoner.BrukernotifikasjonKafkaProducer
import no.nav.syfo.service.*
import no.nav.syfo.service.AccessControlService
import no.nav.syfo.service.MerVeiledningVarselFinder
import no.nav.syfo.service.MerVeiledningVarselService
import no.nav.syfo.service.microfrontend.MikrofrontendService
import no.nav.syfo.testutil.EmbeddedDatabase
import no.nav.syfo.testutil.mocks.*
import no.nav.syfo.testutil.mocks.fnr1
import no.nav.syfo.testutil.mocks.fnr2
import no.nav.syfo.testutil.mocks.fnr3
import no.nav.syfo.testutil.mocks.fnr4
import no.nav.syfo.testutil.mocks.fnr5
import no.nav.syfo.testutil.mocks.orgnummer
import no.nav.syfo.testutil.mocks.userAccessStatus1
import no.nav.syfo.testutil.mocks.userAccessStatus2
import no.nav.syfo.testutil.mocks.userAccessStatus3
import no.nav.syfo.testutil.mocks.userAccessStatus4
import no.nav.syfo.testutil.mocks.userAccessStatus5
import no.nav.syfo.util.contentNegotationFeature
import org.amshove.kluent.shouldBeEqualTo
import java.time.LocalDate
import java.time.LocalDateTime
import java.util.*

class JobApiSpek : DescribeSpec({
val testEnv = getTestEnv()

timeout = 20000L

describe("JobTriggerApi test") {
val embeddedDatabase by lazy { EmbeddedDatabase() }
val accessControlService = mockk<AccessControlService>()
val brukernotifikasjonKafkaProducer = mockk<BrukernotifikasjonKafkaProducer>()
val merVeiledningVarselFinder = mockk<MerVeiledningVarselFinder>(relaxed = true)
val dokarkivService = mockk<DokarkivService>()
val merVeiledningVarselService = mockk<MerVeiledningVarselService>()
val sykmeldingService = mockk<SykmeldingService>()
val mikrofrontendService = mockk<MikrofrontendService>()

coEvery { accessControlService.getUserAccessStatus(fnr1) } returns userAccessStatus1
Expand Down Expand Up @@ -100,32 +106,13 @@ class JobApiSpek : DescribeSpec({
LocalDateTime.now(),
),
)
coEvery {
sykmeldingService.checkSykmeldingStatusForVirksomhet(
any(),
any(),
any(),
)
} returns SykmeldingStatus(isSykmeldtIJobb = false, sendtArbeidsgiver = true)
coEvery { brukernotifikasjonKafkaProducer.sendBeskjed(any(), any(), any(), any(), any()) } returns Unit
coEvery { dokarkivService.getJournalpostId(any(), any(), any()) } returns "1"
coEvery { sykmeldingService.isPersonSykmeldtPaDato(any(), any()) } returns true
coEvery { merVeiledningVarselFinder.isBrukerYngreEnn67Ar(any()) } returns true

justRun { mikrofrontendService.findAndCloseExpiredMikrofrontends() }

val sendVarselService =
SendVarselService(
accessControlService,
testEnv.urlEnv,
merVeiledningVarselService,
merVeiledningVarselFinder,
)
val varselSender =
VarselSender(
embeddedDatabase,
sendVarselService,
merVeiledningVarselFinder,
merVeiledningVarselService
)

with(TestApplicationEngine()) {
Expand All @@ -138,7 +125,7 @@ class JobApiSpek : DescribeSpec({
it("esyfovarsel-job trigger utsending av 2 varsler digitalt og 3 varsler som brev") {
with(handleRequest(HttpMethod.Post, urlPathJobTrigger)) {
response.status()?.isSuccess() shouldBeEqualTo true
coVerify(exactly = 5) { merVeiledningVarselService.sendVarselTilArbeidstaker(any(), any(), any()) }
coVerify(exactly = 5) { merVeiledningVarselService.sendVarselTilArbeidstaker(any(), any()) }
}
}
}
Expand Down

0 comments on commit 0f6571b

Please sign in to comment.