-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SELC-4185] feat: refactor logic on retrieve user email based on user…
…MailUuid instead of institutionId (#50)
- Loading branch information
Showing
6 changed files
with
53 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
import io.smallrye.mutiny.Uni; | ||
import it.pagopa.selfcare.user.constant.OnboardedProductState; | ||
import it.pagopa.selfcare.user.controller.response.UserInstitutionResponse; | ||
import it.pagopa.selfcare.user.controller.response.UserResponse; | ||
import it.pagopa.selfcare.user.entity.UserInfo; | ||
import it.pagopa.selfcare.user.entity.UserInstitutionRole; | ||
import it.pagopa.selfcare.user.exception.InvalidRequestException; | ||
|
@@ -19,16 +20,13 @@ | |
import org.apache.http.HttpStatus; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
import org.openapi.quarkus.user_registry_json.model.CertifiableFieldResourceOfLocalDate; | ||
import org.openapi.quarkus.user_registry_json.model.CertifiableFieldResourceOfstring; | ||
import org.openapi.quarkus.user_registry_json.model.MutableUserFieldsDto; | ||
import org.openapi.quarkus.user_registry_json.model.UserResource; | ||
|
||
import java.time.LocalDate; | ||
import java.util.*; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.mockito.ArgumentMatchers.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
|
||
@QuarkusTest | ||
@TestHTTPEndpoint(UserController.class) | ||
|
@@ -97,13 +95,12 @@ void getUsersEmailByInstitutionNotAuthorized() { | |
@Test | ||
@TestSecurity(user = "userJwt") | ||
void testGetUserInfoOk() { | ||
UserResource userResource = new UserResource(); | ||
userResource.setId(UUID.randomUUID()); | ||
userResource.setFiscalCode("test"); | ||
userResource.setBirthDate(CertifiableFieldResourceOfLocalDate.builder().value(LocalDate.now()).build()); | ||
userResource.setEmail(CertifiableFieldResourceOfstring.builder().value("[email protected]").build()); | ||
userResource.setName(CertifiableFieldResourceOfstring.builder().value("testName").build()); | ||
userResource.setFamilyName(CertifiableFieldResourceOfstring.builder().value("testFamilyName").build()); | ||
UserResponse userResource = new UserResponse(); | ||
userResource.setId(UUID.randomUUID().toString()); | ||
userResource.setTaxCode("test"); | ||
userResource.setEmail("email"); | ||
userResource.setName("name"); | ||
userResource.setSurname("testFamilyName"); | ||
|
||
Mockito.when(userService.retrievePerson(any(), any(), any())) | ||
.thenReturn(Uni.createFrom().item(userResource)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,14 +14,17 @@ | |
import io.smallrye.mutiny.helpers.test.UniAssertSubscriber; | ||
import it.pagopa.selfcare.product.service.ProductService; | ||
import it.pagopa.selfcare.user.constant.OnboardedProductState; | ||
import it.pagopa.selfcare.user.controller.response.*; | ||
import it.pagopa.selfcare.user.controller.response.UserInstitutionResponse; | ||
import it.pagopa.selfcare.user.controller.response.UserProductResponse; | ||
import it.pagopa.selfcare.user.controller.response.UserResponse; | ||
import it.pagopa.selfcare.user.entity.OnboardedProduct; | ||
import it.pagopa.selfcare.user.entity.UserInfo; | ||
import it.pagopa.selfcare.user.entity.UserInstitution; | ||
import it.pagopa.selfcare.user.entity.UserInstitutionRole; | ||
import it.pagopa.selfcare.user.exception.InvalidRequestException; | ||
import it.pagopa.selfcare.user.exception.ResourceNotFoundException; | ||
import it.pagopa.selfcare.user.mapper.UserMapper; | ||
import it.pagopa.selfcare.user.mapper.UserMapperImpl; | ||
import it.pagopa.selfcare.user.model.notification.UserNotificationToSend; | ||
import jakarta.inject.Inject; | ||
import org.apache.http.HttpStatus; | ||
|
@@ -30,6 +33,7 @@ | |
import org.jboss.resteasy.reactive.client.api.WebClientApplicationException; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
import org.mockito.Spy; | ||
import org.openapi.quarkus.user_registry_json.api.UserApi; | ||
import org.openapi.quarkus.user_registry_json.model.CertifiableFieldResourceOfLocalDate; | ||
import org.openapi.quarkus.user_registry_json.model.CertifiableFieldResourceOfstring; | ||
|
@@ -38,22 +42,14 @@ | |
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.*; | ||
|
||
import static it.pagopa.selfcare.user.constant.CustomError.*; | ||
import static it.pagopa.selfcare.onboarding.common.PartyRole.MANAGER; | ||
import static it.pagopa.selfcare.user.constant.CustomError.STATUS_IS_MANDATORY; | ||
import static it.pagopa.selfcare.user.constant.CustomError.USER_TO_UPDATE_NOT_FOUND; | ||
import static it.pagopa.selfcare.user.constant.CustomError.*; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.*; | ||
import static org.mockito.Mockito.when; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
@QuarkusTest | ||
@QuarkusTestResource(MongoTestResource.class) | ||
|
@@ -72,8 +68,9 @@ class UserServiceTest { | |
@InjectMock | ||
private UserApi userRegistryApi; | ||
|
||
@InjectMock | ||
private UserMapper userMapper; | ||
|
||
@Spy | ||
private UserMapper userMapper = new UserMapperImpl(); | ||
|
||
@InjectMock | ||
private ProductService productService; | ||
|
@@ -94,12 +91,13 @@ class UserServiceTest { | |
WorkContactResource workContactResource = new WorkContactResource(); | ||
workContactResource.setEmail(certifiedEmail); | ||
userResource.setEmail(certifiedEmail); | ||
userResource.setWorkContacts(Map.of("institutionId", workContactResource)); | ||
userResource.setWorkContacts(Map.of("userMailUuid", workContactResource)); | ||
|
||
userInstitution = new UserInstitution(); | ||
userInstitution.setId(ObjectId.get()); | ||
userInstitution.setUserId("userId"); | ||
userInstitution.setInstitutionId("institutionId"); | ||
userInstitution.setUserMailUuid("userMailUuid"); | ||
userInstitution.setInstitutionRootName("institutionRootName"); | ||
OnboardedProduct product = new OnboardedProduct(); | ||
product.setProductId("test"); | ||
|
@@ -149,6 +147,8 @@ void getUserProductsByInstitutionTest() { | |
void testRetrievePerson() { | ||
UserInstitution userInstitution = new UserInstitution(); | ||
userInstitution.setUserId("test-user"); | ||
String userMailUuId = UUID.randomUUID().toString(); | ||
userInstitution.setUserMailUuid(userMailUuId); | ||
|
||
UserResource userResource = new UserResource(); | ||
userResource.setId(UUID.randomUUID()); | ||
|
@@ -157,19 +157,22 @@ void testRetrievePerson() { | |
userResource.setEmail(CertifiableFieldResourceOfstring.builder().value("[email protected]").build()); | ||
userResource.setName(CertifiableFieldResourceOfstring.builder().value("testName").build()); | ||
userResource.setFamilyName(CertifiableFieldResourceOfstring.builder().value("testFamilyName").build()); | ||
WorkContactResource workContactResource = new WorkContactResource(); | ||
workContactResource.setEmail(CertifiableFieldResourceOfstring.builder().value("userMail").build()); | ||
userResource.setWorkContacts(Map.of(userMailUuId, workContactResource)); | ||
|
||
when(userInstitutionService.retrieveFirstFilteredUserInstitution(any())).thenReturn(Uni.createFrom().item(userInstitution)); | ||
when(userRegistryApi.findByIdUsingGET(any(), any())).thenReturn(Uni.createFrom().item(userResource)); | ||
|
||
UniAssertSubscriber<UserResource> subscriber = userService.retrievePerson("test-user", "test-product", "test-institutionId").subscribe().withSubscriber(UniAssertSubscriber.create()); | ||
subscriber.assertItem(userResource); | ||
UniAssertSubscriber<UserResponse> subscriber = userService.retrievePerson("test-user", "test-product", "test-institutionId").subscribe().withSubscriber(UniAssertSubscriber.create()); | ||
assertEquals("userMail", subscriber.getItem().getEmail()); | ||
} | ||
|
||
@Test | ||
void testRetrievePersonFailsWhenUserIsNotPresent() { | ||
when(userInstitutionService.retrieveFirstFilteredUserInstitution(any())).thenReturn(Uni.createFrom().nullItem()); | ||
|
||
UniAssertSubscriber<UserResource> subscriber = userService | ||
UniAssertSubscriber<UserResponse> subscriber = userService | ||
.retrievePerson("test-user", "test-product", "test-institutionId") | ||
.subscribe() | ||
.withSubscriber(UniAssertSubscriber.create()); | ||
|
@@ -184,7 +187,7 @@ void testRetrievePersonFailsWhenPdvFails() { | |
when(userInstitutionService.retrieveFirstFilteredUserInstitution(any())).thenReturn(Uni.createFrom().item(userInstitution)); | ||
when(userRegistryApi.findByIdUsingGET(any(), any())).thenReturn(Uni.createFrom().failure(new WebClientApplicationException(HttpStatus.SC_NOT_FOUND))); | ||
|
||
UniAssertSubscriber<UserResource> subscriber = userService.retrievePerson("test-user", "test-product", "test-institutionId").subscribe().withSubscriber(UniAssertSubscriber.create()); | ||
UniAssertSubscriber<UserResponse> subscriber = userService.retrievePerson("test-user", "test-product", "test-institutionId").subscribe().withSubscriber(UniAssertSubscriber.create()); | ||
|
||
subscriber.assertFailedWith(ResourceNotFoundException.class); | ||
} | ||
|
@@ -397,9 +400,6 @@ void findPaginatedUserNotificationToSend() { | |
UserResource userResource = mock(UserResource.class); | ||
when(userRegistryApi.findByIdUsingGET(any(), any())) | ||
.thenReturn(Uni.createFrom().item(userResource)); | ||
UserNotificationResponse userNotificationResponse = mock(UserNotificationResponse.class); | ||
when(userMapper.toUserNotification(any())) | ||
.thenReturn(userNotificationResponse); | ||
|
||
UniAssertSubscriber<List<UserNotificationToSend>> subscriber = userService | ||
.findPaginatedUserNotificationToSend(10, 0, "productId") | ||
|
@@ -416,9 +416,6 @@ void findPaginatedUserNotificationToSendQueryWithoutProductId() { | |
UserResource userResource = mock(UserResource.class); | ||
when(userRegistryApi.findByIdUsingGET(any(), any())) | ||
.thenReturn(Uni.createFrom().item(userResource)); | ||
UserNotificationResponse userNotificationResponse = mock(UserNotificationResponse.class); | ||
when(userMapper.toUserNotification(any())) | ||
.thenReturn(userNotificationResponse); | ||
|
||
UniAssertSubscriber<List<UserNotificationToSend>> subscriber = userService | ||
.findPaginatedUserNotificationToSend(10, 0, null) | ||
|