diff --git a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserInstitutionServiceDefault.java b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserInstitutionServiceDefault.java index d8b78ebd..b6a37643 100644 --- a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserInstitutionServiceDefault.java +++ b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserInstitutionServiceDefault.java @@ -79,14 +79,14 @@ public Uni deleteUserInstitutionProduct(String userId, String institutionI @Override public Uni updateUserStatusWithOptionalFilterByInstitutionAndProduct(String userId, String institutionId, String productId, PartyRole role, String productRole, OnboardedProductState status) { - Map onboardedProductFilterMap; - if(status.equals(OnboardedProductState.ACTIVE)) { - onboardedProductFilterMap = OnboardedProductFilter.builder().productId(productId).role(role).productRole(productRole).status(SUSPENDED.name()).build().constructMap(); - }else if(status.equals(SUSPENDED)) { - onboardedProductFilterMap = OnboardedProductFilter.builder().productId(productId).role(role).productRole(productRole).status(ACTIVE.name()).build().constructMap(); - }else { - onboardedProductFilterMap = OnboardedProductFilter.builder().productId(productId).role(role).productRole(productRole).build().constructMap(); - } + Map onboardedProductFilterMap = switch (status) { + case ACTIVE -> + OnboardedProductFilter.builder().productId(productId).role(role).productRole(productRole).status(SUSPENDED.name()).build().constructMap(); + case SUSPENDED, DELETED -> + OnboardedProductFilter.builder().productId(productId).role(role).productRole(productRole).status(ACTIVE.name()).build().constructMap(); + default -> + OnboardedProductFilter.builder().productId(productId).role(role).productRole(productRole).build().constructMap(); + }; Map userInstitutionFilterMap = UserInstitutionFilter.builder().userId(userId).institutionId(institutionId).build().constructMap(); Map filterMap = userUtils.retrieveMapForFilter(onboardedProductFilterMap, userInstitutionFilterMap); return updateUserStatusDao(filterMap, status); diff --git a/apps/user-ms/src/test/java/it/pagopa/selfcare/user/service/UserInstitutionServiceTest.java b/apps/user-ms/src/test/java/it/pagopa/selfcare/user/service/UserInstitutionServiceTest.java index 75b3ae53..fc0d3448 100644 --- a/apps/user-ms/src/test/java/it/pagopa/selfcare/user/service/UserInstitutionServiceTest.java +++ b/apps/user-ms/src/test/java/it/pagopa/selfcare/user/service/UserInstitutionServiceTest.java @@ -166,6 +166,21 @@ void updateUserStatusToSuspendWithInstitutionAndOnboardedFilter() { subscriber.assertCompleted().assertItem(1L); } + @Test + void updateUserStatusToDeleteWithInstitutionAndOnboardedFilter() { + final String userId = "userId"; + String institutionId = "institutionId"; + String productId = "productId"; + PanacheMock.mock(UserInstitution.class); + ReactivePanacheUpdate update = Mockito.mock(ReactivePanacheUpdate.class); + when(UserInstitution.update(any(Document.class))) + .thenReturn(update); + when(update.where(any())).thenReturn(Uni.createFrom().item(1L)); + UniAssertSubscriber subscriber = userInstitutionService.updateUserStatusWithOptionalFilterByInstitutionAndProduct(userId, institutionId, productId, null, null, OnboardedProductState.DELETED) + .subscribe().withSubscriber(UniAssertSubscriber.create()); + subscriber.assertCompleted().assertItem(1L); + } + @Test void updateUserStatusToActiveWithInstitutionAndOnboardedFilter() { final String userId = "userId";