-
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.
Legg til integrasjonstest for henting av selvbestemt IM (#693)
- Loading branch information
Showing
4 changed files
with
163 additions
and
2 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
159 changes: 159 additions & 0 deletions
159
...est/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/integrasjonstest/HentSelvbestemtIT.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,159 @@ | ||
package no.nav.helsearbeidsgiver.inntektsmelding.integrasjonstest | ||
|
||
import io.kotest.matchers.collections.shouldBeEmpty | ||
import io.kotest.matchers.collections.shouldHaveSize | ||
import io.kotest.matchers.nulls.shouldBeNull | ||
import io.kotest.matchers.nulls.shouldNotBeNull | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.string.shouldNotBeEmpty | ||
import kotlinx.serialization.builtins.serializer | ||
import no.nav.helsearbeidsgiver.domene.inntektsmelding.v1.Inntektsmelding | ||
import no.nav.helsearbeidsgiver.felles.BehovType | ||
import no.nav.helsearbeidsgiver.felles.EventName | ||
import no.nav.helsearbeidsgiver.felles.Key | ||
import no.nav.helsearbeidsgiver.felles.domene.ResultJson | ||
import no.nav.helsearbeidsgiver.felles.json.lesOrNull | ||
import no.nav.helsearbeidsgiver.felles.json.toJson | ||
import no.nav.helsearbeidsgiver.felles.json.toMap | ||
import no.nav.helsearbeidsgiver.felles.rapidsrivers.model.Fail | ||
import no.nav.helsearbeidsgiver.felles.rapidsrivers.redis.RedisPrefix | ||
import no.nav.helsearbeidsgiver.felles.test.json.lesBehov | ||
import no.nav.helsearbeidsgiver.felles.test.mock.mockInntektsmeldingV1 | ||
import no.nav.helsearbeidsgiver.inntektsmelding.integrasjonstest.utils.EndToEndTest | ||
import no.nav.helsearbeidsgiver.utils.json.fromJson | ||
import no.nav.helsearbeidsgiver.utils.json.serializer.UuidSerializer | ||
import no.nav.helsearbeidsgiver.utils.json.toJson | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.TestInstance | ||
import java.util.UUID | ||
|
||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
class HentSelvbestemtIT : EndToEndTest() { | ||
@BeforeEach | ||
fun setup() { | ||
truncateDatabase() | ||
} | ||
|
||
@Test | ||
fun `selvbestemt inntektsmelding hentes`() { | ||
val transaksjonId: UUID = UUID.randomUUID() | ||
val inntektsmelding = | ||
mockInntektsmeldingV1().copy( | ||
type = | ||
Inntektsmelding.Type.Selvbestemt( | ||
id = UUID.randomUUID(), | ||
), | ||
) | ||
|
||
selvbestemtImRepo.lagreIm(inntektsmelding) | ||
|
||
publish( | ||
Key.EVENT_NAME to EventName.SELVBESTEMT_IM_REQUESTED.toJson(), | ||
Key.UUID to transaksjonId.toJson(UuidSerializer), | ||
Key.DATA to | ||
mapOf( | ||
Key.SELVBESTEMT_ID to inntektsmelding.type.id.toJson(UuidSerializer), | ||
).toJson(), | ||
) | ||
|
||
// Ingen feil | ||
messages.filterFeil().all().shouldBeEmpty() | ||
|
||
// Behov publiseres | ||
messages | ||
.filter(EventName.SELVBESTEMT_IM_REQUESTED) | ||
.filter(BehovType.HENT_SELVBESTEMT_IM) | ||
.firstAsMap() | ||
.let { msg -> | ||
Key.UUID.lesOrNull(UuidSerializer, msg) shouldBe transaksjonId | ||
|
||
val data = msg[Key.DATA].shouldNotBeNull().toMap() | ||
Key.SELVBESTEMT_ID.lesOrNull(UuidSerializer, data) shouldBe inntektsmelding.type.id | ||
} | ||
|
||
// Behov besvares | ||
messages | ||
.filter(EventName.SELVBESTEMT_IM_REQUESTED) | ||
.filter(Key.SELVBESTEMT_INNTEKTSMELDING) | ||
.firstAsMap() | ||
.let { msg -> | ||
Key.UUID.lesOrNull(UuidSerializer, msg) shouldBe transaksjonId | ||
|
||
val data = msg[Key.DATA].shouldNotBeNull().toMap() | ||
Key.SELVBESTEMT_ID.lesOrNull(UuidSerializer, data) shouldBe inntektsmelding.type.id | ||
Key.SELVBESTEMT_INNTEKTSMELDING.lesOrNull(Inntektsmelding.serializer(), data) shouldBe inntektsmelding | ||
} | ||
|
||
// Funnet inntektsmelding legges i Redis | ||
val redisResponse = | ||
redisConnection | ||
.get(RedisPrefix.HentSelvbestemtIm, transaksjonId) | ||
.shouldNotBeNull() | ||
.fromJson(ResultJson.serializer()) | ||
|
||
redisResponse.success.shouldNotBeNull().fromJson(Inntektsmelding.serializer()) shouldBe inntektsmelding | ||
redisResponse.failure.shouldBeNull() | ||
} | ||
|
||
@Test | ||
fun `selvbestemt inntektsmelding finnes ikke`() { | ||
val transaksjonId: UUID = UUID.randomUUID() | ||
val inntektsmelding = | ||
mockInntektsmeldingV1().copy( | ||
type = | ||
Inntektsmelding.Type.Selvbestemt( | ||
id = UUID.randomUUID(), | ||
), | ||
) | ||
|
||
publish( | ||
Key.EVENT_NAME to EventName.SELVBESTEMT_IM_REQUESTED.toJson(), | ||
Key.UUID to transaksjonId.toJson(UuidSerializer), | ||
Key.DATA to | ||
mapOf( | ||
Key.SELVBESTEMT_ID to inntektsmelding.type.id.toJson(UuidSerializer), | ||
).toJson(), | ||
) | ||
|
||
// Én feil | ||
messages.filterFeil().all() shouldHaveSize 1 | ||
|
||
// Behov publiseres | ||
messages | ||
.filter(EventName.SELVBESTEMT_IM_REQUESTED) | ||
.filter(BehovType.HENT_SELVBESTEMT_IM) | ||
.firstAsMap() | ||
.let { msg -> | ||
Key.UUID.lesOrNull(UuidSerializer, msg) shouldBe transaksjonId | ||
|
||
val data = msg[Key.DATA].shouldNotBeNull().toMap() | ||
Key.SELVBESTEMT_ID.lesOrNull(UuidSerializer, data) shouldBe inntektsmelding.type.id | ||
} | ||
|
||
// Behov besvares med feil | ||
messages | ||
.filter(EventName.SELVBESTEMT_IM_REQUESTED) | ||
.filterFeil() | ||
.firstAsMap() | ||
.let { | ||
Key.UUID.lesOrNull(UuidSerializer, it) shouldBe transaksjonId | ||
|
||
val fail = Key.FAIL.lesOrNull(Fail.serializer(), it).shouldNotBeNull() | ||
fail.utloesendeMelding.lesBehov() shouldBe BehovType.HENT_SELVBESTEMT_IM | ||
} | ||
|
||
// Funnet feilmelding legges i Redis | ||
val redisResponse = | ||
redisConnection | ||
.get(RedisPrefix.HentSelvbestemtIm, transaksjonId) | ||
.shouldNotBeNull() | ||
.fromJson(ResultJson.serializer()) | ||
|
||
redisResponse.success.shouldBeNull() | ||
redisResponse.failure | ||
.shouldNotBeNull() | ||
.fromJson(String.serializer()) | ||
.shouldNotBeEmpty() | ||
} | ||
} |
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