@@ -172,7 +172,7 @@ class InvoiceCorrectionsIntegrationTest : PureJdbiTest(resetDbBeforeEach = true)
172
172
assertEquals(100_00 , secondInvoice.rows.first().unitPrice)
173
173
assertEquals(2 , secondInvoice.rows.last().amount)
174
174
assertEquals(- 40_00 , secondInvoice.rows.last().unitPrice)
175
- assertEquals(getCorrectionForMonth(secondMonth ).id, secondInvoice.rows.last().correctionId)
175
+ assertEquals(getUnappliedCorrection( ).id, secondInvoice.rows.last().correctionId)
176
176
177
177
insertAndSendInvoice(secondInvoice)
178
178
@@ -184,7 +184,7 @@ class InvoiceCorrectionsIntegrationTest : PureJdbiTest(resetDbBeforeEach = true)
184
184
assertEquals(100_00 , thirdInvoice.rows.first().unitPrice)
185
185
assertEquals(1 , thirdInvoice.rows.last().amount)
186
186
assertEquals(- 40_00 , thirdInvoice.rows.last().unitPrice)
187
- assertEquals(getCorrectionForMonth(thirdMonth ).id, thirdInvoice.rows.last().correctionId)
187
+ assertEquals(getUnappliedCorrection( ).id, thirdInvoice.rows.last().correctionId)
188
188
189
189
insertAndSendInvoice(thirdInvoice)
190
190
}
@@ -213,7 +213,7 @@ class InvoiceCorrectionsIntegrationTest : PureJdbiTest(resetDbBeforeEach = true)
213
213
assertEquals(100_00 , secondInvoice.rows.first().unitPrice)
214
214
assertEquals(1 , secondInvoice.rows.last().amount)
215
215
assertEquals(- 100_00 , secondInvoice.rows.last().unitPrice)
216
- assertEquals(getCorrectionForMonth(secondMonth ).id, secondInvoice.rows.last().correctionId)
216
+ assertEquals(getUnappliedCorrection( ).id, secondInvoice.rows.last().correctionId)
217
217
218
218
insertAndSendInvoice(secondInvoice)
219
219
@@ -225,7 +225,7 @@ class InvoiceCorrectionsIntegrationTest : PureJdbiTest(resetDbBeforeEach = true)
225
225
assertEquals(100_00 , thirdInvoice.rows.first().unitPrice)
226
226
assertEquals(1 , thirdInvoice.rows.last().amount)
227
227
assertEquals(- 50_00 , thirdInvoice.rows.last().unitPrice)
228
- assertEquals(getCorrectionForMonth(thirdMonth ).id, thirdInvoice.rows.last().correctionId)
228
+ assertEquals(getUnappliedCorrection( ).id, thirdInvoice.rows.last().correctionId)
229
229
230
230
insertAndSendInvoice(thirdInvoice)
231
231
}
@@ -274,7 +274,7 @@ class InvoiceCorrectionsIntegrationTest : PureJdbiTest(resetDbBeforeEach = true)
274
274
assertEquals(100_00 , secondInvoice.rows.first().unitPrice)
275
275
assertEquals(1 , secondInvoice.rows.last().amount)
276
276
assertEquals(- 50_00 , secondInvoice.rows.last().unitPrice)
277
- assertEquals(getCorrectionForMonth(secondMonth ).id, secondInvoice.rows.last().correctionId)
277
+ assertEquals(getUnappliedCorrection( ).id, secondInvoice.rows.last().correctionId)
278
278
279
279
insertAndSendInvoice(secondInvoice)
280
280
}
@@ -326,7 +326,7 @@ class InvoiceCorrectionsIntegrationTest : PureJdbiTest(resetDbBeforeEach = true)
326
326
assertEquals(30_00 , secondInvoice.rows.first().unitPrice)
327
327
assertEquals(3 , secondInvoice.rows.last().amount)
328
328
assertEquals(- 10_00 , secondInvoice.rows.last().unitPrice)
329
- val secondCorrection = getCorrectionForMonth(secondMonth )
329
+ val secondCorrection = getUnappliedCorrection( )
330
330
assertEquals(secondCorrection.id, secondInvoice.rows.last().correctionId)
331
331
332
332
insertAndSendInvoice(secondInvoice)
@@ -339,7 +339,7 @@ class InvoiceCorrectionsIntegrationTest : PureJdbiTest(resetDbBeforeEach = true)
339
339
assertEquals(100_00 , thirdInvoice.rows.first().unitPrice)
340
340
assertEquals(2 , thirdInvoice.rows.last().amount)
341
341
assertEquals(- 40_00 , thirdInvoice.rows.last().unitPrice)
342
- assertEquals(getCorrectionForMonth(thirdMonth ).id, thirdInvoice.rows.last().correctionId)
342
+ assertEquals(getUnappliedCorrection( ).id, thirdInvoice.rows.last().correctionId)
343
343
344
344
insertAndSendInvoice(thirdInvoice)
345
345
@@ -351,7 +351,7 @@ class InvoiceCorrectionsIntegrationTest : PureJdbiTest(resetDbBeforeEach = true)
351
351
assertEquals(100_00 , fourthInvoice.rows.first().unitPrice)
352
352
assertEquals(1 , fourthInvoice.rows.last().amount)
353
353
assertEquals(- 40_00 , fourthInvoice.rows.last().unitPrice)
354
- assertEquals(getCorrectionForMonth(fourthMonth ).id, fourthInvoice.rows.last().correctionId)
354
+ assertEquals(getUnappliedCorrection( ).id, fourthInvoice.rows.last().correctionId)
355
355
356
356
insertAndSendInvoice(fourthInvoice)
357
357
}
@@ -363,7 +363,8 @@ class InvoiceCorrectionsIntegrationTest : PureJdbiTest(resetDbBeforeEach = true)
363
363
val invoice = applyCorrections(createTestInvoice(100_00 , month), month)
364
364
insertAndSendInvoice(invoice)
365
365
366
- val correction = getCorrectionForMonth(month)
366
+ val correction =
367
+ db.read { tx -> tx.getInvoiceCorrectionsByIds(setOf (correctionId)).single() }
367
368
assertEquals(correctionId, correction.id)
368
369
assertEquals(1 , correction.amount)
369
370
assertEquals(- 50_00 , correction.unitPrice)
@@ -376,9 +377,9 @@ class InvoiceCorrectionsIntegrationTest : PureJdbiTest(resetDbBeforeEach = true)
376
377
val invoice = applyCorrections(createTestInvoice(100_00 , month), month)
377
378
insertAndSendInvoice(invoice)
378
379
379
- val nextMonthCorrection = getCorrectionForMonth(month.plusMonths( 1 ) )
380
- assertEquals(1 , nextMonthCorrection .amount)
381
- assertEquals(- 100_00 , nextMonthCorrection .unitPrice)
380
+ val unappliedCorrection = getUnappliedCorrection( )
381
+ assertEquals(1 , unappliedCorrection .amount)
382
+ assertEquals(- 100_00 , unappliedCorrection .unitPrice)
382
383
}
383
384
384
385
@Test
@@ -455,7 +456,7 @@ class InvoiceCorrectionsIntegrationTest : PureJdbiTest(resetDbBeforeEach = true)
455
456
it.insert(
456
457
DevInvoiceCorrection (
457
458
headOfFamilyId = adult.id,
458
- targetMonth = month ,
459
+ targetMonth = null ,
459
460
childId = child.id,
460
461
amount = amount,
461
462
unitPrice = unitPrice,
@@ -468,6 +469,5 @@ class InvoiceCorrectionsIntegrationTest : PureJdbiTest(resetDbBeforeEach = true)
468
469
)
469
470
}
470
471
471
- private fun getCorrectionForMonth (month : YearMonth ) =
472
- db.read { it.getInvoiceCorrectionsForMonth(month) }.single()
472
+ private fun getUnappliedCorrection () = db.read { it.getUnappliedInvoiceCorrections() }.single()
473
473
}
0 commit comments