Skip to content

Commit

Permalink
CCMSPUI-379 Updated ClientDetailRepository to filter by surname at bi…
Browse files Browse the repository at this point in the history
…rth instead of current surname to replicate SOA API

Signed-off-by: Jamie Briggs <jamie.briggs@digital.justice.gov.uk>
  • Loading branch information
Jamie Briggs committed Feb 17, 2025
1 parent 5b72708 commit 7d92361
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,32 +91,33 @@ void shouldReturnMultipleClientFilterLikeFirstName(){
}

@Test
@DisplayName("Should return single client filter equals surname")
void shouldReturnSingleClientFilterEqualsSurname(){
@DisplayName("Should return single client filter equals surname at birth")
void shouldReturnSingleClientFilterEqualsSurnameAtBirth(){
// Given
String surname = "doe";
String surname = "smithson";
// When
Page<ClientDetail> result = repository.findAll(null,
surname, null, null, null,
null, null, PageRequest.of(0, 10));
// Then
assertEquals(1L, result.getContent().size());
assertEquals("Doe", result.getContent().getFirst().getSurname());
assertEquals("Smithson", result.getContent().getFirst().getSurnameAtBirth());
}

@Test
@DisplayName("Should return mulitple clients filter like surname")
void shouldReturnMultipleClientsFilterLikeSurname(){
@DisplayName("Should return mulitple clients filter like surname at birth")
void shouldReturnMultipleClientsFilterLikeSurnameAtBirth(){
// Given
String surname = "oe";
String surname = "smith";
// When
Page<ClientDetail> result = repository.findAll(null,
surname, null, null, null,
null, null, PageRequest.of(0, 10));
// Then
assertEquals(2L, result.getContent().size());
assertEquals("Doe", result.getContent().getFirst().getSurname());
assertEquals("Roe", result.getContent().get(1).getSurname());
assertEquals("Smithson", result.getContent().getFirst().getSurnameAtBirth());
assertEquals("Smith", result.getContent().get(1).getSurnameAtBirth());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ INSERT INTO XXCCMS.XXCCMS_GET_CLIENT_DETAILS_V (CLIENT_REFERENCE_NUMBER, TITLE,
CORRESPONDENCE_LANGUAGE,
ETHNIC_MONITORING, NO_FIX_ABODE, NI_NUMBER,
HOME_OFFICE_NUMBER)
VALUES (100000000000001, 'Mr.', 'John', 'Doe', 'Smith',
VALUES (100000000000001, 'Mr.', 'John', 'Doe', 'Smithson',
TO_DATE('1985-06-15', 'YYYY-MM-DD'), 'Male', 'USA', 'Single',
'Email', 'None', 'English',
'Not Recorded', 'No', 'AB123456C', 'HO123456');
Expand All @@ -43,7 +43,7 @@ INSERT INTO XXCCMS.XXCCMS_GET_CLIENT_DETAILS_V (CLIENT_REFERENCE_NUMBER, TITLE,
CORRESPONDENCE_LANGUAGE,
ETHNIC_MONITORING, NO_FIX_ABODE, NI_NUMBER,
HOME_OFFICE_NUMBER)
VALUES (100000000000002, 'Ms.', 'Jane', 'Roe', 'Johnson',
VALUES (100000000000002, 'Ms.', 'Jane', 'Roe', 'Smith',
TO_DATE('1990-03-21', 'YYYY-MM-DD'), 'Female', 'CAN', 'Married',
'Phone', 'Visual Impairment', 'French',
'Caucasian', 'No', 'CD123654E', 'HO987654');
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ SELECT COUNT(*) FROM XXCCMS.XXCCMS_GET_CLIENT_DETAILS_V
return new PageImpl<>(resultList, pageable, total);
}

private static String getFilterSql(final String firstName, final String surname,
private static String getFilterSql(final String firstName, final String surnameAtBirth,
final LocalDate dateOfBirth, final String gender, final String clientReferenceNumber,
final String homeOfficeReference, final String nationalInsuranceNumber){
StringJoiner sj = new StringJoiner(" AND ");
Expand All @@ -68,9 +68,8 @@ private static String getFilterSql(final String firstName, final String surname,
sj.add("UPPER(FIRSTNAME) LIKE '%" + firstName.toUpperCase() + "%'");
}
// Surname (Fuzzy match, case-insensitive)
// TODO: Should this also be filtering rows using SURNAME_AT_BIRTH column?
if(stringNotEmpty(surname)){
sj.add("UPPER(SURNAME) LIKE '%" + surname.toUpperCase() + "%'");
if(stringNotEmpty(surnameAtBirth)){
sj.add("UPPER(SURNAME_AT_BIRTH) LIKE '%" + surnameAtBirth.toUpperCase() + "%'");
}
// Date of birth (Exact match)
if(!Objects.isNull(dateOfBirth)){
Expand Down

0 comments on commit 7d92361

Please sign in to comment.