-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Utvidet tester for ansvar og fikset bugs
- Loading branch information
Showing
4 changed files
with
92 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
apps/bekreftelse-tjeneste/src/test/kotlin/no/nav/paw/bekreftelsetjeneste/TestUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package no.nav.paw.bekreftelsetjeneste | ||
|
||
import io.kotest.assertions.withClue | ||
import io.kotest.matchers.shouldBe | ||
import no.nav.paw.bekreftelsetjeneste.config.BekreftelseIntervals | ||
import no.nav.paw.bekreftelsetjeneste.tilstand.* | ||
import java.time.Instant | ||
import java.util.* | ||
|
||
inline fun <T1: Any, reified T2: T1> List<T1>.assertExactlyOne(f: T2.() -> Unit) = | ||
filterIsInstance<T2>() | ||
.let { | ||
withClue("Expected exactly one ${T2::class.simpleName} but found ${it.size}") { | ||
it.size shouldBe 1 | ||
} | ||
it.first() | ||
}.apply(f) | ||
|
||
fun internTilstand( | ||
periodeStart: Instant, | ||
periodeId: UUID = UUID.randomUUID(), | ||
identitetsnummer: String = "12345678901", | ||
arbeidsoekerId: Long = 1L, | ||
recordKey: Long = 1L, | ||
avsluttet: Instant? = null, | ||
bekreftelser: List<Bekreftelse> = emptyList() | ||
) = InternTilstand( | ||
periode = PeriodeInfo( | ||
periodeId = periodeId, | ||
identitetsnummer = identitetsnummer, | ||
arbeidsoekerId = arbeidsoekerId, | ||
recordKey = recordKey, | ||
startet = periodeStart, | ||
avsluttet = avsluttet | ||
), | ||
bekreftelser = bekreftelser | ||
) | ||
|
||
fun BekreftelseIntervals.bekreftelse( | ||
gjelderFra: Instant = Instant.now(), | ||
gjelderTil: Instant = gjelderFra + interval, | ||
ikkeKlarForUtfylling: IkkeKlarForUtfylling? = IkkeKlarForUtfylling(gjelderFra), | ||
klarForUtfylling: KlarForUtfylling? = KlarForUtfylling(gjelderFra + interval - tilgjengeligOffset), | ||
venterSvar: VenterSvar? = VenterSvar(gjelderFra + interval), | ||
gracePeriodeVarselet: GracePeriodeVarselet? = GracePeriodeVarselet(gjelderFra + interval + varselFoerGraceperiodeUtloept), | ||
gracePeriodeUtloept: GracePeriodeUtloept? = GracePeriodeUtloept(gjelderFra + interval + graceperiode) | ||
): Bekreftelse = Bekreftelse( | ||
tilstandsLogg = listOfNotNull( | ||
ikkeKlarForUtfylling, | ||
klarForUtfylling, | ||
venterSvar, | ||
gracePeriodeVarselet, | ||
gracePeriodeUtloept | ||
).sortedBy { it.timestamp } | ||
.let { | ||
BekreftelseTilstandsLogg( | ||
siste = it.last(), | ||
tidligere = it.dropLast(1) | ||
) | ||
}, | ||
bekreftelseId = UUID.randomUUID(), | ||
gjelderFra = gjelderFra, | ||
gjelderTil = gjelderTil | ||
) | ||
|
||
fun BekreftelseIntervals.gracePeriodeVarsel(startTid: Instant): Instant = | ||
startTid.plus(interval).plus(graceperiode).minus(varselFoerGraceperiodeUtloept) | ||
|
||
fun BekreftelseIntervals.gracePeriodeUtloeper(startTid: Instant): Instant = | ||
startTid.plus(interval).plus(graceperiode) | ||
|
||
fun BekreftelseIntervals.tilgjengelig(startTid: Instant): Instant = startTid.plus(interval).plus(tilgjengeligOffset) | ||
|
||
fun BekreftelseIntervals.frist(startTid: Instant): Instant = startTid.plus(interval) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters