Skip to content

Commit

Permalink
[SELC-6086] Feat: Added mobilePhone in updateUser API (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
flaminiaScarciofolo authored Nov 28, 2024
1 parent bc43661 commit 2e9dedd
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 30 deletions.
5 changes: 5 additions & 0 deletions app/src/main/resources/swagger/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -4278,6 +4278,11 @@
"format" : "email",
"example" : "[email protected]"
},
"mobilePhone" : {
"pattern" : "^\\+?[0-9]{9,15}$",
"type" : "string",
"description" : "User's institutional phone number"
},
"name" : {
"type" : "string",
"description" : "User's name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public class UpdateUserRequestDto {
private String name;
private String surname;
private String email;
private String mobilePhone;
}
63 changes: 61 additions & 2 deletions connector/rest/docs/openapi/selfcare-user-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"name" : "external-pnpg"
}, {
"name" : "external-v2"
}, {
"name" : "internal-pnpg"
}, {
"name" : "internal-v1"
}, {
Expand Down Expand Up @@ -472,7 +474,7 @@
} ]
},
"post" : {
"tags" : [ "User" ],
"tags" : [ "User", "internal-pnpg" ],
"summary" : "Create or update a user by fiscal code",
"description" : "The createOrUpdateByFiscalCode function is used to create a new user or update an existing one.",
"operationId" : "createOrUpdateByFiscalCode",
Expand Down Expand Up @@ -1308,6 +1310,51 @@
"SecurityScheme" : [ ]
} ]
}
},
"/users/{userId}/onboarding" : {
"post" : {
"tags" : [ "User" ],
"summary" : "Check if the user is manager or Update/create a user by userId with a new role",
"description" : "Checks if the user is already a manager for the specified product and, if not, creates or updates the user with a new role.",
"operationId" : "createUserByUserId",
"parameters" : [ {
"name" : "userId",
"in" : "path",
"required" : true,
"schema" : {
"type" : "string"
}
} ],
"requestBody" : {
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/AddUserRoleDto"
}
}
}
},
"responses" : {
"200" : {
"description" : "The user is already a manager for the specified product.",
"content" : {
"application/json" : { }
}
},
"201" : {
"description" : "The user has been created or updated with a new role."
},
"401" : {
"description" : "Not Authorized"
},
"403" : {
"description" : "Not Allowed"
}
},
"security" : [ {
"SecurityScheme" : [ ]
} ]
}
}
},
"components" : {
Expand Down Expand Up @@ -1577,7 +1624,6 @@
}
},
"UpdateUserRequest" : {
"required" : [ "email" ],
"type" : "object",
"properties" : {
"name" : {
Expand All @@ -1588,6 +1634,10 @@
},
"email" : {
"type" : "string"
},
"mobilePhone" : {
"pattern" : "^\\+?[0-9]{9,15}$",
"type" : "string"
}
}
},
Expand Down Expand Up @@ -1670,6 +1720,9 @@
"email" : {
"$ref" : "#/components/schemas/CertifiableFieldResponseString"
},
"mobilePhone" : {
"$ref" : "#/components/schemas/CertifiableFieldResponseString"
},
"workContacts" : {
"type" : "object",
"additionalProperties" : {
Expand Down Expand Up @@ -1875,6 +1928,12 @@
"productRole" : {
"type" : "string"
},
"roles" : {
"type" : "array",
"items" : {
"type" : "string"
}
},
"relationshipStatus" : {
"$ref" : "#/components/schemas/OnboardedProductState"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Data;

import javax.validation.constraints.Email;
import javax.validation.constraints.Pattern;

@Data
public class UpdateUserDto {
Expand All @@ -17,4 +18,8 @@ public class UpdateUserDto {
@ApiModelProperty(value = "${swagger.dashboard.user.model.institutionalEmail}")
@Email
private String email;

@ApiModelProperty(value = "${swagger.dashboard.user.model.institutionalPhone}")
@Pattern(regexp = "^\\+?[0-9]{9,15}$", message = "Il numero di telefono non è valido")
private String mobilePhone;
}
1 change: 1 addition & 0 deletions web/src/main/resources/swagger/swagger_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ swagger.dashboard.user.model.birthDate=User's birth date
swagger.dashboard.user.model.email=User's personal email
swagger.dashboard.user.model.workContacts=User's workcontacts, contains the emails associated to every institution the user is assigned to
swagger.dashboard.user.model.institutionalEmail=User's institutional email
swagger.dashboard.user.model.institutionalPhone=User's institutional phone number
swagger.dashboard.user.model.role=User's role, available value: [MANAGER, DELEGATE, SUBDELEGATE, OPERATOR, ADMIN_EA]
swagger.dashboard.user.model.selcRole=User's Selfcare role, available value: [ADMIN, ADMIN_EA, LIMITED]
swagger.dashboard.user.model.fields=Fields to retrieve from pdv when searching for user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,50 @@ void updateUser() throws Exception {
Mockito.verifyNoMoreInteractions(userServiceMock);
}

@Test
void updateUserInvalidMobilePhone() throws Exception {
//given
final String id = "userId";
final String institutionId = "institutionId";

byte[] userStream = Files.readAllBytes(Paths.get("src/test/resources/stubs/updateUserDto.json"));
UpdateUserDto updateUserDto = objectMapper.readValue(userStream, UpdateUserDto.class);
updateUserDto.setMobilePhone("12345678912345566788");

//when
mockMvc.perform(MockMvcRequestBuilders
.put(BASE_URL + "/{id}", id)
.queryParam("institutionId", institutionId)
.content(objectMapper.writeValueAsString(updateUserDto))
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isBadRequest());

Mockito.verifyNoInteractions(userServiceMock);
}

@Test
void updateUserInvalidMail() throws Exception {
//given
final String id = "userId";
final String institutionId = "institutionId";

byte[] userStream = Files.readAllBytes(Paths.get("src/test/resources/stubs/updateUserDto.json"));
UpdateUserDto updateUserDto = objectMapper.readValue(userStream, UpdateUserDto.class);
updateUserDto.setEmail("test");

//when
mockMvc.perform(MockMvcRequestBuilders
.put(BASE_URL + "/{id}", id)
.queryParam("institutionId", institutionId)
.content(objectMapper.writeValueAsString(updateUserDto))
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isBadRequest());

Mockito.verifyNoInteractions(userServiceMock);
}

@Test
void getUsers_institutionIdProductIdValid() throws Exception {
// given
Expand Down Expand Up @@ -365,31 +409,6 @@ void search_EmptyObject() throws Exception {
Mockito.verifyNoMoreInteractions(userServiceMock);
}

@Test
void updateUser_EmptyObject() throws Exception {
//given
final String id = "userId";
final String institutionId = "institutionId";

byte[] userStream = Files.readAllBytes(Paths.get("src/test/resources/stubs/updateUserDto.json"));
UpdateUserDto updateUserDto = objectMapper.readValue(userStream, UpdateUserDto.class);

//when
mockMvc.perform(MockMvcRequestBuilders
.put(BASE_URL + "/{id}", id)
.queryParam("institutionId", institutionId)
.content(userStream)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isNoContent())
.andExpect(content().string(emptyString()));
//then
verify(userServiceMock, times(1))
.updateUser(id, institutionId, userMapper.fromUpdateUser(updateUserDto));

Mockito.verifyNoMoreInteractions(userServiceMock);
}

@Test
void getUsers_institutionIdProductIdValid_EmptyObject() throws Exception {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -46,7 +45,7 @@ void validateNullFields() {
Class<? extends Annotation> annotationToCheck = toCheckMap.get(violation.getPropertyPath().toString());
return !violation.getConstraintDescriptor().getAnnotation().annotationType().equals(annotationToCheck);
})
.collect(Collectors.toList());
.toList();
assertTrue(filteredViolations.isEmpty());
}

Expand All @@ -56,6 +55,7 @@ void validateNotNullFields() {
// given
UpdateUserDto model = TestUtils.mockInstance(new UpdateUserDto());
model.setEmail("[email protected]");
model.setMobilePhone("1234567890");
// when
Set<ConstraintViolation<Object>> violations = validator.validate(model);
// then
Expand All @@ -69,6 +69,7 @@ void validate_emailFieldsNotValid() {
HashMap<String, Class<? extends Annotation>> toCheckMap = new HashMap<>();
toCheckMap.put("email", Email.class);
UpdateUserDto model = TestUtils.mockInstance(new UpdateUserDto());
model.setMobilePhone("1234567890");
// when
Set<ConstraintViolation<Object>> violations = validator.validate(model);
// then
Expand All @@ -77,7 +78,7 @@ void validate_emailFieldsNotValid() {
Class<? extends Annotation> annotationToCheck = toCheckMap.get(violation.getPropertyPath().toString());
return !violation.getConstraintDescriptor().getAnnotation().annotationType().equals(annotationToCheck);
})
.collect(Collectors.toList());
.toList();
assertTrue(filteredViolations.isEmpty());
}

Expand Down
1 change: 1 addition & 0 deletions web/src/test/resources/stubs/updateUserDto.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"email": "[email protected]",
"mobilePhone": "123456789",
"name": "string",
"surname": "string"
}

0 comments on commit 2e9dedd

Please sign in to comment.