Skip to content

Commit

Permalink
Merge branch 'PAGOPA-1838-issue-get-pdf-receipt' of
Browse files Browse the repository at this point in the history
https://github.com/pagopa/pagopa-receipt-pdf-helpdesk into
PAGOPA-1838-issue-get-pdf-receipt
  • Loading branch information
aacitelli authored and aacitelli committed Jun 17, 2024
2 parents 81f6f08 + c2dcca0 commit 4dd36ba
Showing 1 changed file with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,35 @@ void regeneratePDFSuccess() {
verify(generateReceiptPdfServiceMock).verifyAndUpdateReceipt(any(), any());
}

@Test
@SneakyThrows
void regeneratePDFSameDebtorAndPayerSuccess() {
int numRetry = 0;
Receipt receipt = buildReceiptWithStatus(ReceiptStatusType.INSERTED, numRetry);
receipt.getEventData().setDebtorFiscalCode("same cf debtor and payer");
receipt.getEventData().setPayerFiscalCode("same cf debtor and payer");
receipt.getMdAttach().setUrl(null);

doReturn(bizEvent).when(bizEventCosmosClient).getBizEventDocument(anyString());
doReturn(receipt).when(receiptCosmosClientMock).getReceiptDocument(anyString());
doReturn(new PdfGeneration()).when(generateReceiptPdfServiceMock).generateReceipts(any(), any(), any());
doReturn(true).when(generateReceiptPdfServiceMock).verifyAndUpdateReceipt(any(), any());

HttpRequestMessage<Optional<String>> request = mock(HttpRequestMessage.class);

doAnswer((Answer<HttpResponseMessage.Builder>) invocation -> {
com.microsoft.azure.functions.HttpStatus status = (com.microsoft.azure.functions.HttpStatus) invocation.getArguments()[0];
return new HttpResponseMessageMock.HttpResponseMessageBuilderMock().status(status);
}).when(request).createResponseBuilder(any(com.microsoft.azure.functions.HttpStatus.class));

// test execution
assertEquals(200,assertDoesNotThrow(() -> sut.run(request, "1", documentdb, executionContextMock)).getStatusCode());

verify(receiptCosmosClientMock).getReceiptDocument(anyString());
verify(generateReceiptPdfServiceMock).generateReceipts(any(), any(), any());
verify(generateReceiptPdfServiceMock).verifyAndUpdateReceipt(any(), any());
}

@Test
@SneakyThrows
void regeneratePDFIOException() {
Expand Down Expand Up @@ -228,9 +257,6 @@ void regeneratePDFErrorMissingBizEvent() {
void regeneratePDFReceiptNotFoundSuccess() {
int numRetry = 0;
Receipt receipt = buildReceiptWithStatus(ReceiptStatusType.INSERTED, numRetry);
receipt.getEventData().setDebtorFiscalCode("same cf debtor and payer");
receipt.getEventData().setPayerFiscalCode("same cf debtor and payer");
receipt.getMdAttach().setUrl(null);

doReturn(bizEvent).when(bizEventCosmosClient).getBizEventDocument(anyString());
when(receiptCosmosClientMock.getReceiptDocument(anyString())).thenThrow(new ReceiptNotFoundException("KO")).thenReturn(receipt);
Expand Down

0 comments on commit 4dd36ba

Please sign in to comment.