Skip to content

Commit 09e96b6

Browse files
JMLindsethArselanSultanivskjefst
committed
Begynn på test av post-endepunkt
Co-authored-by: Arselan Sultani <[email protected]> Co-authored-by: Vegard Skjefstad <[email protected]>
1 parent 19553b3 commit 09e96b6

File tree

9 files changed

+112
-13
lines changed

9 files changed

+112
-13
lines changed

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/db/InntektStore.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ data class StoreInntektCommand(
5656

5757
data class InntektPersonMapping(
5858
val inntektId: InntektId,
59-
val aktoerId: String,
59+
val aktørId: String,
6060
val fnr: String? = null,
6161
val kontekstId: String,
6262
val beregningsdato: LocalDate,

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/db/PostgresInntektStore.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ internal class PostgresInntektStore(
105105
).map { row ->
106106
InntektPersonMapping(
107107
inntektId = InntektId(row.string("inntektid")),
108-
aktoerId = row.string("aktorid"),
108+
aktørId = row.string("aktorid"),
109109
fnr = row.string("fnr"),
110110
kontekstId = row.string("kontekstid"),
111111
beregningsdato = row.zonedDateTime("beregningsdato").toLocalDate(),

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/mapping/GUIInntektsKomponentResponse.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ data class GUIInntekt(
2121
)
2222

2323
data class Inntektsmottaker(
24-
val fnr: String?,
24+
val pnr: String?,
2525
val navn: String?,
2626
)
2727

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/mapping/MapFromGUIInntekt.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ private fun mapToInntektkomponentResponse(inntekterDto: InntekterDto): Inntektko
7070
inntektMaaned.skattemessigBosattLand,
7171
inntektMaaned.utbetaltIMaaned,
7272
// TODO: Er det mottaker som skal brukes her?
73-
mapToAktoerNaturligIdent(inntekterDto.mottaker.fnr),
73+
mapToAktoerNaturligIdent(inntekterDto.mottaker.pnr),
7474
// TODO: Er det virksomhet som skal brukes her?
7575
mapToAktoerOrganisasjon(virksomhet),
7676
mapToAktoerOrganisasjon(virksomhet),
77-
mapToAktoerNaturligIdent(inntekterDto.mottaker.fnr),
77+
mapToAktoerNaturligIdent(inntekterDto.mottaker.pnr),
7878
inntektMaaned.inngaarIGrunnlagForTrekk,
7979
inntektMaaned.utloeserArbeidsgiveravgift,
8080
inntektMaaned.informasjonsstatus,
@@ -90,7 +90,7 @@ private fun mapToInntektkomponentResponse(inntekterDto: InntekterDto): Inntektko
9090

9191
return InntektkomponentResponse(
9292
arbeidsInntektMaaneder,
93-
mapToAktoerNaturligIdent(inntekterDto.mottaker.fnr),
93+
mapToAktoerNaturligIdent(inntekterDto.mottaker.pnr),
9494
)
9595
}
9696

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/v1/UklassifisertInntektRoute.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,13 @@ fun Route.uklassifisertInntekt(
175175
inntekterDto = call.receive<InntekterDto>(),
176176
inntektId = inntektId,
177177
).let {
178-
val person = personOppslag.hentPerson(it.inntekt.ident.identifikator)
179178
val inntektPersonMapping = inntektStore.getInntektPersonMapping(inntektId)
180179
inntektStore.storeInntekt(
181180
StoreInntektCommand(
182181
inntektparametre =
183182
Inntektparametre(
184-
aktørId = person.aktørId,
185-
fødselsnummer = person.fødselsnummer,
183+
aktørId = inntektPersonMapping.aktørId,
184+
fødselsnummer = it.inntekt.ident.identifikator,
186185
regelkontekst = RegelKontekst(inntektPersonMapping.kontekstId, inntektPersonMapping.kontekstType),
187186
beregningsdato = inntektPersonMapping.beregningsdato,
188187
),
@@ -195,7 +194,7 @@ fun Route.uklassifisertInntekt(
195194
),
196195
)
197196
}.let {
198-
call.respond(HttpStatusCode.OK, it.inntektId)
197+
call.respond(HttpStatusCode.OK, it.inntektId.id)
199198
}.also {
200199
inntektKorrigeringCounter.inc()
201200
}

dp-inntekt-api/src/test/kotlin/no/nav/dagpenger/inntekt/mapping/MapToInntektFrontendTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ val inntektkomponentResponse =
166166

167167
val mottaker =
168168
Inntektsmottaker(
169-
fnr = "2044350291600",
169+
pnr = "2044350291600",
170170
navn = "Ola Nordmann",
171171
)
172172

dp-inntekt-api/src/test/kotlin/no/nav/dagpenger/inntekt/v1/TestApplication.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import no.nav.security.mock.oauth2.MockOAuth2Server
2929
@Suppress("ktlint:standard:function-naming")
3030
internal object TestApplication {
3131
private const val ISSUER_ID = "default"
32+
const val TEST_OAUTH_USER = "user"
33+
3234
val mockOAuth2Server: MockOAuth2Server by lazy {
3335
MockOAuth2Server().also {
3436
it.start()
@@ -37,7 +39,7 @@ internal object TestApplication {
3739
val testOAuthToken: String by lazy {
3840
mockOAuth2Server.issueToken(
3941
issuerId = ISSUER_ID,
40-
subject = "user",
42+
subject = TEST_OAUTH_USER,
4143
).serialize()
4244
}
4345

dp-inntekt-api/src/test/kotlin/no/nav/dagpenger/inntekt/v1/UklassifisertInntektRouteTest.kt

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package no.nav.dagpenger.inntekt.v1
22

33
import com.fasterxml.jackson.module.kotlin.readValue
44
import de.huxhorn.sulky.ulid.ULID
5+
import io.kotest.matchers.nulls.shouldNotBeNull
56
import io.kotest.matchers.shouldBe
67
import io.ktor.client.request.get
78
import io.ktor.client.statement.bodyAsText
@@ -10,10 +11,13 @@ import io.ktor.http.HttpStatusCode
1011
import io.mockk.coEvery
1112
import io.mockk.every
1213
import io.mockk.mockk
14+
import io.mockk.slot
15+
import io.mockk.verify
1316
import kotlinx.coroutines.runBlocking
1417
import no.nav.dagpenger.inntekt.Problem
1518
import no.nav.dagpenger.inntekt.db.DetachedInntekt
1619
import no.nav.dagpenger.inntekt.db.InntektId
20+
import no.nav.dagpenger.inntekt.db.InntektPersonMapping
1721
import no.nav.dagpenger.inntekt.db.InntektStore
1822
import no.nav.dagpenger.inntekt.db.Inntektparametre
1923
import no.nav.dagpenger.inntekt.db.ManueltRedigert
@@ -38,6 +42,7 @@ import no.nav.dagpenger.inntekt.oppslag.Person
3842
import no.nav.dagpenger.inntekt.oppslag.PersonOppslag
3943
import no.nav.dagpenger.inntekt.oppslag.enhetsregister.EnhetsregisterClient
4044
import no.nav.dagpenger.inntekt.serder.jacksonObjectMapper
45+
import no.nav.dagpenger.inntekt.v1.TestApplication.TEST_OAUTH_USER
4146
import no.nav.dagpenger.inntekt.v1.TestApplication.autentisert
4247
import no.nav.dagpenger.inntekt.v1.TestApplication.mockInntektApi
4348
import no.nav.dagpenger.inntekt.v1.TestApplication.withMockAuthServerAndTestApplication
@@ -452,7 +457,7 @@ internal class UklassifisertInntektRouteTest {
452457
}
453458

454459
@Test
455-
fun `Get request for uklassifisert inntekt with inntektID should return 200 ok`() {
460+
fun `Get request for uklassifisert inntekt med inntektID returnerer 200 ok`() {
456461
val enhetsregisterClientMock = mockk<EnhetsregisterClient>(relaxed = true)
457462
return withMockAuthServerAndTestApplication(
458463
mockInntektApi(
@@ -496,4 +501,53 @@ internal class UklassifisertInntektRouteTest {
496501
assertEquals("", storedInntekt.virksomheter[1].virksomhetsnavn)
497502
}
498503
}
504+
505+
@Test
506+
fun `Post request for uklassifisert inntekt med inntektId lagrer og returnerer ny ID`() {
507+
return withMockAuthServerAndTestApplication(
508+
moduleFunction =
509+
mockInntektApi(
510+
inntektskomponentClient = inntektskomponentClientMock,
511+
inntektStore = inntektStoreMock,
512+
),
513+
) {
514+
val body =
515+
UklassifisertInntektRouteTest::class.java
516+
.getResource("/test-data/expected-uklassifisert-post-body.json")
517+
?.readText()
518+
val inntekterDto = jacksonObjectMapper.readValue<InntekterDto>(body!!)
519+
520+
val inntektPersonMapping =
521+
InntektPersonMapping(
522+
inntektId = inntektId,
523+
aktørId = "123456789",
524+
fnr = null,
525+
kontekstId = "kontekstId",
526+
beregningsdato = LocalDate.now(),
527+
timestamp = LocalDateTime.now(),
528+
kontekstType = "kontekstType",
529+
)
530+
every { inntektStoreMock.getInntektPersonMapping(any()) } returns inntektPersonMapping
531+
532+
val storeInntektCommandSlot = slot<StoreInntektCommand>()
533+
every { inntektStoreMock.storeInntekt(capture(storeInntektCommandSlot), any()) } returns storedInntekt
534+
535+
val response =
536+
autentisert(
537+
httpMethod = HttpMethod.Post,
538+
endepunkt = "$uklassifisertInntekt/${inntektId.id}",
539+
body = body,
540+
)
541+
542+
response.bodyAsText() shouldBe storedInntekt.inntektId.id
543+
verify(exactly = 1) { inntektStoreMock.storeInntekt(any(), any()) }
544+
storeInntektCommandSlot.captured.inntektparametre.aktørId shouldBe inntektPersonMapping.aktørId
545+
storeInntektCommandSlot.captured.inntektparametre.fødselsnummer shouldBe inntekterDto.mottaker.pnr
546+
storeInntektCommandSlot.captured.inntektparametre.regelkontekst.id shouldBe inntektPersonMapping.kontekstId
547+
storeInntektCommandSlot.captured.inntektparametre.regelkontekst.type shouldBe inntektPersonMapping.kontekstType
548+
storeInntektCommandSlot.captured.inntektparametre.beregningsdato shouldBe inntektPersonMapping.beregningsdato
549+
storeInntektCommandSlot.captured.manueltRedigert.shouldNotBeNull()
550+
storeInntektCommandSlot.captured.manueltRedigert!!.redigertAv shouldBe TEST_OAUTH_USER
551+
}
552+
}
499553
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"virksomheter": [
3+
{
4+
"virksomhetsnummer": "123456789",
5+
"virksomhetsnavn": "Test Virksomhet",
6+
"periode": {
7+
"fra": "2023-01",
8+
"til": "2023-12"
9+
},
10+
"inntekter": [
11+
{
12+
"belop": 50000.00,
13+
"fordel": "kontantytelse",
14+
"beskrivelse": "bil",
15+
"inntektskilde": "A-ordningen",
16+
"inntektsstatus": "LoependeInnrapportert",
17+
"inntektsperiodetype": "Maaned",
18+
"leveringstidspunkt": "2023-01",
19+
"opptjeningsland": "NO",
20+
"opptjeningsperiode": null,
21+
"skattemessigBosattLand": "NO",
22+
"utbetaltIMaaned": "2023-01",
23+
"inntektsinnsender": null,
24+
"virksomhet": null,
25+
"inntektsmottaker": null,
26+
"inngaarIGrunnlagForTrekk": true,
27+
"utloeserArbeidsgiveravgift": true,
28+
"informasjonsstatus": "InngaarAlltid",
29+
"inntektType": "LOENNSINNTEKT",
30+
"tilleggsinformasjon": null,
31+
"redigert": true,
32+
"begrunnelse": "Standard",
33+
"aarMaaned": "2023-01"
34+
}
35+
],
36+
"totalBeløp": 50000.00,
37+
"avvikListe": []
38+
}
39+
],
40+
"mottaker": {
41+
"pnr": "19876543210",
42+
"navn": "Navn Navnesen"
43+
}
44+
}

0 commit comments

Comments
 (0)