Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SELC-6086] Feat: Added mobilePhone in updateUser API #497

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
2 changes: 2 additions & 0 deletions web/src/main/resources/swagger/swagger_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ swagger.dashboard.user.model.name=User's name
swagger.dashboard.user.model.surname=User's surname
swagger.dashboard.user.model.birthDate=User's birth date
swagger.dashboard.user.model.email=User's personal email
swagger.dashboard.user.model.phone=User's personal phone Number
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,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 +70,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 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"
}
Loading