Skip to content

Commit ac3d2c9

Browse files
vskjefstJMLindseth
andcommitted
Returner begrunnelse for redigering i responsen
Co-authored-by: John Martin Lindseth <[email protected]>
1 parent 4c8b32e commit ac3d2c9

File tree

3 files changed

+167
-29
lines changed

3 files changed

+167
-29
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ internal fun Application.inntektApi(
240240
}
241241
authenticate("azure") {
242242
route("/v3/inntekt") {
243-
inntektV3(behandlingsInntektsGetter, personOppslag)
243+
inntektV3(behandlingsInntektsGetter, personOppslag, inntektStore)
244244
}
245245
}
246246
naischecks(healthChecks, meterRegistry)

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/api/v3/KlassifisertInntektRouteV3.kt

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,77 @@ import io.ktor.server.routing.route
1010
import kotlinx.coroutines.Dispatchers.IO
1111
import kotlinx.coroutines.withContext
1212
import no.nav.dagpenger.inntekt.BehandlingsInntektsGetter
13+
import no.nav.dagpenger.inntekt.db.InntektId
14+
import no.nav.dagpenger.inntekt.db.InntektStore
1315
import no.nav.dagpenger.inntekt.db.Inntektparametre
16+
import no.nav.dagpenger.inntekt.db.ManueltRedigert
1417
import no.nav.dagpenger.inntekt.db.RegelKontekst
1518
import no.nav.dagpenger.inntekt.oppslag.PersonOppslag
19+
import no.nav.dagpenger.inntekt.v1.Inntekt
20+
import no.nav.dagpenger.inntekt.v1.KlassifisertInntektMåned
1621
import java.time.LocalDate
1722
import java.time.YearMonth
1823

1924
fun Route.inntektV3(
2025
behandlingsInntektsGetter: BehandlingsInntektsGetter,
2126
personOppslag: PersonOppslag,
27+
inntektStore: InntektStore,
2228
) {
2329
route("/klassifisert") {
2430
post {
2531
withContext(IO) {
26-
val inntektRequestDto = call.receive<InntektRequestDto>()
27-
val person = personOppslag.hentPerson(inntektRequestDto.personIdentifikator)
32+
val klassifisertInntektRequestDto = call.receive<KlassifisertInntektRequestDto>()
33+
val person = personOppslag.hentPerson(klassifisertInntektRequestDto.personIdentifikator)
2834
val inntektparametre =
2935
Inntektparametre(
3036
aktørId = person.aktørId,
3137
fødselsnummer = person.fødselsnummer,
32-
regelkontekst = inntektRequestDto.regelkontekst,
33-
beregningsdato = inntektRequestDto.beregningsDato,
38+
regelkontekst = klassifisertInntektRequestDto.regelkontekst,
39+
beregningsdato = klassifisertInntektRequestDto.beregningsDato,
3440
).apply {
35-
opptjeningsperiode.førsteMåned = inntektRequestDto.periodeFraOgMed
36-
opptjeningsperiode.sisteAvsluttendeKalenderMåned = inntektRequestDto.periodeTilOgMed
41+
opptjeningsperiode.førsteMåned = klassifisertInntektRequestDto.periodeFraOgMed
42+
opptjeningsperiode.sisteAvsluttendeKalenderMåned = klassifisertInntektRequestDto.periodeTilOgMed
3743
}
3844
val klassifisertInntekt =
3945
behandlingsInntektsGetter.getKlassifisertInntekt(
4046
inntektparametre,
4147
call.callId,
4248
)
43-
call.respond(HttpStatusCode.OK, klassifisertInntekt)
49+
val manueltRedigert = inntektStore.getManueltRedigert(InntektId(klassifisertInntekt.inntektsId))
50+
51+
call.respond(
52+
HttpStatusCode.OK,
53+
mapToKlassifisertInntektResponseDto(klassifisertInntekt, manueltRedigert),
54+
)
4455
}
4556
}
4657
}
4758
}
4859

