diff --git a/apps/user-cdc/src/main/java/it/pagopa/selfcare/user/event/mapper/NotificationMapper.java b/apps/user-cdc/src/main/java/it/pagopa/selfcare/user/event/mapper/NotificationMapper.java index 2226f680..b9807e6e 100644 --- a/apps/user-cdc/src/main/java/it/pagopa/selfcare/user/event/mapper/NotificationMapper.java +++ b/apps/user-cdc/src/main/java/it/pagopa/selfcare/user/event/mapper/NotificationMapper.java @@ -7,11 +7,12 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Named; -import org.openapi.quarkus.user_registry_json.model.CertifiableFieldResourceOfstring; -import org.openapi.quarkus.user_registry_json.model.UserResource; +import org.openapi.quarkus.user_registry_json.model.*; -import javax.swing.text.html.Option; -import java.util.*; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.UUID; @Mapper(componentModel = "cdi", imports = UUID.class) public interface NotificationMapper { @@ -52,9 +53,10 @@ default UserToNotify mapUserForFD(UserResource userResource,OnboardedProduct onb default UserToNotify mapUser(UserResource userResource, String userMailUuid, OnboardedProduct onboardedProduct) { UserToNotify userToNotify = new UserToNotify(); userToNotify.setUserId(Optional.ofNullable(userResource.getId()).map(UUID::toString).orElse(null)); - userToNotify.setName(Optional.ofNullable(userResource.getName()).map(CertifiableFieldResourceOfstring::getValue).orElse(null)); - userToNotify.setFamilyName(Optional.ofNullable(userResource.getFamilyName()).map(CertifiableFieldResourceOfstring::getValue).orElse(null)); + userToNotify.setName(Optional.ofNullable(userResource.getName()).map(NameCertifiableSchema::getValue).orElse(null)); + userToNotify.setFamilyName(Optional.ofNullable(userResource.getFamilyName()).map(FamilyNameCertifiableSchema::getValue).orElse(null)); userToNotify.setEmail(Optional.ofNullable(userMailUuid).map(mailUuid -> retrieveMailFromWorkContacts(userResource, mailUuid)).orElse(null)); + userToNotify.setMobilePhone(Optional.ofNullable(userMailUuid).map(mailUuid -> retrievePhoneFromWorkContacts(userResource, mailUuid)).orElse(null)); userToNotify.setProductRole(onboardedProduct.getProductRole()); userToNotify.setRole(Optional.ofNullable(onboardedProduct.getRole()).map(Enum::name).orElse(null)); userToNotify.setRelationshipStatus(onboardedProduct.getStatus()); @@ -65,7 +67,15 @@ default String retrieveMailFromWorkContacts(UserResource userResource, String us return Optional.ofNullable(userResource.getWorkContacts()) .flatMap(stringWorkContactResourceMap -> Optional.ofNullable(stringWorkContactResourceMap.get(userMailUuid)) .flatMap(workContactResource -> Optional.ofNullable(workContactResource.getEmail()) - .map(CertifiableFieldResourceOfstring::getValue))) + .map(EmailCertifiableSchema::getValue))) + .orElse(null); + } + + default String retrievePhoneFromWorkContacts(UserResource userResource, String userMailUuid) { + return Optional.ofNullable(userResource.getWorkContacts()) + .flatMap(stringWorkContactResourceMap -> Optional.ofNullable(stringWorkContactResourceMap.get(userMailUuid)) + .flatMap(workContactResource -> Optional.ofNullable(workContactResource.getMobilePhone()) + .map(MobilePhoneCertifiableSchema::getValue))) .orElse(null); } } diff --git a/apps/user-cdc/src/main/openapi/user_registry.json b/apps/user-cdc/src/main/openapi/user_registry.json index c6ac022d..c37fbd51 100644 --- a/apps/user-cdc/src/main/openapi/user_registry.json +++ b/apps/user-cdc/src/main/openapi/user_registry.json @@ -11,6 +11,9 @@ "basePath" : { "default" : "user-registry/v1" } + }, + "x-amazon-apigateway-endpoint-configuration" : { + "disableExecuteApiEndpoint" : true } } ], "tags" : [ { @@ -389,17 +392,7 @@ } } }, - "WorkContactResource" : { - "title" : "WorkContactResource", - "type" : "object", - "properties" : { - "email" : { - "$ref" : "#/components/schemas/CertifiableFieldResourceOfstring" - } - } - }, - "CertifiableFieldResourceOfstring" : { - "title" : "CertifiableFieldResourceOfstring", + "BirthDateCertifiableSchema" : { "required" : [ "certification", "value" ], "type" : "object", "properties" : { @@ -410,37 +403,42 @@ }, "value" : { "type" : "string", - "description" : "Field value" + "description" : "Field value", + "format" : "date" } - } + }, + "description" : "User date of birth" }, - "UserId" : { - "title" : "UserId", - "required" : [ "id" ], + "WorkContactResource" : { "type" : "object", "properties" : { - "id" : { - "type" : "string", - "description" : "User internal id", - "format" : "uuid" + "email" : { + "$ref" : "#/components/schemas/EmailCertifiableSchema" + }, + "mobilePhone" : { + "$ref" : "#/components/schemas/MobilePhoneCertifiableSchema" + }, + "telephone" : { + "$ref" : "#/components/schemas/TelephoneCertifiableSchema" } - } + }, + "description" : "User work contacts" }, "MutableUserFieldsDto" : { "title" : "MutableUserFieldsDto", "type" : "object", "properties" : { "birthDate" : { - "$ref" : "#/components/schemas/CertifiableFieldResourceOfLocalDate" + "$ref" : "#/components/schemas/BirthDateCertifiableSchema" }, "email" : { - "$ref" : "#/components/schemas/CertifiableFieldResourceOfstring" + "$ref" : "#/components/schemas/EmailCertifiableSchema" }, "familyName" : { - "$ref" : "#/components/schemas/CertifiableFieldResourceOfstring" + "$ref" : "#/components/schemas/FamilyNameCertifiableSchema" }, "name" : { - "$ref" : "#/components/schemas/CertifiableFieldResourceOfstring" + "$ref" : "#/components/schemas/NameCertifiableSchema" }, "workContacts" : { "type" : "object", @@ -451,8 +449,7 @@ } } }, - "CertifiableFieldResourceOfLocalDate" : { - "title" : "CertifiableFieldResourceOfLocalDate", + "NameCertifiableSchema" : { "required" : [ "certification", "value" ], "type" : "object", "properties" : { @@ -463,24 +460,23 @@ }, "value" : { "type" : "string", - "description" : "Field value", - "format" : "date" + "description" : "Field value" } - } + }, + "description" : "User name" }, "UserResource" : { - "title" : "UserResource", "required" : [ "id" ], "type" : "object", "properties" : { "birthDate" : { - "$ref" : "#/components/schemas/CertifiableFieldResourceOfLocalDate" + "$ref" : "#/components/schemas/BirthDateCertifiableSchema" }, "email" : { - "$ref" : "#/components/schemas/CertifiableFieldResourceOfstring" + "$ref" : "#/components/schemas/EmailCertifiableSchema" }, "familyName" : { - "$ref" : "#/components/schemas/CertifiableFieldResourceOfstring" + "$ref" : "#/components/schemas/FamilyNameCertifiableSchema" }, "fiscalCode" : { "type" : "string", @@ -492,7 +488,7 @@ "format" : "uuid" }, "name" : { - "$ref" : "#/components/schemas/CertifiableFieldResourceOfstring" + "$ref" : "#/components/schemas/NameCertifiableSchema" }, "workContacts" : { "type" : "object", @@ -503,26 +499,84 @@ } } }, + "TelephoneCertifiableSchema" : { + "required" : [ "certification", "value" ], + "type" : "object", + "properties" : { + "certification" : { + "type" : "string", + "description" : "Certified source of information", + "enum" : [ "NONE", "SPID" ] + }, + "value" : { + "type" : "string", + "description" : "Field value" + } + }, + "description" : "User work telephone number" + }, + "InvalidParam" : { + "title" : "InvalidParam", + "required" : [ "name", "reason" ], + "type" : "object", + "properties" : { + "name" : { + "type" : "string", + "description" : "Invalid parameter name." + }, + "reason" : { + "type" : "string", + "description" : "Invalid parameter reason." + } + } + }, + "EmailCertifiableSchema" : { + "required" : [ "certification", "value" ], + "type" : "object", + "properties" : { + "certification" : { + "type" : "string", + "description" : "Certified source of information", + "enum" : [ "NONE", "SPID" ] + }, + "value" : { + "type" : "string", + "description" : "Field value" + } + }, + "description" : "User email" + }, + "UserId" : { + "title" : "UserId", + "required" : [ "id" ], + "type" : "object", + "properties" : { + "id" : { + "type" : "string", + "description" : "User internal id", + "format" : "uuid" + } + } + }, "SaveUserDto" : { - "title" : "SaveUserDto", "required" : [ "fiscalCode" ], "type" : "object", "properties" : { "birthDate" : { - "$ref" : "#/components/schemas/CertifiableFieldResourceOfLocalDate" + "$ref" : "#/components/schemas/BirthDateCertifiableSchema" }, "email" : { - "$ref" : "#/components/schemas/CertifiableFieldResourceOfstring" + "$ref" : "#/components/schemas/EmailCertifiableSchema" }, "familyName" : { - "$ref" : "#/components/schemas/CertifiableFieldResourceOfstring" + "$ref" : "#/components/schemas/FamilyNameCertifiableSchema" }, "fiscalCode" : { "type" : "string", "description" : "User fiscal code" }, "name" : { - "$ref" : "#/components/schemas/CertifiableFieldResourceOfstring" + "$ref" : "#/components/schemas/NameCertifiableSchema" }, "workContacts" : { "type" : "object", @@ -569,20 +623,37 @@ }, "description" : "A \"problem detail\" as a way to carry machine-readable details of errors (https://datatracker.ietf.org/doc/html/rfc7807)" }, - "InvalidParam" : { - "title" : "InvalidParam", - "required" : [ "name", "reason" ], + "FamilyNameCertifiableSchema" : { + "required" : [ "certification", "value" ], "type" : "object", "properties" : { - "name" : { + "certification" : { "type" : "string", - "description" : "Invalid parameter name." + "description" : "Certified source of information", + "enum" : [ "NONE", "SPID" ] }, - "reason" : { + "value" : { "type" : "string", - "description" : "Invalid parameter reason." + "description" : "Field value" } - } + }, + "description" : "User family name" + }, + "MobilePhoneCertifiableSchema" : { + "required" : [ "certification", "value" ], + "type" : "object", + "properties" : { + "certification" : { + "type" : "string", + "description" : "Certified source of information", + "enum" : [ "NONE", "SPID" ] + }, + "value" : { + "type" : "string", + "description" : "Field value" + } + }, + "description" : "User work mobile phone number" } }, "securitySchemes" : { diff --git a/apps/user-cdc/src/test/java/it/pagopa/selfcare/user/event/mapper/NotificationMapperTest.java b/apps/user-cdc/src/test/java/it/pagopa/selfcare/user/event/mapper/NotificationMapperTest.java index f6568b88..c99daefb 100644 --- a/apps/user-cdc/src/test/java/it/pagopa/selfcare/user/event/mapper/NotificationMapperTest.java +++ b/apps/user-cdc/src/test/java/it/pagopa/selfcare/user/event/mapper/NotificationMapperTest.java @@ -5,36 +5,32 @@ import it.pagopa.selfcare.user.model.UserToNotify; import it.pagopa.selfcare.user.model.constants.OnboardedProductState; import org.junit.jupiter.api.Test; -import org.openapi.quarkus.user_registry_json.model.CertifiableFieldResourceOfstring; -import org.openapi.quarkus.user_registry_json.model.UserResource; -import org.openapi.quarkus.user_registry_json.model.WorkContactResource; - -import static org.junit.jupiter.api.Assertions.*; +import org.openapi.quarkus.user_registry_json.model.*; import java.util.List; import java.util.Map; import java.util.UUID; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + class NotificationMapperTest { @Test void mapUser_withValidData_shouldMapFieldsCorrectly() { - UserResource userResource = new UserResource(); - userResource.setId(UUID.randomUUID()); - userResource.setName(new CertifiableFieldResourceOfstring().value("John")); - userResource.setFamilyName(new CertifiableFieldResourceOfstring().value("Doe")); - userResource.setWorkContacts(Map.of("mailUuid", new WorkContactResource().email(new CertifiableFieldResourceOfstring().value("john.doe@example.com")))); + UserResource userResource = getUserResource(); OnboardedProduct onboardedProduct = new OnboardedProduct(); onboardedProduct.setProductRole("Admin"); onboardedProduct.setRole(PartyRole.MANAGER); onboardedProduct.setStatus(OnboardedProductState.ACTIVE); - UserToNotify result = new NotificationMapperImpl().mapUser(userResource, "mailUuid", onboardedProduct); + UserToNotify result = new NotificationMapperImpl().mapUser(userResource, "contactUuid", onboardedProduct); assertEquals(userResource.getId().toString(), result.getUserId()); assertEquals("John", result.getName()); assertEquals("Doe", result.getFamilyName()); assertEquals("john.doe@example.com", result.getEmail()); + assertEquals("0000000000", result.getMobilePhone()); assertEquals("Admin", result.getProductRole()); assertEquals("MANAGER", result.getRole()); assertEquals(OnboardedProductState.ACTIVE, result.getRelationshipStatus()); @@ -66,6 +62,7 @@ void mapUser_withNullFields_shouldHandleNullValues() { assertNull(result.getName()); assertNull(result.getFamilyName()); assertNull(result.getEmail()); + assertNull(result.getMobilePhone()); assertNull(result.getProductRole()); assertNull(result.getRole()); assertNull(result.getRelationshipStatus()); @@ -73,30 +70,68 @@ void mapUser_withNullFields_shouldHandleNullValues() { @Test void retrieveMailFromWorkContacts_withValidMailUuid_shouldReturnEmail() { - UserResource userResource = new UserResource(); - userResource.setWorkContacts(Map.of("mailUuid", new WorkContactResource().email(new CertifiableFieldResourceOfstring().value("john.doe@example.com")))); + UserResource userResource = getUserResource(); - String result = new NotificationMapperImpl().retrieveMailFromWorkContacts(userResource, "mailUuid"); + String result = new NotificationMapperImpl().retrieveMailFromWorkContacts(userResource, "contactUuid"); assertEquals("john.doe@example.com", result); } + @Test + void retrievePhoneFromWorkContacts_withValidMailUuid_shouldReturnEmail() { + UserResource userResource = getUserResource(); + + String result = new NotificationMapperImpl().retrievePhoneFromWorkContacts(userResource, "contactUuid"); + + assertEquals("0000000000", result); + } + @Test void retrieveMailFromWorkContacts_withInvalidMailUuid_shouldReturnNull() { - UserResource userResource = new UserResource(); - userResource.setWorkContacts(Map.of("mailUuid", new WorkContactResource().email(new CertifiableFieldResourceOfstring().value("john.doe@example.com")))); + UserResource userResource = getUserResource(); String result = new NotificationMapperImpl().retrieveMailFromWorkContacts(userResource, "invalidUuid"); assertNull(result); } + @Test + void retrievePhoneFromWorkContacts_withInvalidMailUuid_shouldReturnNull() { + UserResource userResource = getUserResource(); + + String result = new NotificationMapperImpl().retrievePhoneFromWorkContacts(userResource, "invalidUuid"); + + assertNull(result); + } + @Test void retrieveMailFromWorkContacts_withNullWorkContacts_shouldReturnNull() { UserResource userResource = new UserResource(); - String result = new NotificationMapperImpl().retrieveMailFromWorkContacts(userResource, "mailUuid"); + String result = new NotificationMapperImpl().retrieveMailFromWorkContacts(userResource, "contactUuid"); + + assertNull(result); + } + + @Test + void retrievePhoneFromWorkContacts_withNullPhone_shouldReturnNull() { + UserResource userResource = new UserResource(); + userResource.setWorkContacts(Map.of("contactUuid", new WorkContactResource().email(new EmailCertifiableSchema().value("john.doe@example.com")))); + + String result = new NotificationMapperImpl().retrievePhoneFromWorkContacts(userResource, "contactUuid"); assertNull(result); } + + private static UserResource getUserResource() { + UserResource userResource = new UserResource(); + userResource.setId(UUID.randomUUID()); + userResource.setName(new NameCertifiableSchema().value("John")); + userResource.setFamilyName(new FamilyNameCertifiableSchema().value("Doe")); + WorkContactResource workContactResource = new WorkContactResource(); + workContactResource.setEmail(new EmailCertifiableSchema().value("john.doe@example.com")); + workContactResource.setMobilePhone(new MobilePhoneCertifiableSchema().value("0000000000")); + userResource.setWorkContacts(Map.of("contactUuid", workContactResource)); + return userResource; + } } diff --git a/apps/user-ms/src/main/docs/openapi.json b/apps/user-ms/src/main/docs/openapi.json index 0ffc9925..9adf1250 100644 --- a/apps/user-ms/src/main/docs/openapi.json +++ b/apps/user-ms/src/main/docs/openapi.json @@ -1920,6 +1920,9 @@ "email" : { "type" : "string" }, + "mobilePhone" : { + "type" : "string" + }, "role" : { "description" : "Available values: MANAGER, DELEGATE, SUB_DELEGATE, OPERATOR, ADMIN_EA", "type" : "string" diff --git a/apps/user-ms/src/main/docs/openapi.yaml b/apps/user-ms/src/main/docs/openapi.yaml index 3394b481..405f85c9 100644 --- a/apps/user-ms/src/main/docs/openapi.yaml +++ b/apps/user-ms/src/main/docs/openapi.yaml @@ -1388,6 +1388,8 @@ components: type: string email: type: string + mobilePhone: + type: string role: description: "Available values: MANAGER, DELEGATE, SUB_DELEGATE, OPERATOR,\ \ ADMIN_EA" diff --git a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/mapper/NotificationMapper.java b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/mapper/NotificationMapper.java index d67cdf3e..bd387704 100644 --- a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/mapper/NotificationMapper.java +++ b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/mapper/NotificationMapper.java @@ -7,10 +7,7 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Named; -import org.openapi.quarkus.user_registry_json.model.EmailCertifiableSchema; -import org.openapi.quarkus.user_registry_json.model.FamilyNameCertifiableSchema; -import org.openapi.quarkus.user_registry_json.model.NameCertifiableSchema; -import org.openapi.quarkus.user_registry_json.model.UserResource; +import org.openapi.quarkus.user_registry_json.model.*; import java.util.Collections; import java.util.List; @@ -59,6 +56,7 @@ default UserToNotify mapUser(UserResource userResource, String userMailUuid, Onb userToNotify.setName(Optional.ofNullable(userResource.getName()).map(NameCertifiableSchema::getValue).orElse(null)); userToNotify.setFamilyName(Optional.ofNullable(userResource.getFamilyName()).map(FamilyNameCertifiableSchema::getValue).orElse(null)); userToNotify.setEmail(Optional.ofNullable(userMailUuid).map(mailUuid -> retrieveMailFromWorkContacts(userResource, mailUuid)).orElse(null)); + userToNotify.setMobilePhone(Optional.ofNullable(userMailUuid).map(mailUuid -> retrievePhoneFromWorkContacts(userResource, mailUuid)).orElse(null)); userToNotify.setProductRole(onboardedProduct.getProductRole()); userToNotify.setRole(Optional.ofNullable(onboardedProduct.getRole()).map(Enum::name).orElse(null)); userToNotify.setRelationshipStatus(onboardedProduct.getStatus()); @@ -72,4 +70,13 @@ default String retrieveMailFromWorkContacts(UserResource userResource, String us .map(EmailCertifiableSchema::getValue))) .orElse(null); } + + default String retrievePhoneFromWorkContacts(UserResource userResource, String userMailUuid) { + return Optional.ofNullable(userResource.getWorkContacts()) + .flatMap(stringWorkContactResourceMap -> Optional.ofNullable(stringWorkContactResourceMap.get(userMailUuid)) + .flatMap(workContactResource -> Optional.ofNullable(workContactResource.getMobilePhone()) + .map(MobilePhoneCertifiableSchema::getValue))) + .orElse(null); + } + } diff --git a/apps/user-ms/src/test/java/it/pagopa/selfcare/user/mapper/NotificationMapperTest.java b/apps/user-ms/src/test/java/it/pagopa/selfcare/user/mapper/NotificationMapperTest.java new file mode 100644 index 00000000..52027003 --- /dev/null +++ b/apps/user-ms/src/test/java/it/pagopa/selfcare/user/mapper/NotificationMapperTest.java @@ -0,0 +1,135 @@ +package it.pagopa.selfcare.user.mapper; + +import it.pagopa.selfcare.onboarding.common.PartyRole; +import it.pagopa.selfcare.user.model.OnboardedProduct; +import it.pagopa.selfcare.user.model.UserToNotify; +import it.pagopa.selfcare.user.model.constants.OnboardedProductState; +import org.junit.jupiter.api.Test; +import org.openapi.quarkus.user_registry_json.model.*; + +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +class NotificationMapperTest { + + @Test + void mapUser_withValidData_shouldMapFieldsCorrectly() { + UserResource userResource = getUserResource(); + OnboardedProduct onboardedProduct = new OnboardedProduct(); + onboardedProduct.setProductRole("Admin"); + onboardedProduct.setRole(PartyRole.MANAGER); + onboardedProduct.setStatus(OnboardedProductState.ACTIVE); + + UserToNotify result = new NotificationMapperImpl().mapUser(userResource, "contactUuid", onboardedProduct); + + assertEquals(userResource.getId().toString(), result.getUserId()); + assertEquals("John", result.getName()); + assertEquals("Doe", result.getFamilyName()); + assertEquals("john.doe@example.com", result.getEmail()); + assertEquals("0000000000", result.getMobilePhone()); + assertEquals("Admin", result.getProductRole()); + assertEquals("MANAGER", result.getRole()); + assertEquals(OnboardedProductState.ACTIVE, result.getRelationshipStatus()); + } + + @Test + void mapUserForFdTest() { + OnboardedProduct onboardedProduct = new OnboardedProduct(); + onboardedProduct.setProductRole("Admin"); + onboardedProduct.setRole(PartyRole.MANAGER); + + UserToNotify result = new NotificationMapperImpl().mapUserForFD("userId", onboardedProduct); + + assertEquals("userId", result.getUserId()); + assertEquals(List.of("Admin"), result.getRoles()); + assertEquals("MANAGER", result.getRole()); + } + + @Test + void mapUser_withNullFields_shouldHandleNullValues() { + UserResource userResource = new UserResource(); + OnboardedProduct onboardedProduct = new OnboardedProduct(); + + UserToNotify result = new NotificationMapperImpl().mapUser(userResource, null, onboardedProduct); + + assertNull(result.getUserId()); + assertNull(result.getName()); + assertNull(result.getFamilyName()); + assertNull(result.getEmail()); + assertNull(result.getMobilePhone()); + assertNull(result.getProductRole()); + assertNull(result.getRole()); + assertNull(result.getRelationshipStatus()); + } + + @Test + void retrieveMailFromWorkContacts_withValidMailUuid_shouldReturnEmail() { + UserResource userResource = getUserResource(); + + String result = new NotificationMapperImpl().retrieveMailFromWorkContacts(userResource, "contactUuid"); + + assertEquals("john.doe@example.com", result); + } + + @Test + void retrievePhoneFromWorkContacts_withValidMailUuid_shouldReturnEmail() { + UserResource userResource = getUserResource(); + + String result = new NotificationMapperImpl().retrievePhoneFromWorkContacts(userResource, "contactUuid"); + + assertEquals("0000000000", result); + } + + @Test + void retrieveMailFromWorkContacts_withInvalidMailUuid_shouldReturnNull() { + UserResource userResource = getUserResource(); + + String result = new NotificationMapperImpl().retrieveMailFromWorkContacts(userResource, "invalidUuid"); + + assertNull(result); + } + + @Test + void retrievePhoneFromWorkContacts_withInvalidMailUuid_shouldReturnNull() { + UserResource userResource = getUserResource(); + + String result = new NotificationMapperImpl().retrievePhoneFromWorkContacts(userResource, "invalidUuid"); + + assertNull(result); + } + + @Test + void retrieveMailFromWorkContacts_withNullWorkContacts_shouldReturnNull() { + UserResource userResource = new UserResource(); + + String result = new NotificationMapperImpl().retrieveMailFromWorkContacts(userResource, "contactUuid"); + + assertNull(result); + } + + @Test + void retrievePhoneFromWorkContacts_withNullPhone_shouldReturnNull() { + UserResource userResource = new UserResource(); + userResource.setWorkContacts(Map.of("contactUuid", new WorkContactResource().email(new EmailCertifiableSchema().value("john.doe@example.com")))); + + String result = new NotificationMapperImpl().retrievePhoneFromWorkContacts(userResource, "contactUuid"); + + assertNull(result); + } + + private static UserResource getUserResource() { + UserResource userResource = new UserResource(); + userResource.setId(UUID.randomUUID()); + userResource.setName(new NameCertifiableSchema().value("John")); + userResource.setFamilyName(new FamilyNameCertifiableSchema().value("Doe")); + WorkContactResource workContactResource = new WorkContactResource(); + workContactResource.setEmail(new EmailCertifiableSchema().value("john.doe@example.com")); + workContactResource.setMobilePhone(new MobilePhoneCertifiableSchema().value("0000000000")); + userResource.setWorkContacts(Map.of("contactUuid", workContactResource)); + return userResource; + } +} diff --git a/apps/user-ms/src/test/java/it/pagopa/selfcare/user/util/UserUtilTest.java b/apps/user-ms/src/test/java/it/pagopa/selfcare/user/util/UserUtilTest.java index b7fe063a..cbb17957 100644 --- a/apps/user-ms/src/test/java/it/pagopa/selfcare/user/util/UserUtilTest.java +++ b/apps/user-ms/src/test/java/it/pagopa/selfcare/user/util/UserUtilTest.java @@ -22,10 +22,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import org.openapi.quarkus.user_registry_json.model.EmailCertifiableSchema; -import org.openapi.quarkus.user_registry_json.model.NameCertifiableSchema; -import org.openapi.quarkus.user_registry_json.model.UserResource; -import org.openapi.quarkus.user_registry_json.model.WorkContactResource; +import org.openapi.quarkus.user_registry_json.model.*; import java.util.*; @@ -234,6 +231,7 @@ private static UserResource getUserResource(UUID uuid) { Map map = new HashMap<>(); WorkContactResource workContactResource = new WorkContactResource(); workContactResource.setEmail(EmailCertifiableSchema.builder().value("test@test.it").build()); + workContactResource.setMobilePhone(MobilePhoneCertifiableSchema.builder().value("0000000000").build()); map.put("MAIL_ID#123", workContactResource); return UserResource.builder() .id(uuid) diff --git a/libs/user-sdk-event/src/main/java/it/pagopa/selfcare/user/model/UserToNotify.java b/libs/user-sdk-event/src/main/java/it/pagopa/selfcare/user/model/UserToNotify.java index 6510cf6d..bf060052 100644 --- a/libs/user-sdk-event/src/main/java/it/pagopa/selfcare/user/model/UserToNotify.java +++ b/libs/user-sdk-event/src/main/java/it/pagopa/selfcare/user/model/UserToNotify.java @@ -19,6 +19,7 @@ public class UserToNotify { private String name; private String familyName; private String email; + private String mobilePhone; @Schema(description = "Available values: MANAGER, DELEGATE, SUB_DELEGATE, OPERATOR, ADMIN_EA") private String role; private String productRole;