From b2be39bb57eb2269a6286d2b948d0ed6f6048963 Mon Sep 17 00:00:00 2001 From: Manuel Rafeli Date: Wed, 17 Jan 2024 17:46:11 +0100 Subject: [PATCH] [SELC-349] Enhanced onboarding flow with admin approval in FOR_APPROVE workflows (#90) * TO_BE_VALIDATED status * send confirmation when PT * workflow approve when TO_BE_VALIDATED * fix switch onboarding status * unit test * default properties * next onboarding status * TO_BE_VALIDATED also for PT * unit test --- .../config/MailTemplatePathConfig.java | 1 + .../functions/OnboardingFunctions.java | 33 ++++++++++++++--- .../service/CompletionServiceDefault.java | 4 +-- .../service/NotificationService.java | 3 +- .../service/NotificationServiceDefault.java | 15 +++++--- .../onboarding/service/OnboardingService.java | 10 ++++++ .../src/main/resources/application.properties | 5 +-- .../onboarding/OnboardingFunctionsTest.java | 34 ++++++++++++++++++ .../service/CompletionServiceDefaultTest.java | 4 +-- .../NotificationServiceDefaultTest.java | 25 ++++++++++++- .../service/OnboardingServiceTest.java | 36 ++++++++++++++++++- .../service/OnboardingServiceDefault.java | 2 +- .../onboarding/common/OnboardingStatus.java | 1 + 13 files changed, 155 insertions(+), 18 deletions(-) diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/config/MailTemplatePathConfig.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/config/MailTemplatePathConfig.java index de71c16db..e24c5be06 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/config/MailTemplatePathConfig.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/config/MailTemplatePathConfig.java @@ -7,6 +7,7 @@ public interface MailTemplatePathConfig { String completePath(); String completePathFd(); + String completePathPt(); String autocompletePath(); diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java index 331b0c080..4ee7fd659 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/functions/OnboardingFunctions.java @@ -17,6 +17,7 @@ import com.microsoft.durabletask.azurefunctions.DurableClientInput; import com.microsoft.durabletask.azurefunctions.DurableOrchestrationTrigger; import it.pagopa.selfcare.onboarding.common.OnboardingStatus; +import it.pagopa.selfcare.onboarding.common.WorkflowType; import it.pagopa.selfcare.onboarding.config.RetryPolicyConfig; import it.pagopa.selfcare.onboarding.entity.Onboarding; import it.pagopa.selfcare.onboarding.exception.ResourceNotFoundException; @@ -39,6 +40,8 @@ public class OnboardingFunctions { public static final String SAVE_TOKEN_WITH_CONTRACT_ACTIVITY_NAME = "SaveTokenWithContract"; public static final String BUILD_CONTRACT_ACTIVITY_NAME = "BuildContract"; public static final String SEND_MAIL_REGISTRATION_WITH_CONTRACT_ACTIVITY = "SendMailRegistrationWithContract"; + + public static final String SEND_MAIL_REGISTRATION_WITH_CONTRACT_WHEN_APPROVE_ACTIVITY = "SendMailRegistrationWithContractWhenApprove"; public static final String SEND_MAIL_REGISTRATION_REQUEST_ACTIVITY = "SendMailRegistrationRequest"; public static final String SEND_MAIL_REGISTRATION_APPROVE_ACTIVITY = "SendMailRegistrationApprove"; public static final String SEND_MAIL_ONBOARDING_APPROVE_ACTIVITY = "SendMailOnboardingApprove"; @@ -93,13 +96,15 @@ public void onboardingsOrchestrator( switch (onboarding.getWorkflowType()) { case CONTRACT_REGISTRATION -> workflowContractRegistration(ctx, onboardingString); - case FOR_APPROVE -> workflowForApprove(ctx, onboardingString); + case FOR_APPROVE -> workflowForApprove(ctx, onboardingString, onboarding.getStatus()); case FOR_APPROVE_PT -> workflowRegistrationRequestAndApprove(ctx, onboardingString); case CONFIRMATION -> workflowForConfirmation(ctx, onboardingString); } //Last activity consist of saving pending status - String saveOnboardingStatusInput = SaveOnboardingStatusInput.buildAsJsonString(onboardingId, OnboardingStatus.PENDING.name()); + OnboardingStatus nextStatus = nextProcessOnboardingStatus(onboarding.getStatus(), onboarding.getWorkflowType()); + String saveOnboardingStatusInput = SaveOnboardingStatusInput.buildAsJsonString(onboardingId, nextStatus.name()); + ctx.callActivity(SAVE_ONBOARDING_STATUS_ACTIVITY, saveOnboardingStatusInput, optionsRetry, String.class).await(); } @@ -109,8 +114,14 @@ private void workflowContractRegistration(TaskOrchestrationContext ctx, String o ctx.callActivity(SEND_MAIL_REGISTRATION_WITH_CONTRACT_ACTIVITY, onboardingString, optionsRetry, String.class).await(); } - private void workflowForApprove(TaskOrchestrationContext ctx, String onboardingString){ - ctx.callActivity(SEND_MAIL_ONBOARDING_APPROVE_ACTIVITY, onboardingString, optionsRetry, String.class).await(); + private void workflowForApprove(TaskOrchestrationContext ctx, String onboardingString, OnboardingStatus onboardingStatus){ + if (OnboardingStatus.REQUEST.equals(onboardingStatus)) { + ctx.callActivity(SEND_MAIL_ONBOARDING_APPROVE_ACTIVITY, onboardingString, optionsRetry, String.class).await(); + } else if (OnboardingStatus.TO_BE_VALIDATED.equals(onboardingStatus)) { + ctx.callActivity(BUILD_CONTRACT_ACTIVITY_NAME, onboardingString, optionsRetry, String.class).await(); + ctx.callActivity(SAVE_TOKEN_WITH_CONTRACT_ACTIVITY_NAME, onboardingString, optionsRetry, String.class).await(); + ctx.callActivity(SEND_MAIL_REGISTRATION_WITH_CONTRACT_WHEN_APPROVE_ACTIVITY, onboardingString, optionsRetry, String.class).await(); + } } private void workflowRegistrationRequestAndApprove(TaskOrchestrationContext ctx, String onboardingString){ @@ -148,6 +159,11 @@ public void sendMailRegistrationWithContract(@DurableActivityTrigger(name = "onb context.getLogger().info(String.format(FORMAT_LOGGER_ONBOARDING_STRING, SEND_MAIL_REGISTRATION_WITH_CONTRACT_ACTIVITY, onboardingString)); service.sendMailRegistrationWithContract(readOnboardingValue(objectMapper, onboardingString)); } + @FunctionName(SEND_MAIL_REGISTRATION_WITH_CONTRACT_WHEN_APPROVE_ACTIVITY) + public void sendMailRegistrationWithContractWhenApprove(@DurableActivityTrigger(name = "onboardingString") String onboardingString, final ExecutionContext context) { + context.getLogger().info(String.format(FORMAT_LOGGER_ONBOARDING_STRING, SEND_MAIL_REGISTRATION_WITH_CONTRACT_WHEN_APPROVE_ACTIVITY, onboardingString)); + service.sendMailRegistrationWithContractWhenApprove(readOnboardingValue(objectMapper, onboardingString)); + } @FunctionName(SEND_MAIL_REGISTRATION_REQUEST_ACTIVITY) public void sendMailRegistration(@DurableActivityTrigger(name = "onboardingString") String onboardingString, final ExecutionContext context) { @@ -175,4 +191,13 @@ public String sendMailConfirmation(@DurableActivityTrigger(name = "onboardingStr context.getLogger().info(String.format(FORMAT_LOGGER_ONBOARDING_STRING, SEND_MAIL_CONFIRMATION_ACTIVITY, onboardingString)); return onboardingString; } + + private OnboardingStatus nextProcessOnboardingStatus(OnboardingStatus previous, WorkflowType workflowType) { + if(OnboardingStatus.REQUEST.equals(previous) && + (WorkflowType.FOR_APPROVE.equals(workflowType) || WorkflowType.FOR_APPROVE_PT.equals(workflowType))) { + return OnboardingStatus.TO_BE_VALIDATED; + } + + return OnboardingStatus.PENDING; + } } diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/CompletionServiceDefault.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/CompletionServiceDefault.java index 95f0399c1..398436abd 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/CompletionServiceDefault.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/CompletionServiceDefault.java @@ -136,7 +136,7 @@ private boolean isGspAndProdInterop(InstitutionType institutionType, String prod @Override public void sendCompletedEmail(Onboarding onboarding) { - String workContractId = String.format("obg_%s", onboarding.getOnboardingId()); + String workContractId = workContactsKey.apply(onboarding.getOnboardingId()); List destinationMails = onboarding.getUsers().stream() .filter(user -> MANAGER.equals(user.getRole())) @@ -152,7 +152,7 @@ public void sendCompletedEmail(Onboarding onboarding) { Product product = productService.getProductIsValid(onboarding.getProductId()); - notificationService.sendCompletedEmail(destinationMails, product); + notificationService.sendCompletedEmail(destinationMails, product, onboarding.getInstitution().getInstitutionType()); } diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationService.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationService.java index c1302081d..f433b6fc1 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationService.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationService.java @@ -1,6 +1,7 @@ package it.pagopa.selfcare.onboarding.service; +import it.pagopa.selfcare.onboarding.common.InstitutionType; import it.pagopa.selfcare.product.entity.Product; import java.util.List; @@ -15,5 +16,5 @@ public interface NotificationService { void sendMailRegistrationWithContract(String onboardingId, String destination, String name, String username, String productName); - void sendCompletedEmail(List destinationMails, Product product); + void sendCompletedEmail(List destinationMails, Product product, InstitutionType institutionType); } diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationServiceDefault.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationServiceDefault.java index a01b52a39..0d666f1d8 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationServiceDefault.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/NotificationServiceDefault.java @@ -4,6 +4,7 @@ import io.quarkus.mailer.Mail; import io.quarkus.mailer.Mailer; import it.pagopa.selfcare.azurestorage.AzureBlobClient; +import it.pagopa.selfcare.onboarding.common.InstitutionType; import it.pagopa.selfcare.onboarding.config.MailTemplatePathConfig; import it.pagopa.selfcare.onboarding.config.MailTemplatePlaceholdersConfig; import it.pagopa.selfcare.onboarding.entity.MailTemplate; @@ -136,11 +137,17 @@ public void sendMailRegistrationWithContract(String onboardingId, String destina } @Override - public void sendCompletedEmail(List destinationMails, Product product) { + public void sendCompletedEmail(List destinationMails, Product product, InstitutionType institutionType) { - String templatePath = product.getId().equals(PROD_FD.getValue())||product.getId().equals(PROD_FD_GARANTITO.getValue()) - ? templatePathConfig.completePathFd() - : templatePathConfig.completePath(); + String templatePath; + + if(InstitutionType.PT.equals(institutionType)) { + templatePath = templatePathConfig.completePathPt(); + } else { + templatePath =product.getId().equals(PROD_FD.getValue()) || product.getId().equals(PROD_FD_GARANTITO.getValue()) + ? templatePathConfig.completePathFd() + : templatePathConfig.completePath(); + } byte[] logoData = null; diff --git a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/OnboardingService.java b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/OnboardingService.java index 0bdbd931d..b3a75b25b 100644 --- a/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/OnboardingService.java +++ b/apps/onboarding-functions/src/main/java/it/pagopa/selfcare/onboarding/service/OnboardingService.java @@ -142,6 +142,16 @@ public void sendMailRegistrationWithContract(Onboarding onboarding) { sendMailInput.product.getTitle()); } + public void sendMailRegistrationWithContractWhenApprove(Onboarding onboarding) { + + SendMailInput sendMailInput = builderWithProductAndUserRequest(onboarding); + + notificationService.sendMailRegistrationWithContract(onboarding.getOnboardingId(), + onboarding.getInstitution().getDigitalAddress(), + onboarding.getInstitution().getDescription(), "", + sendMailInput.product.getTitle()); + } + public void sendMailRegistrationApprove(Onboarding onboarding) { SendMailInput sendMailInput = builderWithProductAndUserRequest(onboarding); diff --git a/apps/onboarding-functions/src/main/resources/application.properties b/apps/onboarding-functions/src/main/resources/application.properties index 9c0c81604..af51f06fc 100644 --- a/apps/onboarding-functions/src/main/resources/application.properties +++ b/apps/onboarding-functions/src/main/resources/application.properties @@ -54,14 +54,15 @@ onboarding-functions.logo-path = ${PAGOPA_LOGO_URL:resources/logo.png} ## MAIL TEMPLATE onboarding-functions.mail-template.path.onboarding.complete-path = ${MAIL_TEMPLATE_COMPLETE_PATH:contracts/template/mail/onboarding-complete/1.0.0.json} onboarding-functions.mail-template.path.onboarding.complete-path-fd = ${MAIL_TEMPLATE_FD_COMPLETE_NOTIFICATION_PATH:contracts/template/mail/onboarding-complete-fd/1.0.0.json} +onboarding-functions.mail-template.path.onboarding.complete-path-pt = ${MAIL_TEMPLATE_PT_COMPLETE_PATH:contracts/template/mail/onboarding-complete-pt/1.0.0.json} onboarding-functions.mail-template.path.onboarding.autocomplete-path = ${MAIL_TEMPLATE_AUTOCOMPLETE_PATH:default} onboarding-functions.mail-template.path.onboarding.delegation-notification-path = ${MAIL_TEMPLATE_DELEGATION_NOTIFICATION_PATH:default} onboarding-functions.mail-template.path.onboarding.registration-path = ${MAIL_TEMPLATE_REGISTRATION_PATH:contracts/template/mail/1.0.0.json} onboarding-functions.mail-template.path.onboarding.onboarding-approve-path = ${MAIL_TEMPLATE_NOTIFICATION_PATH:default} -onboarding-functions.mail-template.path.onboarding.registration-request-path = ${MAIL_TEMPLATE_REGISTRATION_REQUEST_PT_PATH:default} -onboarding-functions.mail-template.path.onboarding.registration-approve-path = ${MAIL_TEMPLATE_REGISTRATION_NOTIFICATION_ADMIN_PATH:default} +onboarding-functions.mail-template.path.onboarding.registration-request-path = ${MAIL_TEMPLATE_REGISTRATION_REQUEST_PT_PATH:contracts/template/mail/registration-request-pt/1.0.0.json} +onboarding-functions.mail-template.path.onboarding.registration-approve-path = ${MAIL_TEMPLATE_REGISTRATION_NOTIFICATION_ADMIN_PATH:contracts/template/mail/registration-notification-admin/1.0.0.json} onboarding-functions.mail-template.path.onboarding.reject-path = ${MAIL_TEMPLATE_REJECT_PATH:default} diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/OnboardingFunctionsTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/OnboardingFunctionsTest.java index 3cbe611ba..bef2f9ec2 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/OnboardingFunctionsTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/OnboardingFunctionsTest.java @@ -10,6 +10,7 @@ import com.microsoft.durabletask.azurefunctions.DurableClientContext; import io.quarkus.test.InjectMock; import io.quarkus.test.junit.QuarkusTest; +import it.pagopa.selfcare.onboarding.common.OnboardingStatus; import it.pagopa.selfcare.onboarding.common.WorkflowType; import it.pagopa.selfcare.onboarding.entity.Onboarding; import it.pagopa.selfcare.onboarding.exception.ResourceNotFoundException; @@ -130,6 +131,7 @@ void onboardingsOrchestratorContractRegistration() { void onboardingsOrchestratorForApprove() { Onboarding onboarding = new Onboarding(); onboarding.setOnboardingId("onboardingId"); + onboarding.setStatus(OnboardingStatus.REQUEST); onboarding.setWorkflowType(WorkflowType.FOR_APPROVE); TaskOrchestrationContext orchestrationContext = mockTaskOrchestrationContext(onboarding); @@ -143,6 +145,26 @@ void onboardingsOrchestratorForApprove() { assertEquals(SAVE_ONBOARDING_STATUS_ACTIVITY, captorActivity.getAllValues().get(1)); } + @Test + void onboardingsOrchestratorForApproveWhenToBeValidated() { + Onboarding onboarding = new Onboarding(); + onboarding.setOnboardingId("onboardingId"); + onboarding.setStatus(OnboardingStatus.TO_BE_VALIDATED); + onboarding.setWorkflowType(WorkflowType.FOR_APPROVE); + + TaskOrchestrationContext orchestrationContext = mockTaskOrchestrationContext(onboarding); + + function.onboardingsOrchestrator(orchestrationContext); + + ArgumentCaptor captorActivity = ArgumentCaptor.forClass(String.class); + Mockito.verify(orchestrationContext, times(4)) + .callActivity(captorActivity.capture(), any(), any(),any()); + assertEquals(BUILD_CONTRACT_ACTIVITY_NAME, captorActivity.getAllValues().get(0)); + assertEquals(SAVE_TOKEN_WITH_CONTRACT_ACTIVITY_NAME, captorActivity.getAllValues().get(1)); + assertEquals(SEND_MAIL_REGISTRATION_WITH_CONTRACT_WHEN_APPROVE_ACTIVITY, captorActivity.getAllValues().get(2)); + assertEquals(SAVE_ONBOARDING_STATUS_ACTIVITY, captorActivity.getAllValues().get(3)); + } + @Test void onboardingsOrchestratorConfirmation() { Onboarding onboarding = new Onboarding(); @@ -260,4 +282,16 @@ void sendMailOnboardingApprove() { Mockito.verify(service, times(1)) .sendMailOnboardingApprove(any()); } + + @Test + void sendMailRegistrationWithContractWhenApprove() { + ExecutionContext executionContext = mock(ExecutionContext.class); + when(executionContext.getLogger()).thenReturn(Logger.getGlobal()); + doNothing().when(service).sendMailRegistrationWithContractWhenApprove(any()); + + function.sendMailRegistrationWithContractWhenApprove(onboardinString, executionContext); + + Mockito.verify(service, times(1)) + .sendMailRegistrationWithContractWhenApprove(any()); + } } diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/CompletionServiceDefaultTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/CompletionServiceDefaultTest.java index d47781fc1..a89163279 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/CompletionServiceDefaultTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/CompletionServiceDefaultTest.java @@ -261,12 +261,12 @@ void sendCompletedEmail() { .thenReturn(product); when(userRegistryApi.findByIdUsingGET(USERS_FIELD_LIST, user.getId())) .thenReturn(userResource); - doNothing().when(notificationService).sendCompletedEmail(any(), any()); + doNothing().when(notificationService).sendCompletedEmail(any(), any(), any()); completionServiceDefault.sendCompletedEmail(onboarding); Mockito.verify(notificationService, times(1)) - .sendCompletedEmail(any(), any()); + .sendCompletedEmail(any(), any(), any()); } private InstitutionResponse dummyInstitutionResponse() { diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationServiceDefaultTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationServiceDefaultTest.java index bc5f9bb46..fc6045db7 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationServiceDefaultTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/NotificationServiceDefaultTest.java @@ -6,6 +6,7 @@ import io.quarkus.test.InjectMock; import io.quarkus.test.junit.QuarkusTest; import it.pagopa.selfcare.azurestorage.AzureBlobClient; +import it.pagopa.selfcare.onboarding.common.InstitutionType; import it.pagopa.selfcare.onboarding.config.MailTemplatePathConfig; import it.pagopa.selfcare.onboarding.config.MailTemplatePlaceholdersConfig; import it.pagopa.selfcare.product.entity.Product; @@ -129,7 +130,7 @@ void sendCompletedEmail() { .thenReturn(mailTemplate); Mockito.doNothing().when(mailer).send(any()); - notificationService.sendCompletedEmail(List.of(destination), product); + notificationService.sendCompletedEmail(List.of(destination), product, InstitutionType.PA); Mockito.verify(azureBlobClient, Mockito.times(1)) .getFileAsText(any()); @@ -162,4 +163,26 @@ void sendMailRegistrationApprove() { assertEquals(notificationAdminMail, mailArgumentCaptor.getValue().getTo().get(0)); } + + @Test + void sendMailOnboardingApprove() { + + final String mailTemplate = "{\"subject\":\"example\",\"body\":\"example\"}"; + final String institutionName = "institutionName"; + + Mockito.when(azureBlobClient.getFileAsText(templatePathConfig.onboardingApprovePath())) + .thenReturn(mailTemplate); + Mockito.doNothing().when(mailer).send(any()); + + notificationService.sendMailOnboardingApprove(institutionName, "name","username","product","token"); + + Mockito.verify(azureBlobClient, Mockito.times(1)) + .getFileAsText(any()); + + ArgumentCaptor mailArgumentCaptor = ArgumentCaptor.forClass(Mail.class); + Mockito.verify(mailer, Mockito.times(1)) + .send(mailArgumentCaptor.capture()); + assertEquals(notificationAdminMail, mailArgumentCaptor.getValue().getTo().get(0)); + } + } diff --git a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/OnboardingServiceTest.java b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/OnboardingServiceTest.java index 45f1de111..da5264d34 100644 --- a/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/OnboardingServiceTest.java +++ b/apps/onboarding-functions/src/test/java/it/pagopa/selfcare/onboarding/service/OnboardingServiceTest.java @@ -65,7 +65,9 @@ private Onboarding createOnboarding() { onboarding.setOnboardingId(onboarding.getId().toHexString()); onboarding.setProductId(productId); onboarding.setUsers(List.of()); - onboarding.setInstitution(new Institution()); + Institution institution = new Institution(); + institution.setDescription("description"); + onboarding.setInstitution(institution); onboarding.setUserRequestUid("example-uid"); return onboarding; } @@ -240,6 +242,38 @@ void sendMailRegistrationWithContract() { } + @Test + void sendMailRegistrationWithContractWhenApprove() { + + Onboarding onboarding = createOnboarding(); + Product product = createDummyProduct(); + UserResource userResource = createUserResource(); + Token token = new Token(); + token.setId(ObjectId.get()); + + when(tokenRepository.findByOnboardingId(onboarding.getOnboardingId())) + .thenReturn(Optional.of(token)); + when(productService.getProduct(onboarding.getProductId())) + .thenReturn(product); + + when(userRegistryApi.findByIdUsingGET(USERS_FIELD_LIST, onboarding.getUserRequestUid())) + .thenReturn(userResource); + doNothing().when(notificationService) + .sendMailRegistrationWithContract(onboarding.getOnboardingId(), + onboarding.getInstitution().getDigitalAddress(), + onboarding.getInstitution().getDescription(), "", + product.getTitle()); + + onboardingService.sendMailRegistrationWithContractWhenApprove(onboarding); + + Mockito.verify(notificationService, times(1)) + .sendMailRegistrationWithContract(onboarding.getOnboardingId(), + onboarding.getInstitution().getDigitalAddress(), + onboarding.getInstitution().getDescription(), "", + product.getTitle()); + } + + @Test void sendMailRegistrationWithContract_throwExceptionWhenTokenIsNotPresent() { Onboarding onboarding = createOnboarding(); diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/OnboardingServiceDefault.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/OnboardingServiceDefault.java index f216c35ee..44baaf67a 100644 --- a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/OnboardingServiceDefault.java +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/OnboardingServiceDefault.java @@ -77,7 +77,7 @@ public class OnboardingServiceDefault implements OnboardingService { public static final String USERS_FIELD_LIST = "fiscalCode,familyName,name,workContacts"; public static final String USERS_FIELD_TAXCODE = "fiscalCode"; - public static final String UNABLE_TO_COMPLETE_THE_ONBOARDING_FOR_INSTITUTION_ALREADY_ONBOARDED = "Unable to complete the onboarding for institution with taxCode '%s' to product '%s'."; + public static final String UNABLE_TO_COMPLETE_THE_ONBOARDING_FOR_INSTITUTION_ALREADY_ONBOARDED = "Unable to complete the onboarding for institution with taxCode '%s' to product '%s' because is already onboarded."; public static final Function workContactsKey = onboardingId -> String.format("obg_%s", onboardingId); diff --git a/libs/onboarding-sdk-common/src/main/java/it/pagopa/selfcare/onboarding/common/OnboardingStatus.java b/libs/onboarding-sdk-common/src/main/java/it/pagopa/selfcare/onboarding/common/OnboardingStatus.java index 1b2d98b52..1991c9f94 100644 --- a/libs/onboarding-sdk-common/src/main/java/it/pagopa/selfcare/onboarding/common/OnboardingStatus.java +++ b/libs/onboarding-sdk-common/src/main/java/it/pagopa/selfcare/onboarding/common/OnboardingStatus.java @@ -1,6 +1,7 @@ package it.pagopa.selfcare.onboarding.common; public enum OnboardingStatus { REQUEST, + TO_BE_VALIDATED, PENDING, COMPLETED, FAILED,