From a253eff8ce7972d77030e91d104a7ef1a46c1140 Mon Sep 17 00:00:00 2001 From: Giampiero Ferrara Date: Tue, 19 Nov 2024 16:34:45 +0100 Subject: [PATCH] [SELC-5807] feat: Added fields for PSP template --- .../selfcare/onboarding/utils/PdfMapper.java | 12 +-- .../utils/InstitutionUtilsTest.java | 82 +++++++++++++++++++ .../onboarding/util/InstitutionUtils.java | 3 +- .../onboarding/util/InstitutionUtilsTest.java | 26 +++++- 4 files changed, 115 insertions(+), 8 deletions(-) create mode 100644 apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/InstitutionUtilsTest.java diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/PdfMapper.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/PdfMapper.java index 635e04d89..48f14d6f4 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/PdfMapper.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/utils/PdfMapper.java @@ -1,20 +1,18 @@ package it.pagopa.selfcare.onboarding.utils; +import static it.pagopa.selfcare.onboarding.common.ProductId.PROD_IO; +import static it.pagopa.selfcare.onboarding.utils.GenericError.MANAGER_EMAIL_NOT_FOUND; + import it.pagopa.selfcare.onboarding.common.InstitutionType; import it.pagopa.selfcare.onboarding.common.Origin; import it.pagopa.selfcare.onboarding.common.PricingPlan; import it.pagopa.selfcare.onboarding.entity.*; import it.pagopa.selfcare.onboarding.exception.GenericOnboardingException; +import java.util.*; import org.apache.commons.lang3.StringUtils; import org.openapi.quarkus.user_registry_json.model.CertifiableFieldResourceOfstring; import org.openapi.quarkus.user_registry_json.model.UserResource; -import java.util.*; - -import static it.pagopa.selfcare.onboarding.common.ProductId.PROD_IO; -import static it.pagopa.selfcare.onboarding.utils.GenericError.MANAGER_EMAIL_NOT_FOUND; - - public class PdfMapper { private static final String UNDERSCORE = "_______________"; @@ -105,6 +103,8 @@ public static void setupPSPData(Map map, UserResource validManag map.put("legalRegisterNumber", institution.getPaymentServiceProvider().getLegalRegisterNumber()); map.put("legalRegisterName", institution.getPaymentServiceProvider().getLegalRegisterName()); map.put("vatNumberGroup", institution.getPaymentServiceProvider().isVatNumberGroup() ? "partita iva di gruppo" : ""); + map.put("vatNumberGroupCheckbox1", institution.getPaymentServiceProvider().isVatNumberGroup()? "X" : ""); + map.put("vatNumberGroupCheckbox2", !institution.getPaymentServiceProvider().isVatNumberGroup()? "X" : ""); map.put("institutionRegister", institution.getPaymentServiceProvider().getBusinessRegisterNumber()); map.put("institutionAbi", institution.getPaymentServiceProvider().getAbiCode()); } diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/InstitutionUtilsTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/InstitutionUtilsTest.java new file mode 100644 index 000000000..ec2a63e3a --- /dev/null +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/utils/InstitutionUtilsTest.java @@ -0,0 +1,82 @@ +package it.pagopa.selfcare.onboarding.utils; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import it.pagopa.selfcare.onboarding.common.InstitutionType; +import it.pagopa.selfcare.onboarding.common.PartyRole; +import it.pagopa.selfcare.onboarding.entity.Institution; +import it.pagopa.selfcare.onboarding.entity.Onboarding; +import it.pagopa.selfcare.onboarding.entity.User; +import java.util.List; +import java.util.UUID; +import org.junit.jupiter.api.Test; + +public class InstitutionUtilsTest { + + @Test + void getCurrentInstitutionTypeTest() { + // given + Onboarding onboarding = createDummyOnboarding(); + + // when + String result = InstitutionUtils.getCurrentInstitutionType(onboarding); + + // then + assertEquals("PSP", result); + } + + @Test + void getCurrentInstitutionTypeTest_shouldReturnDefault_whenInstitutionTypeIsNull() { + // given + Onboarding onboarding = createDummyOnboarding(); + onboarding.getInstitution().setInstitutionType(null); + + // when + String result = InstitutionUtils.getCurrentInstitutionType(onboarding); + + // then + assertEquals("default", result); + } + + @Test + void getCurrentInstitutionTypeTest_shouldReturnDefault_whenInstitutionIsNotNull() { + // given + Onboarding onboarding = createDummyOnboarding(); + onboarding.setInstitution(new Institution()); + // when + String result = InstitutionUtils.getCurrentInstitutionType(onboarding); + + // then + assertEquals("default", result); + } + + @Test + void getCurrentInstitutionTypeTest_shouldReturnDefault_whenInstitutionIsNull() { + // given + Onboarding onboarding = createDummyOnboarding(); + onboarding.setInstitution(null); + // when + String result = InstitutionUtils.getCurrentInstitutionType(onboarding); + + // then + assertEquals("default", result); + } + + private Onboarding createDummyOnboarding() { + Onboarding onboarding = new Onboarding(); + onboarding.setId(UUID.randomUUID().toString()); + onboarding.setProductId("prod-pagopa"); + + Institution institution = new Institution(); + institution.setTaxCode("taxCode"); + institution.setSubunitCode("subunitCode"); + institution.setInstitutionType(InstitutionType.PSP); + onboarding.setInstitution(institution); + + User user = new User(); + user.setId("actual-user-id"); + user.setRole(PartyRole.MANAGER); + onboarding.setUsers(List.of(user)); + return onboarding; + } +} diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/util/InstitutionUtils.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/util/InstitutionUtils.java index 209d659b1..1ea3c613d 100644 --- a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/util/InstitutionUtils.java +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/util/InstitutionUtils.java @@ -11,7 +11,8 @@ public class InstitutionUtils { public static String getCurrentInstitutionType(Onboarding onboarding) { String institutionType = Product.CONTRACT_TYPE_DEFAULT; - if (Objects.nonNull(onboarding.getInstitution().getInstitutionType())) { + if (Objects.nonNull(onboarding.getInstitution()) + && Objects.nonNull(onboarding.getInstitution().getInstitutionType())) { institutionType = onboarding.getInstitution().getInstitutionType().name(); } diff --git a/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/util/InstitutionUtilsTest.java b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/util/InstitutionUtilsTest.java index 4dd62be0b..aaa07885f 100644 --- a/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/util/InstitutionUtilsTest.java +++ b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/util/InstitutionUtilsTest.java @@ -24,7 +24,7 @@ void getCurrentInstitutionTypeTest() { // then assertEquals("PSP", result); } - + @Test void getCurrentInstitutionTypeTest_shouldReturnDefault_whenInstitutionTypeIsNull() { // given @@ -38,6 +38,30 @@ void getCurrentInstitutionTypeTest_shouldReturnDefault_whenInstitutionTypeIsNull assertEquals("default", result); } + @Test + void getCurrentInstitutionTypeTest_shouldReturnDefault_whenInstitutionIsNotNull() { + // given + Onboarding onboarding = createDummyOnboarding(); + onboarding.setInstitution(new Institution()); + // when + String result = InstitutionUtils.getCurrentInstitutionType(onboarding); + + // then + assertEquals("default", result); + } + + @Test + void getCurrentInstitutionTypeTest_shouldReturnDefault_whenInstitutionIsNull() { + // given + Onboarding onboarding = createDummyOnboarding(); + onboarding.setInstitution(null); + // when + String result = InstitutionUtils.getCurrentInstitutionType(onboarding); + + // then + assertEquals("default", result); + } + private Onboarding createDummyOnboarding() { Onboarding onboarding = new Onboarding(); onboarding.setId(UUID.randomUUID().toString());