49-
data class InntektRequestDto(
60+
data class KlassifisertInntektRequestDto(
5061
val personIdentifikator: String,
5162
val regelkontekst: RegelKontekst,
5263
val beregningsDato: LocalDate,
5364
val periodeFraOgMed: YearMonth,
5465
val periodeTilOgMed: YearMonth,
5566
)
67+
68+
data class KlassifisertInntektResponseDto(
69+
val inntektsId: String,
70+
val inntektsListe: List<KlassifisertInntektMåned>,
71+
val manueltRedigert: Boolean? = false,
72+
val begrunnelseManueltRedigert: String? = null,
73+
val sisteAvsluttendeKalenderMåned: YearMonth,
74+
)
75+
76+
private fun mapToKlassifisertInntektResponseDto(
77+
inntekt: Inntekt,
78+
manueltRedigert: ManueltRedigert?,
79+
): KlassifisertInntektResponseDto =
80+
KlassifisertInntektResponseDto(
81+
inntektsId = inntekt.inntektsId,
82+
inntektsListe = inntekt.inntektsListe,
83+
manueltRedigert = inntekt.manueltRedigert,
84+
begrunnelseManueltRedigert = manueltRedigert?.begrunnelse,
85+
sisteAvsluttendeKalenderMåned = inntekt.sisteAvsluttendeKalenderMåned,
86+
)
Lines changed: 127 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,50 @@
11
package no.nav.dagpenger.inntekt.api.v3
22

3+
import com.fasterxml.jackson.module.kotlin.readValue
4+
import de.huxhorn.sulky.ulid.ULID
5+
import io.kotest.matchers.collections.shouldNotBeEmpty
36
import io.kotest.matchers.shouldBe
7+
import io.ktor.client.statement.bodyAsText
48
import io.ktor.http.HttpMethod
59
import io.ktor.http.HttpStatusCode.Companion.OK
10+
import io.mockk.coEvery
611
import io.mockk.every
712
import io.mockk.mockk
8-
import kotlinx.coroutines.runBlocking
913
import no.nav.dagpenger.inntekt.BehandlingsInntektsGetter
1014
import no.nav.dagpenger.inntekt.api.v1.TestApplication.autentisert
1115
import no.nav.dagpenger.inntekt.api.v1.TestApplication.mockInntektApi
1216
import no.nav.dagpenger.inntekt.api.v1.TestApplication.withMockAuthServerAndTestApplication
17+
import no.nav.dagpenger.inntekt.db.InntektStore
1318
import no.nav.dagpenger.inntekt.db.Inntektparametre
19+
import no.nav.dagpenger.inntekt.db.ManueltRedigert
1420
import no.nav.dagpenger.inntekt.db.RegelKontekst
1521
import no.nav.dagpenger.inntekt.oppslag.Person
1622
import no.nav.dagpenger.inntekt.oppslag.PersonOppslag
1723
import no.nav.dagpenger.inntekt.serder.jacksonObjectMapper
24+
import no.nav.dagpenger.inntekt.v1.Inntekt
25+
import no.nav.dagpenger.inntekt.v1.KlassifisertInntektMåned
1826
import java.time.LocalDate
1927
import java.time.YearMonth
28+
import java.time.YearMonth.now
2029
import kotlin.test.Test
2130

2231
class KlassifisertInntektRouteV3Test {
23-
val fødselsnummer = "12345678901"
24-
val aktørId = "12345"
32+
private val fødselsnummer = "12345678901"
33+
private val aktørId = "12345"
2534
private val personOppslagMock: PersonOppslag = mockk()
2635
private val behandlingsInntektsGetterMock: BehandlingsInntektsGetter = mockk()
2736
private val inntektParametreCapture = mutableListOf<Inntektparametre>()
37+
private val inntektStoreMock: InntektStore = mockk()
38+
private val regelkontekst = RegelKontekst("id", "type")
39+
private val beregningsDato = LocalDate.of(2018, 5, 27)!!
40+
private val periodeFraOgMed = YearMonth.of(2017, 1)!!
41+
private val periodeTilOgMed = YearMonth.of(2018, 12)!!
42+
private val inntektsId = ULID().nextULID()
43+
private val sisteAvsluttendeKalenderMåned = now()
2844

2945
init {
30-
every {
31-
runBlocking { personOppslagMock.hentPerson(any()) }
46+
coEvery {
47+
personOppslagMock.hentPerson(any())
3248
} returns
3349
Person(
3450
fødselsnummer,
@@ -37,28 +53,24 @@ class KlassifisertInntektRouteV3Test {
3753
null,
3854
"Navnesen",
3955
)
40-
every {
41-
runBlocking {
42-
behandlingsInntektsGetterMock.getKlassifisertInntekt(
43-
capture(inntektParametreCapture),
44-
any(),
45-
)
46-
}
47-
} returns
48-
mockk(relaxed = true)
56+
57+
coEvery {
58+
behandlingsInntektsGetterMock.getKlassifisertInntekt(
59+
capture(inntektParametreCapture),
60+
any(),
61+
)
62+
} returns createInntekt(true)
63+
64+
every { inntektStoreMock.getManueltRedigert(any()) } returns mockk(relaxed = true)
4965
}
5066

5167
@Test
5268
fun `Inntektparametre opprettes med forventede verdier`() {
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-
5869
withMockAuthServerAndTestApplication(
5970
mockInntektApi(
6071
personOppslag = personOppslagMock,
6172
behandlingsInntektsGetter = behandlingsInntektsGetterMock,
73+
inntektStore = inntektStoreMock,
6274
),
6375
) {
6476
val response =
@@ -67,7 +79,7 @@ class KlassifisertInntektRouteV3Test {
6779
endepunkt = "/v3/inntekt/klassifisert",
6880
body =
6981
jacksonObjectMapper.writeValueAsString(
70-
InntektRequestDto(
82+
KlassifisertInntektRequestDto(
7183
fødselsnummer,
7284
regelkontekst,
7385
beregningsDato,
@@ -87,4 +99,99 @@ class KlassifisertInntektRouteV3Test {
8799
inntektparametre.opptjeningsperiode.sisteAvsluttendeKalenderMåned shouldBe periodeTilOgMed
88100
}
89101
}
102+
103+
@Test
104+
fun `Klassifisert-endepunktet returnerer forventet respons når inntekten er manuelt redigert`() {
105+
every { inntektStoreMock.getManueltRedigert(any()) } returns
106+
ManueltRedigert(
107+
"N313373",
108+
"Dette er en begrunnelse.",
109+
)
110+
111+
withMockAuthServerAndTestApplication(
112+
mockInntektApi(
113+
personOppslag = personOppslagMock,
114+
behandlingsInntektsGetter = behandlingsInntektsGetterMock,
115+
inntektStore = inntektStoreMock,
116+
),
117+
) {
118+
val response =
119+
autentisert(
120+
httpMethod = HttpMethod.Post,
121+
endepunkt = "/v3/inntekt/klassifisert",
122+
body =
123+
jacksonObjectMapper.writeValueAsString(
124+
KlassifisertInntektRequestDto(
125+
fødselsnummer,
126+
regelkontekst,
127+
beregningsDato,
128+
periodeFraOgMed,
129+
periodeTilOgMed,
130+
),
131+
),
132+
)
133+
134+
response.status shouldBe OK
135+
val klassifisertInntektResponseDto =
136+
jacksonObjectMapper.readValue<KlassifisertInntektResponseDto>(response.bodyAsText())
137+
klassifisertInntektResponseDto.inntektsId shouldBe inntektsId
138+
klassifisertInntektResponseDto.inntektsListe.shouldNotBeEmpty()
139+
klassifisertInntektResponseDto.manueltRedigert shouldBe true
140+
klassifisertInntektResponseDto.begrunnelseManueltRedigert shouldBe "Dette er en begrunnelse."
141+
klassifisertInntektResponseDto.sisteAvsluttendeKalenderMåned shouldBe sisteAvsluttendeKalenderMåned
142+
}
143+
}
144+
145+
@Test
146+
fun `Klassifisert-endepunktet returnerer forventet respons når inntekten ikke er manuelt redigert`() {
147+
every { inntektStoreMock.getManueltRedigert(any()) } returns null
148+
149+
coEvery {
150+
behandlingsInntektsGetterMock.getKlassifisertInntekt(
151+
capture(inntektParametreCapture),
152+
any(),
153+
)
154+
} returns createInntekt(false)
155+
156+
withMockAuthServerAndTestApplication(
157+
mockInntektApi(
158+
personOppslag = personOppslagMock,
159+
behandlingsInntektsGetter = behandlingsInntektsGetterMock,
160+
inntektStore = inntektStoreMock,
161+
),
162+
) {
163+
val response =
164+
autentisert(
165+
httpMethod = HttpMethod.Post,
166+
endepunkt = "/v3/inntekt/klassifisert",
167+
body =
168+
jacksonObjectMapper.writeValueAsString(
169+
KlassifisertInntektRequestDto(
170+
fødselsnummer,
171+
regelkontekst,
172+
beregningsDato,
173+
periodeFraOgMed,
174+
periodeTilOgMed,
175+
),
176+
),
177+
)
178+
179+
response.status shouldBe OK
180+
val klassifisertInntektResponseDto =
181+
jacksonObjectMapper.readValue<KlassifisertInntektResponseDto>(response.bodyAsText())
182+
klassifisertInntektResponseDto.inntektsId shouldBe inntektsId
183+
klassifisertInntektResponseDto.inntektsListe.shouldNotBeEmpty()
184+
klassifisertInntektResponseDto.manueltRedigert shouldBe false
185+
klassifisertInntektResponseDto.begrunnelseManueltRedigert shouldBe null
186+
klassifisertInntektResponseDto.sisteAvsluttendeKalenderMåned shouldBe sisteAvsluttendeKalenderMåned
187+
}
188+
}
189+
190+
private fun createInntekt(manueltRedigert: Boolean): Inntekt =
191+
Inntekt(
192+
inntektsId,
193+
listOf(KlassifisertInntektMåned(now(), listOf())),
194+
manueltRedigert,
195+
now(),
196+
)
90197
}

0 commit comments

Comments
 (0)