1
1
package no.nav.dagpenger.inntekt.db
2
2
3
3
import io.kotest.assertions.assertSoftly
4
+ import io.kotest.core.spec.style.StringSpec
4
5
import io.kotest.matchers.shouldBe
5
6
import io.kotest.matchers.shouldNotBe
7
+ import io.kotest.property.Arb
8
+ import io.kotest.property.arbitrary.arb
9
+ import io.kotest.property.arbitrary.localDate
10
+ import io.kotest.property.arbitrary.next
11
+ import io.kotest.property.arbitrary.string
12
+ import io.kotest.property.checkAll
6
13
import java.time.LocalDate
7
14
import kotlin.test.assertEquals
8
15
import kotlin.test.assertFalse
@@ -93,11 +100,16 @@ internal class PostgresInntektStoreTest {
93
100
val aktørId2 = " 5678"
94
101
95
102
withMigratedDb {
103
+
96
104
with (PostgresInntektStore (DataSource .instance)) {
97
105
106
+ val aktør1 =
107
+ Inntektparametre (aktørId = aktørId1, vedtakId = " 1234" , beregningsdato = LocalDate .now())
108
+ val aktør2 =
109
+ Inntektparametre (aktørId = aktørId2, vedtakId = " 1234" , beregningsdato = LocalDate .now())
98
110
storeInntekt(
99
111
StoreInntektCommand (
100
- inntektparametre = Inntektparametre (aktørId = aktørId1, vedtakId = " 1234 " , beregningsdato = LocalDate .now()) ,
112
+ inntektparametre = aktør1 ,
101
113
inntekt = InntektkomponentResponse (
102
114
emptyList(),
103
115
Aktoer (AktoerType .AKTOER_ID , aktørId1)
@@ -107,7 +119,7 @@ internal class PostgresInntektStoreTest {
107
119
108
120
storeInntekt(
109
121
StoreInntektCommand (
110
- inntektparametre = Inntektparametre (aktørId = aktørId2, vedtakId = " 1234 " , beregningsdato = LocalDate .now()) ,
122
+ inntektparametre = aktør2 ,
111
123
inntekt = InntektkomponentResponse (
112
124
emptyList(),
113
125
Aktoer (AktoerType .AKTOER_ID , aktørId2)
@@ -116,9 +128,9 @@ internal class PostgresInntektStoreTest {
116
128
)
117
129
118
130
assertSoftly {
119
- getInntektId(Inntektparametre (aktørId = aktørId1, vedtakId = " 1234 " , beregningsdato = LocalDate .now()) ) shouldNotBe null
120
- getInntektId(Inntektparametre (aktørId = aktørId2, vedtakId = " 1234 " , beregningsdato = LocalDate .now()) ) shouldNotBe null
121
- getInntektId(Inntektparametre (aktørId = aktørId2, vedtakId = " 1234 " , beregningsdato = LocalDate .now())) shouldNotBe getInntektId(Inntektparametre (aktørId = aktørId1, vedtakId = " 1234 " , beregningsdato = LocalDate .now()) )
131
+ getInntektId(aktør1 ) shouldNotBe null
132
+ getInntektId(aktør2 ) shouldNotBe null
133
+ getInntektId(aktør2) shouldNotBe getInntektId(aktør1 )
122
134
getInntektId(Inntektparametre (aktørId = aktørId2, vedtakId = " 464664" , beregningsdato = LocalDate .now())) shouldBe null
123
135
getInntektId(Inntektparametre (aktørId = " 3535535335" , vedtakId = " 1234" , beregningsdato = LocalDate .now())) shouldBe null
124
136
}
@@ -277,3 +289,62 @@ internal class PostgresInntektStoreTest {
277
289
}
278
290
}
279
291
}
292
+
293
+ internal class InntektsStorePropertyTest : StringSpec () {
294
+
295
+ init {
296
+ withMigratedDb {
297
+ val store = PostgresInntektStore (DataSource .instance)
298
+
299
+ " Alle inntekter skal kunne hentes når de lagres" {
300
+ checkAll(storeInntekCommandGenerator) { command: StoreInntektCommand ->
301
+ val stored = store.storeInntekt(command)
302
+ store.getInntektId(command.inntektparametre) shouldBe stored.inntektId
303
+ }
304
+ }
305
+
306
+ " Alle inntekter skal kunne hentes når de lagres med samme vedtak id men forskjellig person uten fødselsnummer" {
307
+ checkAll(storeInntektCommandGeneratorWithSameVedtakidAndBeregningsDato) { command: StoreInntektCommand ->
308
+ val stored = store.storeInntekt(command)
309
+ store.getInntektId(command.inntektparametre) shouldBe stored.inntektId
310
+ }
311
+ }
312
+ }
313
+ }
314
+
315
+ private val storeInntekCommandGenerator = arb {
316
+ val stringArb = Arb .string(10 , 11 )
317
+ generateSequence {
318
+ StoreInntektCommand (
319
+ inntektparametre = Inntektparametre (
320
+ aktørId = stringArb.next(it),
321
+ vedtakId = stringArb.next(it),
322
+ fødselnummer = stringArb.next(it),
323
+ beregningsdato = Arb .localDate(minYear = 2010 , maxYear = LocalDate .now().year).next(it)
324
+ ),
325
+ inntekt = InntektkomponentResponse (
326
+ arbeidsInntektMaaned = emptyList(),
327
+ ident = Aktoer (AktoerType .AKTOER_ID , " 1234" )
328
+ )
329
+ )
330
+ }
331
+ }
332
+
333
+ private val storeInntektCommandGeneratorWithSameVedtakidAndBeregningsDato = arb {
334
+ val stringArb = Arb .string(10 , 11 )
335
+ generateSequence {
336
+ StoreInntektCommand (
337
+ inntektparametre = Inntektparametre (
338
+ aktørId = stringArb.next(it),
339
+ vedtakId = " 12345" ,
340
+ fødselnummer = null ,
341
+ beregningsdato = LocalDate .now()
342
+ ),
343
+ inntekt = InntektkomponentResponse (
344
+ arbeidsInntektMaaned = emptyList(),
345
+ ident = Aktoer (AktoerType .AKTOER_ID , " 1234" )
346
+ )
347
+ )
348
+ }
349
+ }
350
+ }
0 commit comments