|
| 1 | +package no.nav.dagpenger.inntekt.api.v3 |
| 2 | + |
| 3 | +import io.kotest.matchers.shouldBe |
| 4 | +import io.ktor.http.HttpMethod |
| 5 | +import io.ktor.http.HttpStatusCode |
| 6 | +import io.mockk.every |
| 7 | +import io.mockk.mockk |
| 8 | +import kotlinx.coroutines.runBlocking |
| 9 | +import no.nav.dagpenger.inntekt.BehandlingsInntektsGetter |
| 10 | +import no.nav.dagpenger.inntekt.api.v1.TestApplication.autentisert |
| 11 | +import no.nav.dagpenger.inntekt.api.v1.TestApplication.mockInntektApi |
| 12 | +import no.nav.dagpenger.inntekt.api.v1.TestApplication.withMockAuthServerAndTestApplication |
| 13 | +import no.nav.dagpenger.inntekt.db.Inntektparametre |
| 14 | +import no.nav.dagpenger.inntekt.db.RegelKontekst |
| 15 | +import no.nav.dagpenger.inntekt.oppslag.Person |
| 16 | +import no.nav.dagpenger.inntekt.oppslag.PersonOppslag |
| 17 | +import no.nav.dagpenger.inntekt.serder.jacksonObjectMapper |
| 18 | +import java.time.LocalDate |
| 19 | +import java.time.YearMonth |
| 20 | +import kotlin.test.Test |
| 21 | + |
| 22 | +class KlassifisertInntektRouteV3Test { |
| 23 | + val fødselsnummer = "12345678901" |
| 24 | + val aktørId = "12345" |
| 25 | + private val personOppslagMock: PersonOppslag = mockk() |
| 26 | + private val behandlingsInntektsGetterMock: BehandlingsInntektsGetter = mockk() |
| 27 | + private val inntektParametreCapture = mutableListOf<Inntektparametre>() |
| 28 | + |
| 29 | + init { |
| 30 | + every { |
| 31 | + runBlocking { personOppslagMock.hentPerson(any()) } |
| 32 | + } returns |
| 33 | + Person( |
| 34 | + fødselsnummer, |
| 35 | + aktørId, |
| 36 | + "Navn", |
| 37 | + null, |
| 38 | + "Navnesen", |
| 39 | + ) |
| 40 | + every { |
| 41 | + runBlocking { |
| 42 | + behandlingsInntektsGetterMock.getKlassifisertInntekt( |
| 43 | + capture(inntektParametreCapture), |
| 44 | + any(), |
| 45 | + ) |
| 46 | + } |
| 47 | + } returns |
| 48 | + mockk(relaxed = true) |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + fun `Inntektparametre is created with expected values`() { |
| 53 | + val regelkontekst = RegelKontekst("id", "type") |
| 54 | + val beregningsDato = LocalDate.of(2018, 5, 27) |
| 55 | + val periodeFraOgMed = YearMonth.of(2017, 1) |
| 56 | + val periodeTilOgMed = YearMonth.of(2018, 12) |
| 57 | + |
| 58 | + withMockAuthServerAndTestApplication( |
| 59 | + mockInntektApi( |
| 60 | + personOppslag = personOppslagMock, |
| 61 | + behandlingsInntektsGetter = behandlingsInntektsGetterMock, |
| 62 | + ), |
| 63 | + ) { |
| 64 | + val response = |
| 65 | + autentisert( |
| 66 | + httpMethod = HttpMethod.Post, |
| 67 | + endepunkt = "/v3/inntekt/klassifisert", |
| 68 | + body = |
| 69 | + jacksonObjectMapper.writeValueAsString( |
| 70 | + InntektRequestDto( |
| 71 | + fødselsnummer, |
| 72 | + regelkontekst, |
| 73 | + beregningsDato, |
| 74 | + periodeFraOgMed, |
| 75 | + periodeTilOgMed, |
| 76 | + ), |
| 77 | + ), |
| 78 | + ) |
| 79 | + |
| 80 | + response.status shouldBe HttpStatusCode.OK |
| 81 | + val inntektparametre = inntektParametreCapture.first() |
| 82 | + inntektparametre.aktørId shouldBe aktørId |
| 83 | + inntektparametre.fødselsnummer shouldBe fødselsnummer |
| 84 | + inntektparametre.regelkontekst shouldBe regelkontekst |
| 85 | + inntektparametre.beregningsdato shouldBe beregningsDato |
| 86 | + inntektparametre.opptjeningsperiode.førsteMåned shouldBe periodeFraOgMed |
| 87 | + inntektparametre.opptjeningsperiode.sisteAvsluttendeKalenderMåned shouldBe periodeTilOgMed |
| 88 | + } |
| 89 | + } |
| 90 | +} |
0 commit comments