Skip to content

Commit 31256da

Browse files
author
dalilaacqua
committed
Fix test
1 parent e984d04 commit 31256da

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

src/test/java/it/gov/pagopa/idpay/transactions/service/PointOfSaleTransactionServiceImplTest.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ void updateInvoiceTransaction_evaluatingBatch_suspendOkButRefetchEmpty_throws()
10881088
}
10891089

10901090
@Test
1091-
void updateInvoiceTransaction_evaluatingBatch_newBatchSameAsOld_doesNotMoveCounters() {
1091+
void updateInvoiceTransaction_evaluatingBatch_currentMonthEvaluating_switchesToNextMonth_andMovesCounters() {
10921092
FilePart fp = filePartBackedBySrc("invoice.pdf", true);
10931093

10941094
RewardTransaction trx = baseInvoicedTrx();
@@ -1111,10 +1111,15 @@ void updateInvoiceTransaction_evaluatingBatch_newBatchSameAsOld_doesNotMoveCount
11111111
oldBatch.setStatus(RewardBatchStatus.EVALUATING);
11121112
oldBatch.setMonth("2024-01");
11131113

1114-
RewardBatch sameBatch = new RewardBatch();
1115-
sameBatch.setId("SAME");
1116-
sameBatch.setStatus(RewardBatchStatus.EVALUATING);
1117-
sameBatch.setMonth(YearMonth.now().toString());
1114+
RewardBatch currentMonthBatch = new RewardBatch();
1115+
currentMonthBatch.setId("SAME");
1116+
currentMonthBatch.setStatus(RewardBatchStatus.EVALUATING);
1117+
currentMonthBatch.setMonth(YearMonth.now().toString());
1118+
1119+
RewardBatch nextMonthBatch = new RewardBatch();
1120+
nextMonthBatch.setId("NEXT");
1121+
nextMonthBatch.setStatus(RewardBatchStatus.CREATED);
1122+
nextMonthBatch.setMonth(YearMonth.now().plusMonths(1).toString());
11181123

11191124
@SuppressWarnings("unchecked")
11201125
Response<BlockBlobItem> uploadResponse = (Response<BlockBlobItem>) mock(Response.class);
@@ -1134,17 +1139,38 @@ void updateInvoiceTransaction_evaluatingBatch_newBatchSameAsOld_doesNotMoveCount
11341139
when(rewardBatchService.suspendTransactions(eq("SAME"), eq(INITIATIVE_ID), any(TransactionsRequest.class)))
11351140
.thenReturn(Mono.just(oldBatch));
11361141

1137-
when(rewardBatchService.findOrCreateBatch(eq(MERCHANT_ID), eq(PosType.PHYSICAL), eq(YearMonth.now().toString()), eq("Biz")))
1138-
.thenReturn(Mono.just(sameBatch));
1142+
// 1) lookup mese corrente -> EVALUATING -> triggera switch
1143+
when(rewardBatchService.findOrCreateBatch(
1144+
eq(MERCHANT_ID),
1145+
eq(PosType.PHYSICAL),
1146+
eq(YearMonth.now().toString()),
1147+
eq("Biz")
1148+
)).thenReturn(Mono.just(currentMonthBatch));
1149+
1150+
// 2) lookup mese successivo -> batch destinazione
1151+
when(rewardBatchService.findOrCreateBatch(
1152+
eq(MERCHANT_ID),
1153+
eq(PosType.PHYSICAL),
1154+
eq(YearMonth.now().plusMonths(1).toString()),
1155+
eq("Biz")
1156+
)).thenReturn(Mono.just(nextMonthBatch));
1157+
1158+
// move counters (oldBatch è EVALUATING -> va su moveSuspendToNewBatch)
1159+
when(rewardBatchService.moveSuspendToNewBatch(eq("SAME"), eq("NEXT"), eq(123L)))
1160+
.thenReturn(Mono.empty());
11391161

11401162
StepVerifier.create(service.updateInvoiceTransaction(TRX_ID, MERCHANT_ID, POS_ID, fp, DOC_NUMBER))
11411163
.verifyComplete();
11421164

1143-
verify(rewardBatchService, never()).moveSuspendToNewBatch(anyString(), anyString(), anyLong());
1165+
// Verifica chiamate contatori: deve muovere suspended da SAME a NEXT
1166+
verify(rewardBatchService, times(1)).moveSuspendToNewBatch("SAME", "NEXT", 123L);
1167+
1168+
// E non deve usare il ramo CREATED (decrement/increment)
11441169
verify(rewardBatchService, never()).decrementTotalAmountCents(anyString(), anyLong());
11451170
verify(rewardBatchService, never()).incrementTotalAmountCents(anyString(), anyLong());
11461171
}
11471172

1173+
11481174
@Test
11491175
void updateInvoiceTransaction_createdBatch_newBatchDifferent_movesTotalsWithDecrementAndIncrement() {
11501176
FilePart fp = filePartBackedBySrc("invoice.pdf", true);

0 commit comments

Comments
 (0)