Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PRDP-214] Change RefNumber's value & type mapping #88

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class BuildTemplateServiceImpl implements BuildTemplateService {

private static final Map<String, String> brandLogoMap;
private static final Map<String, Object> pspMap;
public static final String MODEL_TYPE_IUV = "1";
public static final String MODEL_TYPE_NOTICE = "2";

static {
try {
Expand Down Expand Up @@ -241,19 +243,24 @@ private String getUserTaxCode(BizEvent event) throws TemplateDataMappingExceptio

private String getRefNumberType(BizEvent event) throws TemplateDataMappingException {
if (event.getDebtorPosition() != null && event.getDebtorPosition().getModelType() != null) {
if (event.getDebtorPosition().getModelType().equals("1")) {
return REF_TYPE_NOTICE;
}
if (event.getDebtorPosition().getModelType().equals("2")) {
if (event.getDebtorPosition().getModelType().equals(MODEL_TYPE_IUV)) {
return REF_TYPE_IUV;
}
if (event.getDebtorPosition().getModelType().equals(MODEL_TYPE_NOTICE)) {
return REF_TYPE_NOTICE;
}
}
throw new TemplateDataMappingException(formatErrorMessage(TemplateDataField.CART_ITEM_REF_NUMBER_TYPE), ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode());
}

private String getRefNumberValue(BizEvent event) throws TemplateDataMappingException {
if (event.getDebtorPosition() != null && event.getDebtorPosition().getIuv() != null) {
return event.getDebtorPosition().getIuv();
if (event.getDebtorPosition() != null && event.getDebtorPosition().getModelType() != null) {
if (event.getDebtorPosition().getModelType().equals(MODEL_TYPE_IUV) && event.getDebtorPosition().getIuv() != null) {
return event.getDebtorPosition().getIuv();
}
if (event.getDebtorPosition().getModelType().equals(MODEL_TYPE_NOTICE) && event.getDebtorPosition().getNoticeNumber() != null) {
return event.getDebtorPosition().getNoticeNumber();
}
}
throw new TemplateDataMappingException(formatErrorMessage(TemplateDataField.CART_ITEM_REF_NUMBER_VALUE), ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ class BuildTemplateServiceImplTest {
public static final String PSP_PROVINCE = "province";
public static final String BRAND_ASSET_URL = "/asset";
private static final String IUV = "02119891614290410";
private static final String NOTICE_NUMBER = "valid notice number";
private static final String BIZ_EVENT_ID = "biz-event-id";
private static final String MODEL_TYPE_NOTICE_CODE = "1";
private static final String MODEL_TYPE_IUV_CODE = "2";
private static final String MODEL_TYPE_IUV_CODE = "1";
private static final String MODEL_TYPE_NOTICE_CODE = "2";
private static final String MODEL_TYPE_NOTICE_TEXT = "codiceAvviso";
private static final String MODEL_TYPE_IUV_TEXT = "IUV";
private static final String DATE_TIME_TIMESTAMP_FORMATTED = "14 novembre 2023, 19:31:55";
Expand Down Expand Up @@ -268,7 +269,7 @@ void mapTemplateAllFieldsSuccessPartialTemplateAndNotPagoPaChannel() throws Exce
BizEvent event = BizEvent.builder()
.id(BIZ_EVENT_ID)
.debtorPosition(DebtorPosition.builder()
.iuv(IUV)
.noticeNumber(NOTICE_NUMBER)
.modelType(MODEL_TYPE_NOTICE_CODE)
.build())
.creditor(Creditor.builder()
Expand Down Expand Up @@ -350,7 +351,7 @@ void mapTemplateAllFieldsSuccessPartialTemplateAndNotPagoPaChannel() throws Exce
assertEquals(COMPANY_NAME, cart.getItems().get(0).getPayee().getName());
assertEquals(ID_PA, cart.getItems().get(0).getPayee().getTaxCode());
assertEquals(MODEL_TYPE_NOTICE_TEXT, cart.getItems().get(0).getRefNumber().getType());
assertEquals(IUV, cart.getItems().get(0).getRefNumber().getValue());
assertEquals(NOTICE_NUMBER, cart.getItems().get(0).getRefNumber().getValue());
}

@Test
Expand Down Expand Up @@ -1116,7 +1117,7 @@ void mapTemplateNoCartItemRefNumberTypeError() {
}

@Test
void mapTemplateNoCartItemRefNumberValueError() {
void mapTemplateNoCartItemRefNumberValueIUVError() {
BizEvent event = BizEvent.builder()
.id(BIZ_EVENT_ID)
.paymentInfo(PaymentInfo.builder()
Expand All @@ -1142,6 +1143,34 @@ void mapTemplateNoCartItemRefNumberValueError() {
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.CART_ITEM_REF_NUMBER_VALUE), e.getMessage());
}

@Test
void mapTemplateWrongModelTypeError() {
BizEvent event = BizEvent.builder()
.id(BIZ_EVENT_ID)
.paymentInfo(PaymentInfo.builder()
.IUR(IUR)
.paymentDateTime(DATE_TIME_TIMESTAMP_MILLISECONDS)
.amount(AMOUNT_WITHOUT_CENTS)
.build())
.psp(Psp.builder()
.idPsp(ID_PSP)
.psp(PSP_NAME)
.build())
.payer(Payer.builder()
.fullName(PAYER_FULL_NAME)
.entityUniqueIdentifierValue(PAYER_VALID_CF)
.build())
.debtorPosition(DebtorPosition.builder()
.iuv(IUV)
.modelType(MODEL_TYPE_NOTICE_CODE)
.build())
.build();
TemplateDataMappingException e = assertThrows(TemplateDataMappingException.class, () -> buildTemplateService.buildTemplate(event, COMPLETE_TEMPLATE, Receipt.builder().build()));

assertEquals(ReasonErrorCode.ERROR_TEMPLATE_PDF.getCode(), e.getStatusCode());
assertEquals(String.format(TemplateDataField.ERROR_MAPPING_MESSAGE, TemplateDataField.CART_ITEM_REF_NUMBER_VALUE), e.getMessage());
}

@Test
void mapTemplateNoCartItemDebtorTaxCodeValueError() {
BizEvent event = BizEvent.builder()
Expand Down
Loading