Skip to content

Commit

Permalink
[PRDP-178] Improved unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
svariant committed Oct 24, 2023
1 parent 5b2e2a5 commit 6a95ffd
Showing 1 changed file with 95 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class BuildTemplateServiceImplTest {
private static final String DATE_TIME_TIMESTAMP_FORMATTED = "12 aprile 2023, 16:32:27";
private static final String PAGO_PA_CHANNEL_IO = "IO";
private static final String PAGO_PA_CHANNEL_IO_PAY = "IO-PAY";
private static final String NOT_PAGO_PA_CHANNEL = "NOT_PAGO_PA_CHANNEL";
private BuildTemplateServiceImpl buildTemplateService;

@BeforeEach
Expand All @@ -72,7 +73,7 @@ void setUp() throws Exception {
}

@Test
void mapTemplateAllFieldsSuccessCompleteTemplate() throws Exception {
void mapTemplateAllFieldsSuccessCompleteTemplateAndIOChannel() throws Exception {
BizEvent event = BizEvent.builder()
.id(BIZ_EVENT_ID)
.debtorPosition(DebtorPosition.builder()
Expand Down Expand Up @@ -162,12 +163,12 @@ void mapTemplateAllFieldsSuccessCompleteTemplate() throws Exception {
}

@Test
void mapTemplateAllFieldsSuccessPartialTemplate() throws Exception {
void mapTemplateAllFieldsSuccessCompleteTemplateAndIOPAYChannel() throws Exception {
BizEvent event = BizEvent.builder()
.id(BIZ_EVENT_ID)
.debtorPosition(DebtorPosition.builder()
.iuv(IUV)
.modelType(MODEL_TYPE_NOTICE_CODE)
.modelType(MODEL_TYPE_IUV_CODE)
.build())
.creditor(Creditor.builder()
.companyName(COMPANY_NAME)
Expand Down Expand Up @@ -210,6 +211,96 @@ void mapTemplateAllFieldsSuccessPartialTemplate() throws Exception {
.build())
.eventStatus(BizEventStatusType.DONE)
.build();
ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE);

assertNotNull(receiptPdfTemplate);

it.gov.pagopa.receipt.pdf.generator.model.template.Transaction transaction = receiptPdfTemplate.getTransaction();
assertEquals(String.valueOf(ID_TRANSACTION), transaction.getId());
assertEquals(DATE_TIME_TIMESTAMP_FORMATTED, transaction.getTimestamp());
assertEquals(FORMATTED_GRAND_TOTAL, transaction.getAmount());
assertEquals(PSP_LOGO, transaction.getPsp().getLogo());
assertEquals(FORMATTED_FEE, transaction.getPsp().getFee().getAmount());
assertEquals(PSP_NAME, transaction.getPsp().getName());
assertEquals(PSP_CITY, transaction.getPsp().getCity());
assertEquals(PSP_COMPANY, transaction.getPsp().getCompanyName());
assertEquals(PSP_POSTAL_CODE, transaction.getPsp().getPostalCode());
assertEquals(PSP_ADDRESS, transaction.getPsp().getAddress());
assertEquals(PSP_BUILDING_NUMBER, transaction.getPsp().getBuildingNumber());
assertEquals(PSP_PROVINCE, transaction.getPsp().getProvince());
assertEquals(RRN, transaction.getRrn());
assertEquals(BRAND, transaction.getPaymentMethod().getName());
assertEquals(BRAND_ASSET_URL, transaction.getPaymentMethod().getLogo());
assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder());
assertEquals(AUTH_CODE, transaction.getAuthCode());
assertEquals(COMPLETE_TEMPLATE, transaction.isRequestedByDebtor());
assertTrue(transaction.isProcessedByPagoPA());

it.gov.pagopa.receipt.pdf.generator.model.template.UserData userData = receiptPdfTemplate.getUser().getData();
assertEquals(PAYER_VALID_CF, userData.getTaxCode());
assertEquals(PAYER_FULL_NAME, userData.getFullName());

it.gov.pagopa.receipt.pdf.generator.model.template.Cart cart = receiptPdfTemplate.getCart();
assertEquals(FORMATTED_AMOUNT, cart.getAmountPartial());
assertEquals(FORMATTED_AMOUNT, cart.getItems().get(0).getAmount());
assertEquals(DEBTOR_FULL_NAME, cart.getItems().get(0).getDebtor().getFullName());
assertEquals(DEBTOR_VALID_CF, cart.getItems().get(0).getDebtor().getTaxCode());
assertEquals(REMITTANCE_INFORMATION, cart.getItems().get(0).getSubject());
assertEquals(OFFICE_NAME, cart.getItems().get(0).getPayee().getName());
assertEquals(COMPANY_NAME, cart.getItems().get(0).getPayee().getTaxCode());
assertEquals(MODEL_TYPE_IUV_TEXT, cart.getItems().get(0).getRefNumber().getType());
assertEquals(IUV, cart.getItems().get(0).getRefNumber().getValue());
}

@Test
void mapTemplateAllFieldsSuccessPartialTemplateAndNotPagoPaChannel() throws Exception {
BizEvent event = BizEvent.builder()
.id(BIZ_EVENT_ID)
.debtorPosition(DebtorPosition.builder()
.iuv(IUV)
.modelType(MODEL_TYPE_NOTICE_CODE)
.build())
.creditor(Creditor.builder()
.companyName(COMPANY_NAME)
.officeName(OFFICE_NAME)
.build())
.psp(Psp.builder()
.idPsp(ID_PSP)
.psp(PSP_NAME)
.build())
.debtor(Debtor.builder()
.fullName(DEBTOR_FULL_NAME)
.entityUniqueIdentifierValue(DEBTOR_VALID_CF)
.build())
.payer(Payer.builder().fullName(PAYER_FULL_NAME).entityUniqueIdentifierValue(PAYER_VALID_CF).build())
.paymentInfo(PaymentInfo.builder()
.paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
.paymentToken(PAYMENT_TOKEN)
.amount(AMOUNT_WITHOUT_CENTS)
.fee(FEE_WITH_SINGLE_DIGIT_CENTS)
.remittanceInformation(REMITTANCE_INFORMATION)
.IUR(IUR)
.build())
.transactionDetails(TransactionDetails.builder()
.wallet(WalletItem.builder()
.info(Info.builder().brand(BRAND).holder(HOLDER_FULL_NAME).build())
.onboardingChannel(NOT_PAGO_PA_CHANNEL)
.build())
.transaction(Transaction.builder()
.idTransaction(ID_TRANSACTION)
.grandTotal(GRAND_TOTAL_LONG)
.amount(AMOUNT_LONG)
.fee(FEE_LONG)
.rrn(RRN)
.authorizationCode(AUTH_CODE)
.creationDate(DATE_TIME_TIMESTAMP_ZONED)
.psp(TransactionPsp.builder()
.businessName(PSP_NAME)
.build())
.build())
.build())
.eventStatus(BizEventStatusType.DONE)
.build();
ReceiptPDFTemplate receiptPdfTemplate = buildTemplateService.buildTemplate(event, PARTIAL_TEMPLATE);

assertNotNull(receiptPdfTemplate);
Expand All @@ -233,7 +324,7 @@ void mapTemplateAllFieldsSuccessPartialTemplate() throws Exception {
assertEquals(HOLDER_FULL_NAME, transaction.getPaymentMethod().getAccountHolder());
assertEquals(AUTH_CODE, transaction.getAuthCode());
assertEquals(PARTIAL_TEMPLATE, transaction.isRequestedByDebtor());
assertTrue(transaction.isProcessedByPagoPA());
assertFalse(transaction.isProcessedByPagoPA());

it.gov.pagopa.receipt.pdf.generator.model.template.User user = receiptPdfTemplate.getUser();
assertNull(user);
Expand Down

0 comments on commit 6a95ffd

Please sign in to comment.