Skip to content

Commit

Permalink
Merge pull request #112 from pagopa/fix-relaxed-debtor-checks
Browse files Browse the repository at this point in the history
Fix relaxed debtor checks
  • Loading branch information
pasqualespica authored Dec 21, 2023
2 parents 15ddc2b + 21e8f0c commit f78feff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ public boolean verifyAndUpdateReceipt(Receipt receipt, PdfGeneration pdfGenerati
result = false;
}

if (debtorMetadata.getStatusCode() == ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode()
if ((debtorMetadata != null && debtorMetadata.getStatusCode() == ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode())
|| payerMetadata.getStatusCode() == ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode()) {
String errMsg = String.format("Receipt generation fail for debtor (status: %s) and/or payer (status: %s)",
debtorMetadata.getStatusCode(), payerMetadata.getStatusCode());
debtorMetadata != null ? debtorMetadata.getStatusCode() : "N/A", payerMetadata.getStatusCode());
throw new ReceiptGenerationNotToRetryException(errMsg);
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

Expand Down Expand Up @@ -2008,7 +2010,8 @@ void mapTemplateNoCartItemDebtorTaxCodeValueError() {
.iuv(IUV)
.build())
.build();
TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER,
Receipt.builder().eventData(EventData.builder().debtorFiscalCode("DEBTOR_FC").build()).build()));

assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.CART_ITEM_DEBTOR_TAX_CODE), e.getMessage());
Expand Down Expand Up @@ -2039,7 +2042,8 @@ void mapTemplateNoCartItemPayeeTaxCodeValueError() {
.entityUniqueIdentifierValue(DEBTOR_VALID_CF)
.build())
.build();
TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().eventData(
EventData.builder().debtorFiscalCode("DEBTOR_FC").build()).build()));

assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.CART_ITEM_PAYEE_TAX_CODE), e.getMessage());
Expand Down Expand Up @@ -2122,7 +2126,10 @@ void mapTemplateNoCartItemSubjectError() {
.build()
)
.build();
TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().build()));
TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () ->
buildTemplateService.buildTemplate(event, GENERATED_BY_PAYER, Receipt.builder().eventData(
EventData.builder().cart(Collections.singletonList(CartItem.builder().build()))
.debtorFiscalCode("DEBTOR_FC").build()).build()));

assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.CART_ITEM_SUBJECT), e.getMessage());
Expand Down

0 comments on commit f78feff

Please sign in to comment.