Skip to content

Commit

Permalink
[SELC-6062] feat: added check on workflow type for SELC Manager and d…
Browse files Browse the repository at this point in the history
…efault origin and originId
  • Loading branch information
empassaro committed Dec 10, 2024
1 parent 9d2af63 commit 609c8f2
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public Uni<Onboarding> customValidation(Product product) {
onboarding.getInstitution().getTaxCode(),
onboarding.getProductId()), DEFAULT_ERROR.getCode());
}
return Uni.createFrom().item(onboarding);

return super.customValidation(product);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package it.pagopa.selfcare.onboarding.entity.registry;

import io.smallrye.mutiny.Uni;
import it.pagopa.selfcare.onboarding.common.Origin;
import it.pagopa.selfcare.onboarding.common.WorkflowType;
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import it.pagopa.selfcare.onboarding.exception.InvalidRequestException;
import it.pagopa.selfcare.product.entity.Product;

public class RegistryManagerSELC extends BaseRegistryManager<Object> {
Expand All @@ -11,12 +14,28 @@ public RegistryManagerSELC(Onboarding onboarding) {
}

public Object retrieveInstitution() {
return Uni.createFrom().item(new Object());
setDefaultOriginAndOriginId();
return Uni.createFrom().item(new Object());
}

private void setDefaultOriginAndOriginId() {
onboarding.getInstitution().setOriginId(onboarding.getInstitution().getTaxCode());
onboarding.getInstitution().setOrigin(Origin.SELC);
}

@Override
public Uni<Onboarding> customValidation(Product product) {
return Uni.createFrom().item(onboarding);
if (isWorkflowTypeAllowed(onboarding.getWorkflowType())) {
return Uni.createFrom().item(onboarding);
}

return Uni.createFrom().failure(new InvalidRequestException("Invalid workflow type for origin SELC"));
}

protected boolean isWorkflowTypeAllowed(WorkflowType workflowType) {
return workflowType == WorkflowType.FOR_APPROVE ||
workflowType == WorkflowType.IMPORT ||
workflowType == WorkflowType.FOR_APPROVE_PT;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ void onboardingIncrement_Ok(UniAsserter asserter) {
institutionBaseRequest.setInstitutionType(InstitutionType.PA);
institutionBaseRequest.setTaxCode("taxCode");
institutionBaseRequest.setOriginId("originId");
institutionBaseRequest.setOrigin(Origin.IPA);
institutionBaseRequest.setDescription(DESCRIPTION_FIELD);
institutionBaseRequest.setDigitalAddress(DIGITAL_ADDRESS_FIELD);
onboardingRequest.setInstitution(institutionBaseRequest);
Billing billing = new Billing();
billing.setRecipientCode("recCode");
Expand All @@ -294,6 +297,12 @@ void onboardingIncrement_Ok(UniAsserter asserter) {
mockVerifyAllowedMap(onboardingRequest.getInstitution().getTaxCode(), onboardingRequest.getProductId(), asserter);
mockVerifyOnboardingNotEmpty(asserter);

InstitutionResource institutionResource = new InstitutionResource();
institutionResource.setDigitalAddress(DIGITAL_ADDRESS_FIELD);
institutionResource.setDescription(DESCRIPTION_FIELD);
when(institutionRegistryProxyApi.findInstitutionUsingGET(any(), any(), any())).thenReturn(Uni.createFrom().item(institutionResource));


UOResource uoResource = new UOResource();
uoResource.setCodiceFiscaleSfe("codSfe");
uoResource.setCodiceIpa("originId");
Expand All @@ -317,6 +326,9 @@ private static OnboardingResponse getOnboardingResponse() {
institution.setInstitutionType("PA");
institution.setOriginId("originId");
institution.setTaxCode("taxCode");
institution.setDigitalAddress(DIGITAL_ADDRESS_FIELD);
institution.setDescription(DESCRIPTION_FIELD);
institution.setOrigin(Origin.IPA);
onboardingResponse.setInstitution(institution);

UserOnboardingResponse userOnboardingResponse = new UserOnboardingResponse();
Expand Down Expand Up @@ -485,6 +497,7 @@ void onboarding_Onboarding_addParentDescriptionForAooOrUo_Aoo(UniAsserter assert
institutionBaseRequest.setTaxCode("taxCode");
institutionBaseRequest.setSubunitType(InstitutionPaSubunitType.AOO);
institutionBaseRequest.setSubunitCode("SubunitCode");
institutionBaseRequest.setOrigin(Origin.IPA);
request.setInstitution(institutionBaseRequest);

mockPersistOnboarding(asserter);
Expand Down Expand Up @@ -594,6 +607,7 @@ void onboarding_Onboarding_addParentDescriptionForAooOrUo_Uo(UniAsserter asserte
institutionBaseRequest.setTaxCode("taxCode");
institutionBaseRequest.setSubunitType(InstitutionPaSubunitType.UO);
institutionBaseRequest.setSubunitCode("SubunitCode");
institutionBaseRequest.setOrigin(Origin.IPA);
request.setInstitution(institutionBaseRequest);

mockPersistOnboarding(asserter);
Expand Down Expand Up @@ -781,6 +795,33 @@ void onboarding_PRV(UniAsserter asserter) {
});
}

@Test
@RunOnVertxContext
void onboarding_SELC_Forbidden_WorkflowType(UniAsserter asserter) {
Onboarding request = new Onboarding();
List<UserRequest> users = List.of(manager);
request.setProductId(PROD_PAGOPA.getValue());
Institution institutionBaseRequest = new Institution();
institutionBaseRequest.setDescription("name");
institutionBaseRequest.setDigitalAddress("pec");
institutionBaseRequest.setInstitutionType(InstitutionType.GSP);
institutionBaseRequest.setTaxCode("taxCode");
request.setInstitution(institutionBaseRequest);
mockPersistOnboarding(asserter);

asserter.execute(() -> when(userRegistryApi.updateUsingPATCH(any(), any()))
.thenReturn(Uni.createFrom().item(Response.noContent().build())));


mockSimpleSearchPOSTAndPersist(asserter);
mockSimpleProductValidAssert(request.getProductId(), false, asserter);
mockVerifyOnboardingNotFound();
mockVerifyAllowedMap(request.getInstitution().getTaxCode(), request.getProductId(), asserter);

// onboardingCompletion will set the workflowType to COMPLETION, which is not allowed for GSP
asserter.assertFailedWith(() -> onboardingService.onboardingCompletion(request, users, null), InvalidRequestException.class);
}

@Test
@RunOnVertxContext
void onboarding_PRV_Bad_Request(UniAsserter asserter) {
Expand Down Expand Up @@ -1143,7 +1184,7 @@ void onboardingPsp_whenUserFoundedAndWillNotUpdateAndProductHasParent(UniAsserte

Institution dummyInstitution() {
Institution institution = new Institution();
institution.setInstitutionType(InstitutionType.SA);
institution.setInstitutionType(InstitutionType.GSP);
return institution;
}

Expand Down Expand Up @@ -1250,7 +1291,7 @@ void onboarding_whenUserFoundAndWillNotUpdate(UniAsserter asserter) {

Onboarding request = new Onboarding();
List<UserRequest> users = List.of(wrongManager);
request.setProductId(PROD_INTEROP.getValue());
request.setProductId(PROD_PAGOPA.getValue());
Institution institutionPspRequest = new Institution();
institutionPspRequest.setInstitutionType(InstitutionType.GSP);
request.setInstitution(institutionPspRequest);
Expand Down Expand Up @@ -1291,7 +1332,7 @@ void onboarding_whenUserFoundedAndWillUpdateMailUuid(UniAsserter asserter) {

Onboarding request = new Onboarding();
List<UserRequest> users = List.of(newManager);
request.setProductId(PROD_INTEROP.getValue());
request.setProductId(PROD_IO.getValue());
Institution institutionPspRequest = new Institution();
institutionPspRequest.setInstitutionType(InstitutionType.GSP);
request.setInstitution(institutionPspRequest);
Expand Down Expand Up @@ -1349,6 +1390,12 @@ void onboarding_whenUserNotFoundedAndWillSave(UniAsserter asserter) {
mockVerifyOnboardingNotFound();
mockVerifyAllowedMap(request.getInstitution().getTaxCode(), request.getProductId(), asserter);

InstitutionResource institutionResource = new InstitutionResource();
institutionResource.setDigitalAddress(DIGITAL_ADDRESS_FIELD);
institutionResource.setDescription(DESCRIPTION_FIELD);
when(institutionRegistryProxyApi.findInstitutionUsingGET(any(), any(), any())).thenReturn(Uni.createFrom().item(institutionResource));


asserter.execute(() -> when(Onboarding.persistOrUpdate(any(List.class)))
.thenAnswer(arg -> {
List<Onboarding> onboardings = (List<Onboarding>) arg.getArguments()[0];
Expand All @@ -1371,8 +1418,10 @@ void onboarding_whenUserNotFoundedAndWillSave(UniAsserter asserter) {
@RunOnVertxContext
void onboarding_shouldThrowExceptionIfUserRegistryFails(UniAsserter asserter) {
Onboarding onboardingDefaultRequest = new Onboarding();
onboardingDefaultRequest.setInstitution(dummyInstitution());
onboardingDefaultRequest.setProductId(PROD_INTEROP.getValue());
Institution institution = new Institution();
institution.setInstitutionType(InstitutionType.GSP);
onboardingDefaultRequest.setInstitution(institution);
onboardingDefaultRequest.setProductId(PROD_PAGOPA.getValue());
List<UserRequest> users = List.of(manager);

mockPersistOnboarding(asserter);
Expand Down Expand Up @@ -2010,11 +2059,17 @@ void onboarding_Onboarding_importPSP(UniAsserter asserter) {
void onboarding_aggregationCompletion(UniAsserter asserter) {
Onboarding request = new Onboarding();
List<UserRequest> users = List.of(manager);
request.setProductId(PROD_IO.getValue());
request.setProductId(PROD_INTEROP.getValue());
Institution institutionBaseRequest = new Institution();
institutionBaseRequest.setTaxCode("taxCode");
institutionBaseRequest.setInstitutionType(InstitutionType.SA);
institutionBaseRequest.setOrigin(Origin.IPA);
institutionBaseRequest.setDescription(DESCRIPTION_FIELD);
institutionBaseRequest.setDigitalAddress(DIGITAL_ADDRESS_FIELD);
request.setInstitution(institutionBaseRequest);
Billing billing = new Billing();
billing.setRecipientCode("recipientCode");
request.setBilling(billing);

mockPersistOnboarding(asserter);
mockPersistToken(asserter);
Expand All @@ -2029,6 +2084,8 @@ void onboarding_aggregationCompletion(UniAsserter asserter) {

InstitutionResource institutionResource = new InstitutionResource();
institutionResource.setCategory("L37");
institutionResource.setDescription(DESCRIPTION_FIELD);
institutionResource.setDigitalAddress(DIGITAL_ADDRESS_FIELD);
asserter.execute(() -> when(institutionRegistryProxyApi.findInstitutionUsingGET(institutionBaseRequest.getTaxCode(), null, null))
.thenReturn(Uni.createFrom().item(institutionResource)));

Expand All @@ -2046,12 +2103,15 @@ void onboarding_aggregationCompletion(UniAsserter asserter) {
@RunOnVertxContext
void onboardingCompletion(UniAsserter asserter) {
Onboarding request = new Onboarding();
Product product = createDummyProduct(PROD_IO.getValue(), false);
Product product = createDummyProduct(PROD_INTEROP.getValue(), false);
List<UserRequest> users = List.of(manager);
request.setProductId(PROD_IO.getValue());
request.setProductId(PROD_INTEROP.getValue());
Institution institutionBaseRequest = new Institution();
institutionBaseRequest.setTaxCode("taxCode");
institutionBaseRequest.setInstitutionType(InstitutionType.SA);
institutionBaseRequest.setOrigin(Origin.IPA);
institutionBaseRequest.setDescription(DESCRIPTION_FIELD);
institutionBaseRequest.setDigitalAddress(DIGITAL_ADDRESS_FIELD);
request.setInstitution(institutionBaseRequest);

mockPersistOnboarding(asserter);
Expand All @@ -2069,6 +2129,8 @@ void onboardingCompletion(UniAsserter asserter) {

InstitutionResource institutionResource = new InstitutionResource();
institutionResource.setCategory("L37");
institutionResource.setDigitalAddress(DIGITAL_ADDRESS_FIELD);
institutionResource.setDescription(DESCRIPTION_FIELD);
asserter.execute(() -> when(institutionRegistryProxyApi.findInstitutionUsingGET(institutionBaseRequest.getTaxCode(), null, null))
.thenReturn(Uni.createFrom().item(institutionResource)));

Expand Down

0 comments on commit 609c8f2

Please sign in to comment.