diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/cwrdapi/StaffRefDataAdvancedSearchFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/cwrdapi/StaffRefDataAdvancedSearchFunctionalTest.java index 7583b91d2..0b787ced3 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/cwrdapi/StaffRefDataAdvancedSearchFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/cwrdapi/StaffRefDataAdvancedSearchFunctionalTest.java @@ -21,6 +21,7 @@ import java.util.List; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static uk.gov.hmcts.reform.cwrdapi.TestSupport.validateSearchUserProfileResponse; import static uk.gov.hmcts.reform.cwrdapi.util.FeatureToggleConditionExtension.getToggledOffMessage; @@ -65,7 +66,7 @@ void should_return_staff_user_with_status_code_200_when_default_pagination() { .userType("1") .role("case allocator") .build(); - assertTrue(validateSearchUserProfileResponse(new ResponseEntity<>(searchStaffUserResponse,HttpStatus.OK), + assertNotNull(validateSearchUserProfileResponse(new ResponseEntity<>(searchStaffUserResponse,HttpStatus.OK), searchReq)); } diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/CreateStaffReferenceProfileBasicSearchTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/CreateStaffReferenceProfileBasicSearchTest.java index 6bf77a612..dadb9f254 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/CreateStaffReferenceProfileBasicSearchTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/CreateStaffReferenceProfileBasicSearchTest.java @@ -173,6 +173,38 @@ void should_return_staff_search_by_name_with_firstname_and_lastname_status_code_ assertThat(searchStaffUserResponse.get(0).getLastName()).contains("sbn-David"); } + @Test + void should_return_staff_search_by_name_with_firstname_and_lastname_with_phonetics_status_code_200() { + + generateCaseWorkerDataPhoneticAndSpecial(); + String searchString = "sbn-Æquen"; + List searchStaffUserResponse = searchApiCallAndCommonAssertions(searchString); + assertThat(searchStaffUserResponse.get(0).getFirstName()).contains("sbn-Æquen"); + assertThat(searchStaffUserResponse.get(0).getLastName()).contains("sbn-Ïndîkä"); + } + + @Test + void should_return_staff_search_by_name_with_firstname_and_lastname_with_roman_status_code_200() { + + generateCaseWorkerDataPhoneticAndSpecial(); + String searchString = "sbn-IVXIIV"; + + List searchStaffUserResponse = searchApiCallAndCommonAssertions(searchString); + assertThat(searchStaffUserResponse.get(0).getFirstName()).contains("sbn-IVXIIV"); + assertThat(searchStaffUserResponse.get(0).getLastName()).contains("sbn-IV-XIIV’"); + } + + @Test + void should_return_staff_search_by_name_with_firstname_and_lastname_with_specialCharacters_status_code_200() { + + generateCaseWorkerDataPhoneticAndSpecial(); + String searchString = "sbn-IV-XIIV’"; + List searchStaffUserResponse = searchApiCallAndCommonAssertions(searchString); + + assertThat(searchStaffUserResponse.get(0).getFirstName()).contains("sbn-IVXIIV"); + assertThat(searchStaffUserResponse.get(0).getLastName()).contains("sbn-IV-XIIV’"); + } + @Test void should_return_staff_search_by_firstname_and_lastname_initial_status_code_200() { @@ -292,7 +324,7 @@ void should_return_status_code_400_when_search_String_is_not_valid() assertThat(response).containsEntry("http_status", "400"); assertThat(response.get("response_body").toString()) - .contains("Invalid search string. Please input a valid string."); + .contains("The field Page Size is invalid. Please provide a valid value."); } @@ -326,6 +358,23 @@ void should_return_status_code_400_when_search_String_empty() } + private List searchApiCallAndCommonAssertions(String searchString) { + String path = "/profile/search-by-name"; + CaseWorkerReferenceDataClient.setBearerToken(EMPTY); + ResponseEntity response = caseworkerReferenceDataClient + .searchStaffUserByNameExchange(path, searchString, null, null, ROLE_STAFF_ADMIN); + + assertThat(response).isNotNull(); + + assertThat(Integer.valueOf(response.getHeaders().get("total-records").get(0))).isEqualTo(1); + + List searchStaffUserResponse = Arrays.asList( + response.getBody()); + + assertThat(searchStaffUserResponse).isNotNull(); + return searchStaffUserResponse; + } + private void generateCaseWorkerData() { String emailPattern = "sbnTest1234"; String email = format(EMAIL_TEMPLATE, randomAlphanumeric(10) + emailPattern).toLowerCase(); @@ -342,6 +391,15 @@ private void generateCaseWorkerData() { createCaseWorkerTestData("sbn-Mary", "sbn-David", email); } + private void generateCaseWorkerDataPhoneticAndSpecial() { + String emailPattern = "sbnTest1234"; + String email = format(EMAIL_TEMPLATE, randomAlphanumeric(10) + emailPattern).toLowerCase(); + email = format(EMAIL_TEMPLATE, randomAlphanumeric(10) + emailPattern).toLowerCase(); + createCaseWorkerTestData("sbn-Æquen", "sbn-Ïndîkä", email); + email = format(EMAIL_TEMPLATE, randomAlphanumeric(10) + emailPattern).toLowerCase(); + createCaseWorkerTestData("sbn-IVXIIV", "sbn-IV-XIIV’", email); + } + private void validateSearchStaffUserResponse(List searchStaffUserResponse) { assertThat(searchStaffUserResponse.get(0).getFirstName()).contains("sbn-Mary"); diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/CreateStaffReferenceProfileIntegrationTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/CreateStaffReferenceProfileIntegrationTest.java index b4bc0c1ae..17730834e 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/CreateStaffReferenceProfileIntegrationTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/CreateStaffReferenceProfileIntegrationTest.java @@ -10,6 +10,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.skyscreamer.jsonassert.JSONAssert; import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.beans.factory.annotation.Autowired; @@ -30,6 +33,7 @@ import java.util.List; import java.util.Map; +import java.util.stream.Stream; import static org.apache.logging.log4j.util.Strings.EMPTY; import static org.assertj.core.api.Assertions.assertThat; @@ -96,7 +100,7 @@ void should_return_staff_user_with_status_code_201() { userProfilePostUserWireMockForStaffProfile(HttpStatus.CREATED); StaffProfileCreationRequest request = caseWorkerReferenceDataClient.createStaffProfileCreationRequest(); - Map response = caseworkerReferenceDataClient.createStaffProfile(request,ROLE_STAFF_ADMIN); + Map response = caseworkerReferenceDataClient.createStaffProfile(request, ROLE_STAFF_ADMIN); assertThat(response) .isNotNull() @@ -105,6 +109,64 @@ void should_return_staff_user_with_status_code_201() { assertThat(response.get("case_worker_id")).isNotNull(); } + + @ParameterizedTest(name = "{index} => firstName={0}, lastName={1}") + @MethodSource("validNameProvider") + @DisplayName("Create Staff profile with valid names status 201") + void should_return_staff_user_with_valid_name_status_code_201(String firstName, String lastName) { + CaseWorkerReferenceDataClient.setBearerToken(EMPTY); + userProfilePostUserWireMockForStaffProfile(HttpStatus.CREATED); + StaffProfileCreationRequest request = + caseWorkerReferenceDataClient.buildStaffProfileCreationRequest(firstName, lastName); + + Map response = caseworkerReferenceDataClient.createStaffProfile(request, ROLE_STAFF_ADMIN); + + assertThat(response) + .isNotNull() + .containsEntry("http_status", "201 CREATED"); + + assertThat(response.get("case_worker_id")).isNotNull(); + } + + + @ParameterizedTest(name = "{index} => firstName={0}, lastName={1}") + @MethodSource("inValidNameProvider") + @DisplayName("Create Staff profile with invalid names status 400") + void should_return_staff_user_with_invalid_name_status_code_400(String firstName, String lastName) { + CaseWorkerReferenceDataClient.setBearerToken(EMPTY); + userProfilePostUserWireMockForStaffProfile(HttpStatus.CREATED); + StaffProfileCreationRequest request = + caseWorkerReferenceDataClient.buildStaffProfileCreationRequest(firstName, lastName); + + Map response = caseworkerReferenceDataClient.createStaffProfile(request, ROLE_STAFF_ADMIN); + + assertThat(response) + .isNotNull() + .containsEntry("http_status", "400"); + + assertThat(response.get("case_worker_id")).isNull(); + } + + private static Stream validNameProvider() { + return Stream.of( + Arguments.of("Vilas", "Shelke"),//normal + Arguments.of("Vilas1234", "Sh456"),//numeric + Arguments.of("IIIIVVI", "XIII"),//Roman + Arguments.of("Nando's", "Zi-n ac"),//Space, and Special characters - ' + Arguments.of("Æâçdëøœoo", "Qętŷįłgå12"),//Space, and Special characters - ' + Arguments.of("Æmaze", "Zìœ")//phonetic + ); + } + + private static Stream inValidNameProvider() { + return Stream.of( + Arguments.of("Vilas&", "She_lke"),//invalid special characters & _ + Arguments.of("Vilas1234", "Sh+456"),//valid first name and invalid last name + Arguments.of("Nando*s", "Zi-n ac"),//valid last name and valid last name + Arguments.of("??%%/", "()*&^)")//invalid special characters + ); + } + @Test @DisplayName("Create Staff profile with status 201 with child tables entries") void should_return_staff_user_with_status_code_201_child_tables_size() { @@ -113,7 +175,7 @@ void should_return_staff_user_with_status_code_201_child_tables_size() { StaffProfileCreationRequest request = caseWorkerReferenceDataClient.createStaffProfileCreationRequest(); Map response = caseworkerReferenceDataClient - .createStaffProfile(request,ROLE_STAFF_ADMIN); + .createStaffProfile(request, ROLE_STAFF_ADMIN); assertThat(response) .isNotNull() @@ -135,7 +197,7 @@ void validate_staff_audit_data() throws JsonProcessingException, JSONException { StaffProfileCreationRequest request = caseWorkerReferenceDataClient.createStaffProfileCreationRequest(); Map response = caseworkerReferenceDataClient - .createStaffProfile(request,ROLE_STAFF_ADMIN); + .createStaffProfile(request, ROLE_STAFF_ADMIN); assertThat(response) .isNotNull() @@ -173,9 +235,9 @@ void should_return_create_staff_user_with_status_code_400_invalid_email_id() thr Map response = caseworkerReferenceDataClient - .createStaffProfile(request,ROLE_STAFF_ADMIN); + .createStaffProfile(request, ROLE_STAFF_ADMIN); - assertThat(response).containsEntry("http_status","400"); + assertThat(response).containsEntry("http_status", "400"); String responseBody = (String) response.get("response_body"); assertThat(responseBody).contains(INVALID_EMAIL); @@ -222,12 +284,12 @@ void should_return_create_staff_user_with_status_code_400_invalid_primary_locati StaffProfileCreationRequest request = caseWorkerReferenceDataClient.createStaffProfileCreationRequest(); - request.setBaseLocations(List.of(caseWorkerLocationRequest,caseWorkerLocationRequest2)); + request.setBaseLocations(List.of(caseWorkerLocationRequest, caseWorkerLocationRequest2)); Map response = caseworkerReferenceDataClient - .createStaffProfile(request,ROLE_STAFF_ADMIN); + .createStaffProfile(request, ROLE_STAFF_ADMIN); - assertThat(response).containsEntry("http_status","400"); + assertThat(response).containsEntry("http_status", "400"); String responseBody = (String) response.get("response_body"); assertThat(responseBody).contains(NO_PRIMARY_LOCATION_PRESENT_PROFILE); @@ -275,13 +337,13 @@ void should_return_create_staff_user_with_status_code_400_duplicate_service_code .build(); StaffProfileCreationRequest request = caseWorkerReferenceDataClient.createStaffProfileCreationRequest(); - request.setServices(List.of(caseWorkerServicesRequest,caseWorkerServicesRequest2)); + request.setServices(List.of(caseWorkerServicesRequest, caseWorkerServicesRequest2)); Map response = caseworkerReferenceDataClient - .createStaffProfile(request,ROLE_STAFF_ADMIN); + .createStaffProfile(request, ROLE_STAFF_ADMIN); - assertThat(response).containsEntry("http_status","400"); + assertThat(response).containsEntry("http_status", "400"); String responseBody = (String) response.get("response_body"); assertThat(responseBody).contains(DUPLICATE_SERVICE_CODE_IN_AREA_OF_WORK); @@ -322,13 +384,13 @@ void should_return_create_staff_user_with_status_code_400_duplicate_roles() thro StaffProfileCreationRequest request = caseWorkerReferenceDataClient.createStaffProfileCreationRequest(); - request.setRoles(List.of(staffProfileRoleRequest1,staffProfileRoleRequest2)); + request.setRoles(List.of(staffProfileRoleRequest1, staffProfileRoleRequest2)); Map response = caseworkerReferenceDataClient - .createStaffProfile(request,ROLE_STAFF_ADMIN); + .createStaffProfile(request, ROLE_STAFF_ADMIN); - assertThat(response).containsEntry("http_status","400"); + assertThat(response).containsEntry("http_status", "400"); String responseBody = (String) response.get("response_body"); assertThat(responseBody).contains(DUPLICATE_PRIMARY_AND_SECONDARY_ROLES); @@ -366,12 +428,12 @@ void should_return_create_staff_user_with_status_code_400_invalid_roles() throws new StaffProfileRoleRequest(1, "adminRole", false); StaffProfileCreationRequest request = caseWorkerReferenceDataClient.createStaffProfileCreationRequest(); - request.setRoles(List.of(staffProfileRoleRequest1,staffProfileRoleRequest2)); + request.setRoles(List.of(staffProfileRoleRequest1, staffProfileRoleRequest2)); Map response = caseworkerReferenceDataClient - .createStaffProfile(request,ROLE_STAFF_ADMIN); + .createStaffProfile(request, ROLE_STAFF_ADMIN); - assertThat(response).containsEntry("http_status","400"); + assertThat(response).containsEntry("http_status", "400"); String responseBody = (String) response.get("response_body"); assertThat(responseBody).contains(NO_PRIMARY_ROLE_PRESENT_PROFILE); diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/util/CaseWorkerReferenceDataClient.java b/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/util/CaseWorkerReferenceDataClient.java index b339bb59e..7ab24d85f 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/util/CaseWorkerReferenceDataClient.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/util/CaseWorkerReferenceDataClient.java @@ -593,44 +593,17 @@ public Map createStaffProfile(StaffProfileCreationRequest reques public StaffProfileCreationRequest createStaffProfileCreationRequest() { + return buildStaffProfileCreationRequest("StaffProfilefirstName", "StaffProfilelastName"); + } + public StaffProfileCreationRequest buildStaffProfileCreationRequest(String firstName, String lastName) { String emailPattern = "deleteTest1234"; String email = format(STAFF_EMAIL_TEMPLATE, RandomStringUtils.randomAlphanumeric(10) + emailPattern).toLowerCase(); - - List caseWorkerRoleRequests = - ImmutableList.of(StaffProfileRoleRequest.staffProfileRoleRequest() - .roleId(2) - .role("Legal Caseworker") - .isPrimaryFlag(true).build()); - - List caseWorkerLocationRequests = ImmutableList.of(CaseWorkerLocationRequest - .caseWorkersLocationRequest() - .isPrimaryFlag(true).locationId(12345) - .location("test location").build(), CaseWorkerLocationRequest - .caseWorkersLocationRequest() - .isPrimaryFlag(true).locationId(6789) - .location("test location2").build()); - - List caseWorkerServicesRequests = ImmutableList.of(CaseWorkerServicesRequest - .caseWorkerServicesRequest() - .service("Immigration and Asylum Appeals").serviceCode("serviceCode2") - .build(), CaseWorkerServicesRequest - .caseWorkerServicesRequest() - .service("Divorce").serviceCode("ABA1") - .build()); - - List skillsRequest = ImmutableList.of(SkillsRequest - .skillsRequest() - .skillId(9) - .skillCode("1") - .description("testskill1") - .build()); - return StaffProfileCreationRequest .staffProfileCreationRequest() - .firstName("StaffProfilefirstName") - .lastName("StaffProfilelastName") + .firstName(firstName) + .lastName(lastName) .emailId(email) .regionId(1).userType("CTSC") .region("National") @@ -638,20 +611,56 @@ public StaffProfileCreationRequest createStaffProfileCreationRequest() { .taskSupervisor(true) .caseAllocator(true) .staffAdmin(false) - .roles(caseWorkerRoleRequests) - .baseLocations(caseWorkerLocationRequests) - .services(caseWorkerServicesRequests) - .skills(skillsRequest) + .roles(getCaseWorkerRoleRequests()) + .baseLocations(getCaseWorkerLocationRequests()) + .services(getCaseWorkerServicesRequests()) + .skills(getSkillsRequest()) .build(); } + private List getSkillsRequest() { + return ImmutableList.of(SkillsRequest + .skillsRequest() + .skillId(9) + .skillCode("1") + .description("testskill1") + .build()); + } + + private List getCaseWorkerServicesRequests() { + return ImmutableList.of(CaseWorkerServicesRequest + .caseWorkerServicesRequest() + .service("Immigration and Asylum Appeals").serviceCode("serviceCode2") + .build(), CaseWorkerServicesRequest + .caseWorkerServicesRequest() + .service("Divorce").serviceCode("ABA1") + .build()); + } + + private List getCaseWorkerLocationRequests() { + return ImmutableList.of(CaseWorkerLocationRequest + .caseWorkersLocationRequest() + .isPrimaryFlag(true).locationId(12345) + .location("test location").build(), CaseWorkerLocationRequest + .caseWorkersLocationRequest() + .isPrimaryFlag(true).locationId(6789) + .location("test location2").build()); + } + + private List getCaseWorkerRoleRequests() { + return ImmutableList.of(StaffProfileRoleRequest.staffProfileRoleRequest() + .roleId(2) + .role("Legal Caseworker") + .isPrimaryFlag(true).build()); + } + public Map updateStaffProfile(StaffProfileCreationRequest request, String role) { return putRequest(baseUrl + "/profile", request, role, null); } public Object fetchStaffUserById(Class clazz, - String userId, String role) throws JsonProcessingException { + String userId, String role) throws JsonProcessingException { ResponseEntity responseEntity = getRequest(userId, clazz, role); - return mapServiceSkillsIdResponse(responseEntity, clazz); + return mapServiceSkillsIdResponse(responseEntity, clazz); } } diff --git a/src/main/java/uk/gov/hmcts/reform/cwrdapi/util/CaseWorkerConstants.java b/src/main/java/uk/gov/hmcts/reform/cwrdapi/util/CaseWorkerConstants.java index 16856146a..5a1d7879d 100644 --- a/src/main/java/uk/gov/hmcts/reform/cwrdapi/util/CaseWorkerConstants.java +++ b/src/main/java/uk/gov/hmcts/reform/cwrdapi/util/CaseWorkerConstants.java @@ -118,7 +118,9 @@ private CaseWorkerConstants() { + " empty space, ', - characters and must be less than 128 characters"; public static final String LAST_NAME_INVALID = "Last Name is invalid - can only contain Alphabetic," + " empty space, ', - characters and must be less than 128 characters"; - public static final String NAME_REGEX = "^[a-zA-Z' .-]{1,127}$"; + + public static final String COMMON_NAME_AND_SEARCH_REGEX = "^[(a-zA-Z0-9 )\\p{L}\\p{N}'’-]"; + public static final String NAME_REGEX = COMMON_NAME_AND_SEARCH_REGEX + "{1,127}$"; public static final String MISSING_REGION = "You must add a region and upload the file again"; public static final String NO_USER_TO_SUSPEND = "There is no user present for row id %s to suspend. " @@ -181,7 +183,7 @@ private CaseWorkerConstants() { public static final String CW_LAST_NAME = "lastName"; - public static final String SEARCH_STRING_REGEX_PATTERN = "([a-zA-Z\\-\\s']){3,}+"; + public static final String SEARCH_STRING_REGEX_PATTERN = COMMON_NAME_AND_SEARCH_REGEX + "{3,}"; public static final String REG_EXP_SPCL_CHAR = "^[^<>{}\"/|;:.~!?@#$%^=&*\\]\\\\()\\[¿§«»ω⊙¤°℃℉€¥£¢¡®©+]*$"; diff --git a/src/test/java/uk/gov/hmcts/reform/cwrdapi/controllers/StaffRefDataControllerTest.java b/src/test/java/uk/gov/hmcts/reform/cwrdapi/controllers/StaffRefDataControllerTest.java index 612c185be..73af9f0bb 100644 --- a/src/test/java/uk/gov/hmcts/reform/cwrdapi/controllers/StaffRefDataControllerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/cwrdapi/controllers/StaffRefDataControllerTest.java @@ -790,7 +790,9 @@ void shouldFetchEmptyJobTitles() { } @ParameterizedTest - @ValueSource(strings = {"firstname", "lastname", "firstname lastname", "f l", "name"}) + @ValueSource(strings = {"firstname", "lastname", "firstname lastname", "f l", "name", + "Ab 123", "I II III IV V VI VII VIII IX X", "VïlæŚ Śhëłkę", "Æñdrèw", "àáâäæãåā", "Ęéëį", + "a'b-’"}) void should_return_staff_search_by_name_with_search_string_status_code_200(String searchString) { ResponseEntity> searchStaffUserResponseEntity = @@ -806,7 +808,7 @@ void should_return_staff_search_by_name_with_search_string_status_code_200(Strin } @ParameterizedTest - @ValueSource(strings = {"", "ab", "ab*", "ab123", "a ", " ", " s ", " ab ", "&ab ", " "}) + @ValueSource(strings = {"", "ab", "ab*", "a ", " ", " s ", " ab ", " "}) void should_return_staff_search_by_name_with_invalid_search_string_status_code_400(String searchString) { Exception ex = assertThrows(InvalidRequestException.class, () -> staffRefDataController diff --git a/src/test/java/uk/gov/hmcts/reform/cwrdapi/service/impl/JsrValidatorStaffProfileTest.java b/src/test/java/uk/gov/hmcts/reform/cwrdapi/service/impl/JsrValidatorStaffProfileTest.java index 262934a8f..2d5104212 100644 --- a/src/test/java/uk/gov/hmcts/reform/cwrdapi/service/impl/JsrValidatorStaffProfileTest.java +++ b/src/test/java/uk/gov/hmcts/reform/cwrdapi/service/impl/JsrValidatorStaffProfileTest.java @@ -57,7 +57,7 @@ void init() { } @ParameterizedTest - @ValueSource(strings = {"", "abc.com","test.gov","user@gmail.com"}) + @ValueSource(strings = {"", "abc.com", "test.gov", "user@gmail.com"}) void testValidateStaffProfileEmail(String email) { StaffProfileCreationRequest profile = buildStaffProfileRequest(); profile.setEmailId(email); @@ -65,38 +65,64 @@ void testValidateStaffProfileEmail(String email) { when(staffAuditRepository.save(any())).thenReturn(staffAudit.builder().id(1L).build()); InvalidRequestException exception = Assertions.assertThrows(InvalidRequestException.class, () -> - jsrValidatorStaffProfile.validateStaffProfile(profile,STAFF_PROFILE_CREATE)); + jsrValidatorStaffProfile.validateStaffProfile(profile, STAFF_PROFILE_CREATE)); assertThat(exception.getMessage()).contains(INVALID_EMAIL); } - @Test + @ParameterizedTest + @ValueSource(strings = {"123.name", "name&", "vilas_shelke", "vilas.:\"_shelke", "*()"}) @DisplayName("staff profile invalid first name") - void testValidateStaffProfileInvalidFirstName() { + void testValidateStaffProfileInvalidFirstName(String name) { StaffProfileCreationRequest profile = buildStaffProfileRequest(); - profile.setFirstName("123name"); + profile.setFirstName(name); when(jwtGrantedAuthoritiesConverter.getUserInfo()).thenReturn(UserInfo.builder().name("test").build()); when(staffAuditRepository.save(any())).thenReturn(staffAudit.builder().id(1L).build()); InvalidRequestException exception = Assertions.assertThrows(InvalidRequestException.class, () -> - jsrValidatorStaffProfile.validateStaffProfile(profile,STAFF_PROFILE_CREATE)); + jsrValidatorStaffProfile.validateStaffProfile(profile, STAFF_PROFILE_CREATE)); assertThat(exception.getMessage()).contains(FIRST_NAME_INVALID); } - @Test + @ParameterizedTest + @ValueSource(strings = {"123.name", "name&", "vilas_shelke", "vilas.:\"_shelke", "*()"}) @DisplayName("staff profile invalid last name") - void testValidateStaffProfileInvalidLastName() { + void testValidateStaffProfileInvalidLastName(String name) { StaffProfileCreationRequest profile = buildStaffProfileRequest(); - profile.setLastName("123name"); + profile.setLastName(name); when(jwtGrantedAuthoritiesConverter.getUserInfo()).thenReturn(UserInfo.builder().name("test").build()); when(staffAuditRepository.save(any())).thenReturn(staffAudit.builder().id(1L).build()); InvalidRequestException lastNameException = Assertions.assertThrows(InvalidRequestException.class, () -> - jsrValidatorStaffProfile.validateStaffProfile(profile,STAFF_PROFILE_CREATE)); + jsrValidatorStaffProfile.validateStaffProfile(profile, STAFF_PROFILE_CREATE)); Assertions.assertNotNull(lastNameException.getLocalizedMessage()); assertThat(lastNameException.getMessage()).contains(LAST_NAME_INVALID); } + @ParameterizedTest + @ValueSource(strings = {"123name", "IIIIVVI", "vilas-shelke", "Nando's", "Æâçdëøœoo", "Æmaze"}) + @DisplayName("staff profile valid first name") + void testValidateStaffProfileValidFirstName(String name) { + StaffProfileCreationRequest profile = buildStaffProfileRequest(); + profile.setFirstName(name); + when(jwtGrantedAuthoritiesConverter.getUserInfo()).thenReturn(UserInfo.builder().name("test").build()); + when(staffAuditRepository.save(any())).thenReturn(staffAudit.builder().id(1L).build()); + jsrValidatorStaffProfile.validateStaffProfile(profile, STAFF_PROFILE_CREATE); + verify(staffAuditRepository, times(0)).save(any()); + } + + @ParameterizedTest + @ValueSource(strings = {"123name", "IIIIVVI", "vilas-shelke", "Nando's", "Æâçdëøœoo", "Æmaze"}) + @DisplayName("staff profile valid last name") + void testValidateStaffProfileValidLastName(String name) { + StaffProfileCreationRequest profile = buildStaffProfileRequest(); + profile.setLastName(name); + when(jwtGrantedAuthoritiesConverter.getUserInfo()).thenReturn(UserInfo.builder().name("test").build()); + when(staffAuditRepository.save(any())).thenReturn(staffAudit.builder().id(1L).build()); + jsrValidatorStaffProfile.validateStaffProfile(profile, STAFF_PROFILE_CREATE); + verify(staffAuditRepository, times(0)).save(any()); + } + @Test @DisplayName("staff profile missing region") void testValidateStaffProfileMissingServices() { @@ -106,7 +132,7 @@ void testValidateStaffProfileMissingServices() { when(staffAuditRepository.save(any())).thenReturn(staffAudit.builder().id(1L).build()); InvalidRequestException lastNameException = Assertions.assertThrows(InvalidRequestException.class, () -> - jsrValidatorStaffProfile.validateStaffProfile(profile,STAFF_PROFILE_CREATE)); + jsrValidatorStaffProfile.validateStaffProfile(profile, STAFF_PROFILE_CREATE)); Assertions.assertNotNull(lastNameException.getLocalizedMessage()); assertThat(lastNameException.getMessage()).contains(MISSING_REGION_PROFILE); } @@ -119,7 +145,7 @@ void testValidateStaffProfileEmptyRequest() { when(staffAuditRepository.save(any())).thenReturn(staffAudit.builder().id(1L).build()); InvalidRequestException exception = Assertions.assertThrows(InvalidRequestException.class, () -> - jsrValidatorStaffProfile.validateStaffProfile(profile,STAFF_PROFILE_CREATE)); + jsrValidatorStaffProfile.validateStaffProfile(profile, STAFF_PROFILE_CREATE)); Assertions.assertNotNull(exception.getLocalizedMessage()); } @@ -130,7 +156,7 @@ void testValidateStaffProfileNoViolations() { StaffProfileCreationRequest profile = buildStaffProfileRequest(); when(jwtGrantedAuthoritiesConverter.getUserInfo()).thenReturn(UserInfo.builder().name("test").build()); when(staffAuditRepository.save(any())).thenReturn(staffAudit.builder().id(1L).build()); - jsrValidatorStaffProfile.validateStaffProfile(profile,STAFF_PROFILE_CREATE); + jsrValidatorStaffProfile.validateStaffProfile(profile, STAFF_PROFILE_CREATE); verify(staffAuditRepository, times(0)).save(any()); } } diff --git a/src/test/java/uk/gov/hmcts/reform/cwrdapi/util/RequestUtilsTest.java b/src/test/java/uk/gov/hmcts/reform/cwrdapi/util/RequestUtilsTest.java index f5155045a..f4fc2e5f2 100644 --- a/src/test/java/uk/gov/hmcts/reform/cwrdapi/util/RequestUtilsTest.java +++ b/src/test/java/uk/gov/hmcts/reform/cwrdapi/util/RequestUtilsTest.java @@ -136,7 +136,7 @@ void testInvalidRequestExceptionForValidateSearchStringEmpty() { @Test void testInvalidRequestExceptionForValidateSearchStringNotValid() { Assertions.assertThrows(InvalidRequestException.class, () -> - validateSearchString("abcd123") + validateSearchString("abcd123*?") ); }