diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/controller/OnboardingController.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/controller/OnboardingController.java index d3ac4637..9817b6db 100644 --- a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/controller/OnboardingController.java +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/controller/OnboardingController.java @@ -252,7 +252,7 @@ public Uni onboardingPspCompletion(@Valid OnboardingPspReque public Uni onboardingPgCompletion(@Valid OnboardingPgRequest onboardingRequest, @Context SecurityContext ctx) { return readUserIdFromToken(ctx) .onItem().transformToUni(userId -> onboardingService - .onboardingCompletion(fillUserId(onboardingMapper.toEntity(onboardingRequest), userId), onboardingRequest.getUsers())); + .onboardingPgCompletion(fillUserId(onboardingMapper.toEntity(onboardingRequest), userId), onboardingRequest.getUsers())); } @Operation( diff --git a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/OnboardingService.java b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/OnboardingService.java index c584023f..488be2e3 100644 --- a/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/OnboardingService.java +++ b/apps/onboarding-ms/src/main/java/it/pagopa/selfcare/onboarding/service/OnboardingService.java @@ -37,6 +37,9 @@ Uni onboardingImport( Uni onboardingCompletion( Onboarding onboarding, List userRequests); + Uni onboardingPgCompletion( + Onboarding onboarding, List userRequests); + Uni onboardingAggregationCompletion( Onboarding onboarding, List userRequests, 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 03d51cfc..f0325855 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 @@ -246,6 +246,16 @@ public Uni onboardingCompletion( onboarding, userRequests, null, TIMEOUT_ORCHESTRATION_RESPONSE, false); } + @Override + public Uni onboardingPgCompletion( + Onboarding onboarding, List userRequests) { + onboarding.setWorkflowType(WorkflowType.CONFIRMATION); + onboarding.setStatus(OnboardingStatus.PENDING); + + return fillUsersAndOnboarding( + onboarding, userRequests, null, TIMEOUT_ORCHESTRATION_RESPONSE, false); + } + @Override public Uni onboardingAggregationCompletion( Onboarding onboarding, diff --git a/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/controller/OnboardingControllerTest.java b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/controller/OnboardingControllerTest.java index 9e8b04ee..93aef5a9 100644 --- a/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/controller/OnboardingControllerTest.java +++ b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/controller/OnboardingControllerTest.java @@ -679,7 +679,7 @@ void onboardingCompletePg() { onboardingPgRequest.setDigitalAddress("digital@address.it"); onboardingPgRequest.setOrigin(Origin.INFOCAMERE); - Mockito.when(onboardingService.onboardingCompletion(any(), any())) + Mockito.when(onboardingService.onboardingPgCompletion(any(), any())) .thenReturn(Uni.createFrom().item(new OnboardingResponse())); given() @@ -691,7 +691,7 @@ void onboardingCompletePg() { .statusCode(200); ArgumentCaptor captor = ArgumentCaptor.forClass(Onboarding.class); - Mockito.verify(onboardingService, times(1)).onboardingCompletion(captor.capture(), any()); + Mockito.verify(onboardingService, times(1)).onboardingPgCompletion(captor.capture(), any()); assertEquals(InstitutionType.PG, captor.getValue().getInstitution().getInstitutionType()); } diff --git a/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/service/OnboardingServiceDefaultTest.java b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/service/OnboardingServiceDefaultTest.java index fc1c7be8..fcf5eeaf 100644 --- a/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/service/OnboardingServiceDefaultTest.java +++ b/apps/onboarding-ms/src/test/java/it/pagopa/selfcare/onboarding/service/OnboardingServiceDefaultTest.java @@ -2144,6 +2144,47 @@ void onboardingCompletion(UniAsserter asserter) { }); } + @Test + @RunOnVertxContext + void onboardingPgCompletion(UniAsserter asserter) { + Onboarding request = new Onboarding(); + Product product = createDummyProduct(PROD_PN.getValue(), false); + List users = List.of(manager); + request.setProductId(PROD_PN.getValue()); + Institution institutionBaseRequest = new Institution(); + institutionBaseRequest.setTaxCode("taxCode"); + institutionBaseRequest.setInstitutionType(InstitutionType.PG); + institutionBaseRequest.setOrigin(Origin.INFOCAMERE); + request.setInstitution(institutionBaseRequest); + + mockPersistOnboarding(asserter); + mockPersistToken(asserter); + + mockSimpleSearchPOSTAndPersist(asserter); + mockSimpleProductValidAssert(request.getProductId(), false, asserter); + mockVerifyOnboardingNotFound(); + mockVerifyAllowedMap(request.getInstitution().getTaxCode(), request.getProductId(), asserter); + + asserter.execute(() -> when(productService.getProduct(any())).thenReturn(product)); + + asserter.execute(() -> when(userRegistryApi.updateUsingPATCH(any(), any())) + .thenReturn(Uni.createFrom().item(Response.noContent().build()))); + + InstitutionResource institutionResource = new InstitutionResource(); + institutionResource.setCategory("L37"); + asserter.execute(() -> when(institutionRegistryProxyApi.findInstitutionUsingGET(institutionBaseRequest.getTaxCode(), null, null)) + .thenReturn(Uni.createFrom().item(institutionResource))); + + asserter.assertThat(() -> onboardingService.onboardingPgCompletion(request, users), Assertions::assertNotNull); + + asserter.execute(() -> { + PanacheMock.verify(Onboarding.class).persist(any(Onboarding.class), any()); + PanacheMock.verify(Onboarding.class).persistOrUpdate(any(List.class)); + PanacheMock.verify(Onboarding.class).find(any(Document.class)); + PanacheMock.verifyNoMoreInteractions(Onboarding.class); + }); + } + @Test @RunOnVertxContext void onboardingUsers(UniAsserter asserter) {