1
1
package no.nav.dagpenger.inntekt.api.v3
2
2
3
+ import com.fasterxml.jackson.module.kotlin.readValue
4
+ import de.huxhorn.sulky.ulid.ULID
5
+ import io.kotest.matchers.collections.shouldNotBeEmpty
3
6
import io.kotest.matchers.shouldBe
7
+ import io.ktor.client.statement.bodyAsText
4
8
import io.ktor.http.HttpMethod
5
9
import io.ktor.http.HttpStatusCode.Companion.OK
10
+ import io.mockk.coEvery
6
11
import io.mockk.every
7
12
import io.mockk.mockk
8
- import kotlinx.coroutines.runBlocking
9
13
import no.nav.dagpenger.inntekt.BehandlingsInntektsGetter
10
14
import no.nav.dagpenger.inntekt.api.v1.TestApplication.autentisert
11
15
import no.nav.dagpenger.inntekt.api.v1.TestApplication.mockInntektApi
12
16
import no.nav.dagpenger.inntekt.api.v1.TestApplication.withMockAuthServerAndTestApplication
17
+ import no.nav.dagpenger.inntekt.db.InntektStore
13
18
import no.nav.dagpenger.inntekt.db.Inntektparametre
19
+ import no.nav.dagpenger.inntekt.db.ManueltRedigert
14
20
import no.nav.dagpenger.inntekt.db.RegelKontekst
15
21
import no.nav.dagpenger.inntekt.oppslag.Person
16
22
import no.nav.dagpenger.inntekt.oppslag.PersonOppslag
17
23
import no.nav.dagpenger.inntekt.serder.jacksonObjectMapper
24
+ import no.nav.dagpenger.inntekt.v1.Inntekt
25
+ import no.nav.dagpenger.inntekt.v1.KlassifisertInntektMåned
18
26
import java.time.LocalDate
19
27
import java.time.YearMonth
28
+ import java.time.YearMonth.now
20
29
import kotlin.test.Test
21
30
22
31
class KlassifisertInntektRouteV3Test {
23
- val fødselsnummer = " 12345678901"
24
- val aktørId = " 12345"
32
+ private val fødselsnummer = " 12345678901"
33
+ private val aktørId = " 12345"
25
34
private val personOppslagMock: PersonOppslag = mockk()
26
35
private val behandlingsInntektsGetterMock: BehandlingsInntektsGetter = mockk()
27
36
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()
28
44
29
45
init {
30
- every {
31
- runBlocking { personOppslagMock.hentPerson(any()) }
46
+ coEvery {
47
+ personOppslagMock.hentPerson(any())
32
48
} returns
33
49
Person (
34
50
fødselsnummer,
@@ -37,28 +53,24 @@ class KlassifisertInntektRouteV3Test {
37
53
null ,
38
54
" Navnesen" ,
39
55
)
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 )
49
65
}
50
66
51
67
@Test
52
68
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
-
58
69
withMockAuthServerAndTestApplication(
59
70
mockInntektApi(
60
71
personOppslag = personOppslagMock,
61
72
behandlingsInntektsGetter = behandlingsInntektsGetterMock,
73
+ inntektStore = inntektStoreMock,
62
74
),
63
75
) {
64
76
val response =
@@ -67,7 +79,7 @@ class KlassifisertInntektRouteV3Test {
67
79
endepunkt = " /v3/inntekt/klassifisert" ,
68
80
body =
69
81
jacksonObjectMapper.writeValueAsString(
70
- InntektRequestDto (
82
+ KlassifisertInntektRequestDto (
71
83
fødselsnummer,
72
84
regelkontekst,
73
85
beregningsDato,
@@ -87,4 +99,99 @@ class KlassifisertInntektRouteV3Test {
87
99
inntektparametre.opptjeningsperiode.sisteAvsluttendeKalenderMåned shouldBe periodeTilOgMed
88
100
}
89
101
}
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
+ )
90
197
}
0 commit comments