diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/BizEventToReceiptServiceImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/BizEventToReceiptServiceImpl.java index 7e82685..a8337a2 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/BizEventToReceiptServiceImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/BizEventToReceiptServiceImpl.java @@ -259,7 +259,8 @@ public Receipt createCartReceipt(List bizEventList) { } public static BigDecimal getAmount(BizEvent bizEvent) { - if (bizEvent.getTransactionDetails() != null && bizEvent.getTransactionDetails().getTransaction() != null) { + if (bizEvent.getTransactionDetails() != null && bizEvent.getTransactionDetails().getTransaction() != null + && bizEvent.getTransactionDetails().getTransaction().getGrandTotal() != 0) { return new BigDecimal(bizEvent.getTransactionDetails().getTransaction().getGrandTotal()); } if (bizEvent.getPaymentInfo() != null && bizEvent.getPaymentInfo().getAmount() != null) { diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/BizEventToReceiptUtils.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/BizEventToReceiptUtils.java index bc6cd28..968ad4d 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/BizEventToReceiptUtils.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/BizEventToReceiptUtils.java @@ -281,7 +281,8 @@ public static void tokenizeReceipt(BizEventToReceiptService service, List queueResponse = mock(Response.class); + when(queueResponse.getStatusCode()).thenReturn(HttpStatus.CREATED.value()); + when(queueClientMock.sendMessageToQueue(anyString())).thenReturn(queueResponse); + + when(requestMock.getQueryParameters()).thenReturn(Collections.singletonMap("isCart","true")); + + FeedResponse feedResponseMock = mock(FeedResponse.class); + List receiptList = Collections.singletonList(generateValidBizEvent("1")); + when(feedResponseMock.getResults()).thenReturn(receiptList); + doReturn(Collections.singletonList(feedResponseMock)).when(bizEventCosmosClientMock) + .getAllBizEventDocument(Mockito.eq("a valid id"), any(), any()); + + when(receiptCosmosServiceMock.getReceipt(EVENT_ID)).thenThrow(ReceiptNotFoundException.class); + + doAnswer((Answer) invocation -> { + HttpStatus status = (HttpStatus) invocation.getArguments()[0]; + return new HttpResponseMessageMock.HttpResponseMessageBuilderMock().status(status); + }).when(requestMock).createResponseBuilder(any(HttpStatus.class)); + + // test execution + HttpResponseMessage response = assertDoesNotThrow(() -> sut.run(requestMock, EVENT_ID, documentdb, contextMock)); + + // test assertion + assertNotNull(response); + assertEquals(HttpStatus.OK, response.getStatus()); + assertNotNull(response.getBody()); + + verify(documentdb).setValue(receiptCaptor.capture()); + Receipt captured = receiptCaptor.getValue(); + assertEquals(ReceiptStatusType.INSERTED, captured.getStatus()); + assertEquals(EVENT_ID, captured.getEventId()); + assertEquals(TOKENIZED_PAYER_FISCAL_CODE, captured.getEventData().getPayerFiscalCode()); + assertEquals(TOKENIZED_DEBTOR_FISCAL_CODE, captured.getEventData().getDebtorFiscalCode()); + assertNotNull(captured.getEventData().getCart()); + assertEquals(1, captured.getEventData().getCart().size()); + } + @Test @SneakyThrows void requestOnValidBizEventTransactionDetailsShouldCreateRequest() {