Skip to content

Commit

Permalink
Validate port of entry for non-mainland UK addresses (#1537)
Browse files Browse the repository at this point in the history
* Allow empty postcode if non-mainland UK

* Use port of entry for addresses not in mainland UK

* Add test
  • Loading branch information
linusnorton authored Dec 11, 2024
1 parent d65b2b4 commit 1c8299d
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ && isNotBlank(callback.getCaseDetails().getCaseData().getAppeal().getBenefitType
callback.getCaseDetails().getCaseData().setDwpRegionalCentre(dwpRegionCentre);
}

String postcode = appealPostcodeHelper.resolvePostcode(appeal.getAppellant());
String processingVenue = sscsDataHelper.findProcessingVenue(postcode, appeal.getBenefitType());
String postCodeOrPort = appealPostcodeHelper.resolvePostCodeOrPort(appeal.getAppellant());
String processingVenue = sscsDataHelper.findProcessingVenue(postCodeOrPort, appeal.getBenefitType());

if (isNotBlank(processingVenue)) {
callback.getCaseDetails().getCaseData().setProcessingVenue(processingVenue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import uk.gov.hmcts.reform.sscs.ccd.domain.Address;
import uk.gov.hmcts.reform.sscs.ccd.domain.Appellant;
import uk.gov.hmcts.reform.sscs.ccd.domain.Appointee;
import uk.gov.hmcts.reform.sscs.ccd.domain.YesNo;
import uk.gov.hmcts.reform.sscs.validators.PostcodeValidator;

@Component
Expand All @@ -15,12 +16,16 @@ public class AppealPostcodeHelper {

private final PostcodeValidator postcodeValidator;

public String resolvePostcode(Appellant appellant) {
public String resolvePostCodeOrPort(Appellant appellant) {

if (appellant == null) {
if (appellant == null || appellant.getAddress() == null) {
return StringUtils.EMPTY;
}

if (YesNo.NO.equals(appellant.getAddress().getInMainlandUk())) {
return appellant.getAddress().getPortOfEntry() == null ? StringUtils.EMPTY : appellant.getAddress().getPortOfEntry();
}

return Optional.ofNullable(appellant.getAppointee())
.map(Appointee::getAddress)
.map(Address::getPostcode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ private Map<String, Object> transformData(String caseId,
transformed.put("bulkScanCaseReference", caseId);
transformed.put("caseCreated", scannedData.getOpeningDate());

String postcode = appealPostcodeHelper.resolvePostcode(appeal.getAppellant());
String processingVenue = sscsDataHelper.findProcessingVenue(postcode, appeal.getBenefitType());
String postCodeOrPort = appealPostcodeHelper.resolvePostCodeOrPort(appeal.getAppellant());
String processingVenue = sscsDataHelper.findProcessingVenue(postCodeOrPort, appeal.getBenefitType());
boolean isIbcCode = appeal.getBenefitType() != null && appeal.getBenefitType().getCode() != null && appeal.getBenefitType().getCode().equals(Benefit.INFECTED_BLOOD_COMPENSATION.getShortName());
boolean isIbcDescription = appeal.getBenefitType() != null && appeal.getBenefitType().getDescription() != null && appeal.getBenefitType().getDescription().equalsIgnoreCase(Benefit.INFECTED_BLOOD_COMPENSATION.getDescription());
RegionalProcessingCenter rpc = regionalProcessingCenterService.getByPostcode(postcode, isIbcCode || isIbcDescription);
RegionalProcessingCenter rpc = regionalProcessingCenterService.getByPostcode(postCodeOrPort, isIbcCode || isIbcDescription);

if (isNotBlank(processingVenue)) {
log.info("{} - setting venue name to {}", caseId, processingVenue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,9 @@ private void checkPersonAddressAndDob(Address address, Identity identity, String
if (isAddressPostcodeValid(address, personType, appellant) && address != null) {
if (personType.equals(getPerson1OrPerson2(appellant))) {
boolean isIbc = INFECTED_BLOOD_COMPENSATION.equals(benefitTypeCode);
RegionalProcessingCenter rpc = regionalProcessingCenterService.getByPostcode(address.getPostcode(), isIbc);
var postCodeOrPort = YesNo.NO.equals(address.getInMainlandUk()) ? address.getPortOfEntry() : address.getPostcode();

RegionalProcessingCenter rpc = regionalProcessingCenterService.getByPostcode(postCodeOrPort, isIbc);

if (rpc != null) {
caseData.put("region", rpc.getName());
Expand Down Expand Up @@ -588,6 +590,9 @@ private Boolean doesAddressCountyExist(Address address) {
}

private Boolean isAddressPostcodeValid(Address address, String personType, Appellant appellant) {
if (address != null && YesNo.NO.equals(address.getInMainlandUk())) {
return true;
}
if (address != null && address.getPostcode() != null) {
if (postcodeValidator.isValidPostcodeFormat(address.getPostcode())) {
boolean isValidPostcode = postcodeValidator.isValid(address.getPostcode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public void should_return_no_warnings_or_errors_or_data_when_validation_endpoint

CaseResponse caseValidationResponse = CaseResponse.builder().build();
when(caseValidator.validateValidationRecord(any(), anyBoolean())).thenReturn(caseValidationResponse);
when(appealPostcodeHelper.resolvePostcode(appeal.getAppellant())).thenReturn("CV35 2TD");
when(appealPostcodeHelper.resolvePostCodeOrPort(appeal.getAppellant())).thenReturn("CV35 2TD");

when(caseManagementLocationService.retrieveCaseManagementLocation(PROCESSING_VENUE, rpc)).thenReturn(
Optional.of(CaseManagementLocation.builder().baseLocation("rpcEpimsId").region(REGION_ID).build()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import uk.gov.hmcts.reform.sscs.ccd.domain.Address;
import uk.gov.hmcts.reform.sscs.ccd.domain.Appellant;
import uk.gov.hmcts.reform.sscs.ccd.domain.Appointee;
import uk.gov.hmcts.reform.sscs.ccd.domain.YesNo;
import uk.gov.hmcts.reform.sscs.validators.PostcodeValidator;

@RunWith(MockitoJUnitRunner.class)
Expand All @@ -37,11 +38,41 @@ public void shouldReturnAppointeePostcode_givenAppointeeAddressExists_andAppoint
.build())
.build();

String actualPostcode = appealPostcodeHelper.resolvePostcode(testAppellant);
String actualPostcode = appealPostcodeHelper.resolvePostCodeOrPort(testAppellant);

assertThat(actualPostcode).isEqualTo("CR2 8YY");
}

@Test
public void shouldReturnPortOfEntry_givenAppointeeNonMainlandUkAddress() {

Appellant testAppellant = Appellant.builder()
.address(Address.builder()
.inMainlandUk(YesNo.NO)
.portOfEntry("GB11111")
.build())
.build();

String actualPostcode = appealPostcodeHelper.resolvePostCodeOrPort(testAppellant);

assertThat(actualPostcode).isEqualTo("GB11111");
}

@Test
public void shouldReturnEmptyString_givenAppointeeNonMainlandWithNoPort() {

Appellant testAppellant = Appellant.builder()
.address(Address.builder()
.inMainlandUk(YesNo.NO)
.portOfEntry(null)
.build())
.build();

String actualPostcode = appealPostcodeHelper.resolvePostCodeOrPort(testAppellant);

assertThat(actualPostcode).isEqualTo("");
}

@Test
public void shouldReturnAppellantPostcode_givenInvalidAppointeePostcode_andAppellantPostcodeIsValid() {
when(postcodeValidator.isValid("TS3 6NM")).thenReturn(true);
Expand All @@ -57,7 +88,7 @@ public void shouldReturnAppellantPostcode_givenInvalidAppointeePostcode_andAppel
.build())
.build();

String actualPostcode = appealPostcodeHelper.resolvePostcode(testAppellant);
String actualPostcode = appealPostcodeHelper.resolvePostCodeOrPort(testAppellant);

assertThat(actualPostcode).isEqualTo("TS3 6NM");
}
Expand All @@ -73,7 +104,7 @@ public void shouldReturnAppellantPostcode_givenAppointeeAddressDoesNotExist_andA
.appointee(Appointee.builder().build())
.build();

String actualPostcode = appealPostcodeHelper.resolvePostcode(testAppellant);
String actualPostcode = appealPostcodeHelper.resolvePostCodeOrPort(testAppellant);

assertThat(actualPostcode).isEqualTo("TS3 6NM");
}
Expand All @@ -90,7 +121,7 @@ public void shouldReturnBlankPostcode_givenAppointeeAndAppellantPostcodeAreNotVa
.build())
.build();

String actualPostcode = appealPostcodeHelper.resolvePostcode(testAppellant);
String actualPostcode = appealPostcodeHelper.resolvePostCodeOrPort(testAppellant);

assertThat(actualPostcode).isEmpty();
}
Expand All @@ -104,7 +135,7 @@ public void shouldReturnBlankPostcode_givenAppointeeAndAppellantPostcodeDoNotExi
.build())
.build();

String actualPostcode = appealPostcodeHelper.resolvePostcode(testAppellant);
String actualPostcode = appealPostcodeHelper.resolvePostCodeOrPort(testAppellant);

assertThat(actualPostcode).isEmpty();
}
Expand All @@ -113,9 +144,9 @@ public void shouldReturnBlankPostcode_givenAppointeeAndAppellantPostcodeDoNotExi
public void shouldReturnBlankPostcode_givenAppointeeAndAppellantAddressDoNotExist() {
Appellant testAppellant = Appellant.builder().build();

String actualPostcode = appealPostcodeHelper.resolvePostcode(testAppellant);
String actualPostcode = appealPostcodeHelper.resolvePostCodeOrPort(testAppellant);

assertThat(actualPostcode).isEmpty();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2114,7 +2114,7 @@ public void setProcessingVenue_withGivingPriorityToAppointeeOverAppellant() {
.epimsId("rpcEpimsId").build();

when(regionalProcessingCenterService.getByPostcode(eq(APPOINTEE_POSTCODE), anyBoolean())).thenReturn(rpc);
when(appealPostcodeHelper.resolvePostcode(any())).thenReturn(APPOINTEE_POSTCODE);
when(appealPostcodeHelper.resolvePostCodeOrPort(any())).thenReturn(APPOINTEE_POSTCODE);
when(airLookupService.lookupAirVenueNameByPostCode(eq(APPOINTEE_POSTCODE), any(BenefitType.class))).thenReturn(PROCESSING_VENUE);
when(caseManagementLocationService.retrieveCaseManagementLocation(PROCESSING_VENUE, rpc)).thenReturn(
Optional.of(CaseManagementLocation.builder().baseLocation("rpcEpimsId").region(REGION_ID).build()));
Expand Down Expand Up @@ -2143,7 +2143,7 @@ public void setProcessingVenue_fromAppellantAddress() {

when(regionalProcessingCenterService.getByPostcode(APPELLANT_POSTCODE, false)).thenReturn(rpc);

when(appealPostcodeHelper.resolvePostcode(any())).thenReturn(APPELLANT_POSTCODE);
when(appealPostcodeHelper.resolvePostCodeOrPort(any())).thenReturn(APPELLANT_POSTCODE);
when(airLookupService.lookupAirVenueNameByPostCode(eq(APPELLANT_POSTCODE), any(BenefitType.class))).thenReturn(PROCESSING_VENUE);
when(caseManagementLocationService.retrieveCaseManagementLocation(PROCESSING_VENUE, rpc)).thenReturn(
Optional.of(CaseManagementLocation.builder().baseLocation("rpcEpimsId").region(REGION_ID).build()));
Expand Down Expand Up @@ -2173,7 +2173,7 @@ public void setProcessingVenue_isIbcCase() {

when(regionalProcessingCenterService.getByPostcode(APPELLANT_POSTCODE, true)).thenReturn(rpc);

when(appealPostcodeHelper.resolvePostcode(any())).thenReturn(APPELLANT_POSTCODE);
when(appealPostcodeHelper.resolvePostCodeOrPort(any())).thenReturn(APPELLANT_POSTCODE);
when(airLookupService.lookupAirVenueNameByPostCode(eq(APPELLANT_POSTCODE), any(BenefitType.class))).thenReturn(PROCESSING_VENUE);
when(caseManagementLocationService.retrieveCaseManagementLocation(PROCESSING_VENUE, rpc)).thenReturn(
Optional.of(CaseManagementLocation.builder().baseLocation("rpcEpimsId").region(REGION_ID).build()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static uk.gov.hmcts.reform.sscs.TestDataConstants.OTHER_PARTY_ADDRESS_LINE3;
import static uk.gov.hmcts.reform.sscs.TestDataConstants.OTHER_PARTY_POSTCODE;
import static uk.gov.hmcts.reform.sscs.ccd.domain.Benefit.*;
import static uk.gov.hmcts.reform.sscs.ccd.domain.Benefit.INFECTED_BLOOD_COMPENSATION;
import static uk.gov.hmcts.reform.sscs.constants.SscsConstants.*;

import java.util.*;
Expand Down Expand Up @@ -44,6 +45,7 @@ public class SscsCaseValidatorTest {

private static final String VALID_MOBILE = "07832882849";
private static final String VALID_POSTCODE = "CM13 0GD";
private static final String PORT_OF_NORWICH_A_FINE_CITY = "GBSTGTY00";
private final List<String> titles = new ArrayList<>();
private final Map<String, Object> ocrCaseData = new HashMap<>();
private final List<OcrDataField> ocrList = new ArrayList<>();
Expand Down Expand Up @@ -89,6 +91,9 @@ public void setup() {
given(regionalProcessingCenterService.getByPostcode(eq(VALID_POSTCODE), anyBoolean()))
.willReturn(RegionalProcessingCenter.builder().address1("Address 1").name("Liverpool").build());

given(regionalProcessingCenterService.getByPostcode(eq(PORT_OF_NORWICH_A_FINE_CITY), anyBoolean()))
.willReturn(RegionalProcessingCenter.builder().address1("Address 1").name("Bradford").build());

exceptionRecord = ExceptionRecord.builder().ocrDataFields(ocrList).formType(FormType.SSCS1PE.getId()).build();
given(sscsJsonExtractor.extractJson(exceptionRecord)).willReturn(scannedData);
given(scannedData.getOcrCaseData()).willReturn(ocrCaseData);
Expand Down Expand Up @@ -773,6 +778,21 @@ public void givenAnAppellantDoesNotContainAPostcode_thenAddAWarningAndDoNotAddRe
verifyNoInteractions(regionalProcessingCenterService);
}

@Test
public void givenAnAppellantDoesNotContainAPostcodeButNotInUk_thenLetItGoElsa() {
defaultMrnDetails.setDwpIssuingOffice("IBCA");
Appellant appellant = buildAppellant(false);
appellant.getAddress().setPostcode(null);
appellant.getAddress().setInMainlandUk(YesNo.NO);
appellant.getAddress().setPortOfEntry(PORT_OF_NORWICH_A_FINE_CITY);

var data = buildMinimumAppealDataWithBenefitType(INFECTED_BLOOD_COMPENSATION.getShortName(), appellant, true, FormType.SSCS5);
CaseResponse response = validator.validateExceptionRecord(transformResponse, exceptionRecord, data, false);

assertEquals(0, response.getWarnings().size());
verifyNoInteractions(regionalProcessingCenterService);
}

@Test
public void givenAnAppellantContainsPostcodeWithNoRegionalProcessingCenter_thenDoNotAddRegionalProcessingCenter() {
Appellant appellant = buildAppellant(false);
Expand Down Expand Up @@ -1238,7 +1258,7 @@ public void givenAnIbcAppealContainsAnValidPostcodeFormatButFound_thenNoErrorOrW
given(postcodeValidator.isValid(anyString())).willReturn(true);

given(regionalProcessingCenterService.getByPostcode(anyString(), eq(true))).willReturn(RegionalProcessingCenter.builder().address1("Address 1").name("Liverpool").build());
CaseResponse response = validator.validateExceptionRecord(transformResponse, exceptionRecord, buildMinimumAppealDataWithBenefitType(Benefit.INFECTED_BLOOD_COMPENSATION.getShortName(), buildAppellantWithPostcode("W1 1LA"), true, FormType.SSCS1PE), false);
CaseResponse response = validator.validateExceptionRecord(transformResponse, exceptionRecord, buildMinimumAppealDataWithBenefitType(INFECTED_BLOOD_COMPENSATION.getShortName(), buildAppellantWithPostcode("W1 1LA"), true, FormType.SSCS1PE), false);

assertThat(response.getWarnings().size()).isEqualTo(0);
assertThat(response.getErrors().size()).isEqualTo(0);
Expand Down

0 comments on commit 1c8299d

Please sign in to comment.