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

DFR-2980-Mandatory-Postcode-Field #1756

Merged
merged 17 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.gov.hmcts.reform.finrem.caseorchestration.handler;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.reform.finrem.caseorchestration.ccd.callback.CallbackType;
import uk.gov.hmcts.reform.finrem.caseorchestration.controllers.GenericAboutToStartOrSubmitCallbackResponse;
Expand All @@ -9,14 +10,24 @@
import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CaseType;
import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.FinremCaseData;
import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.FinremCaseDetails;
import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.wrapper.ContactDetailsWrapper;
import uk.gov.hmcts.reform.finrem.caseorchestration.service.InternationalPostalService;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Slf4j
@Service
public class UpdateContactDetailsContestedMidHandler extends FinremCallbackHandler {

private final InternationalPostalService postalService;

private static final String APPLICANT_POSTCODE_ERROR = "Postcode field is required for applicant address.";
private static final String RESPONDENT_POSTCODE_ERROR = "Postcode field is required for respondent address.";
private static final String APPLICANT_SOLICITOR_POSTCODE_ERROR = "Postcode field is required for applicant solicitor address.";
private static final String RESPONDENT_SOLICITOR_POSTCODE_ERROR = "Postcode field is required for respondent solicitor address.";

public UpdateContactDetailsContestedMidHandler(FinremCaseDetailsMapper finremCaseDetailsMapper,
InternationalPostalService postalService) {
super(finremCaseDetailsMapper);
Expand All @@ -38,7 +49,48 @@ public GenericAboutToStartOrSubmitCallbackResponse<FinremCaseData> handle(Finrem
caseDetails.getId());

FinremCaseData caseData = caseDetails.getData();
List<String> errors = new ArrayList<>();
errors.addAll(postalService.validate(caseData));
errors.addAll(validateCaseData(caseData));
return GenericAboutToStartOrSubmitCallbackResponse.<FinremCaseData>builder()
.data(caseData).errors(postalService.validate(caseData)).build();
.data(caseData).errors(errors).build();
}

private List<String> validateCaseData(FinremCaseData caseData) {

List<String> errors = new ArrayList<>();
ContactDetailsWrapper wrapper = caseData.getContactDetailsWrapper();

if (caseData.isApplicantRepresentedByASolicitor()
&& Optional.ofNullable(wrapper.getApplicantSolicitorAddress())
.map(address -> ObjectUtils.isEmpty(address.getPostCode()))
.orElse(false)) {
errors.add(APPLICANT_SOLICITOR_POSTCODE_ERROR);
return errors;
}

if (Optional.ofNullable(wrapper.getApplicantAddress())
.map(address -> ObjectUtils.isEmpty(address.getPostCode()))
.orElse(false)) {
errors.add(APPLICANT_POSTCODE_ERROR);
return errors;
}

if (caseData.isRespondentRepresentedByASolicitor()
&& Optional.ofNullable(wrapper.getRespondentSolicitorAddress())
.map(address -> ObjectUtils.isEmpty(address.getPostCode()))
.orElse(false)) {
errors.add(RESPONDENT_SOLICITOR_POSTCODE_ERROR);
return errors;
}

if (Optional.ofNullable(wrapper.getRespondentAddress())
.map(address -> ObjectUtils.isEmpty(address.getPostCode()))
.orElse(false)) {
errors.add(RESPONDENT_POSTCODE_ERROR);
return errors;
}

return errors;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import uk.gov.hmcts.reform.finrem.caseorchestration.ccd.callback.CallbackType;
import uk.gov.hmcts.reform.finrem.caseorchestration.controllers.GenericAboutToStartOrSubmitCallbackResponse;
import uk.gov.hmcts.reform.finrem.caseorchestration.model.EventType;
import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.Address;
import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CaseType;
import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.FinremCaseData;
import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.FinremCaseDetails;
import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.YesOrNo;
import uk.gov.hmcts.reform.finrem.caseorchestration.service.InternationalPostalService;

import java.util.stream.Stream;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.verify;
import static uk.gov.hmcts.reform.finrem.caseorchestration.ccd.callback.CallbackType.MID_EVENT;
import static uk.gov.hmcts.reform.finrem.caseorchestration.ccd.callback.CallbackType.SUBMITTED;
Expand Down Expand Up @@ -65,4 +70,190 @@ private FinremCallbackRequest buildCallbackRequest() {
.data(FinremCaseData.builder().ccdCaseType(CONTESTED).build()).build())
.build();
}
}

@Test
void givenContestedCase_WhenNotEmptyPostCode_thenHandlerWillShowNoErrorMessage() {

FinremCallbackRequest finremCallbackRequest = buildCallbackRequest();
FinremCaseDetails caseDetails = finremCallbackRequest.getCaseDetails();
FinremCaseData data = caseDetails.getData();

Address address = new Address();
address.setPostCode("AB1 1AB");
data.getContactDetailsWrapper().setApplicantAddress(address);
data.getContactDetailsWrapper().setRespondentAddress(address);
data.getContactDetailsWrapper().setApplicantRepresented(YesOrNo.NO);
data.getContactDetailsWrapper().setContestedRespondentRepresented(YesOrNo.NO);

GenericAboutToStartOrSubmitCallbackResponse<FinremCaseData> handle = handler.handle(finremCallbackRequest, AUTH_TOKEN);
assertEquals(0, handle.getErrors().size());
}

dawudgovuk marked this conversation as resolved.
Show resolved Hide resolved
@Test
void givenConsentedCase_WhenEmptyApplicantPostCode_thenHandlerWillShowMessage() {

FinremCallbackRequest finremCallbackRequest = buildCallbackRequest();
FinremCaseDetails caseDetails = finremCallbackRequest.getCaseDetails();
FinremCaseData data = caseDetails.getData();

Address address = new Address();
address.setPostCode("");
data.getContactDetailsWrapper().setApplicantAddress(address);
data.getContactDetailsWrapper().setApplicantRepresented(YesOrNo.NO);

GenericAboutToStartOrSubmitCallbackResponse<FinremCaseData> handle = handler.handle(finremCallbackRequest, AUTH_TOKEN);

assertEquals(1, handle.getErrors().size());
assertTrue(handle.getErrors().get(0).equals("Postcode field is required for applicant address."));
}

@Test
void givenConsentedCase_WhenNullApplicantPostCode_thenHandlerWillShowMessage() {

FinremCallbackRequest finremCallbackRequest = buildCallbackRequest();
FinremCaseDetails caseDetails = finremCallbackRequest.getCaseDetails();
FinremCaseData data = caseDetails.getData();

Address address = new Address();
address.setPostCode(null);
data.getContactDetailsWrapper().setApplicantAddress(address);
data.getContactDetailsWrapper().setApplicantRepresented(YesOrNo.NO);

GenericAboutToStartOrSubmitCallbackResponse<FinremCaseData> handle = handler.handle(finremCallbackRequest, AUTH_TOKEN);

assertEquals(1, handle.getErrors().size());
assertTrue(handle.getErrors().get(0).equals("Postcode field is required for applicant address."));
}

@Test
void givenConsentedCase_WhenEmptyRespondentPostCode_thenHandlerWillShowMessage() {

FinremCallbackRequest finremCallbackRequest = buildCallbackRequest();
FinremCaseDetails caseDetails = finremCallbackRequest.getCaseDetails();
FinremCaseData data = caseDetails.getData();

Address address = new Address();
address.setPostCode("AB1 1AB");
Address addressBlank = new Address();
addressBlank.setPostCode("");
data.getContactDetailsWrapper().setApplicantAddress(address);
data.getContactDetailsWrapper().setRespondentAddress(addressBlank);
data.getContactDetailsWrapper().setApplicantRepresented(YesOrNo.NO);
data.getContactDetailsWrapper().setContestedRespondentRepresented(YesOrNo.NO);

GenericAboutToStartOrSubmitCallbackResponse<FinremCaseData> handle = handler.handle(finremCallbackRequest, AUTH_TOKEN);

assertEquals(1, handle.getErrors().size());
assertTrue(handle.getErrors().get(0).equals("Postcode field is required for respondent address."));
}

@Test
void givenConsentedCase_WhenNullRespondentPostCode_thenHandlerWillShowMessage() {

FinremCallbackRequest finremCallbackRequest = buildCallbackRequest();
FinremCaseDetails caseDetails = finremCallbackRequest.getCaseDetails();
FinremCaseData data = caseDetails.getData();

Address address = new Address();
address.setPostCode("AB1 1AB");
Address addressBlank = new Address();
addressBlank.setPostCode(null);
data.getContactDetailsWrapper().setApplicantAddress(address);
data.getContactDetailsWrapper().setRespondentAddress(addressBlank);
data.getContactDetailsWrapper().setApplicantRepresented(YesOrNo.NO);
data.getContactDetailsWrapper().setContestedRespondentRepresented(YesOrNo.NO);

GenericAboutToStartOrSubmitCallbackResponse<FinremCaseData> handle = handler.handle(finremCallbackRequest, AUTH_TOKEN);

assertEquals(1, handle.getErrors().size());
assertTrue(handle.getErrors().get(0).equals("Postcode field is required for respondent address."));
}

@Test
void givenConsentedCase_WhenEmptyApplicantSolicitorPostCode_thenHandlerWillShowMessage() {

FinremCallbackRequest finremCallbackRequest = buildCallbackRequest();
FinremCaseDetails caseDetails = finremCallbackRequest.getCaseDetails();
FinremCaseData data = caseDetails.getData();

Address address = new Address();
address.setPostCode("AB1 1AB");
Address addressBlank = new Address();
addressBlank.setPostCode("");
dawudgovuk marked this conversation as resolved.
Show resolved Hide resolved
data.getContactDetailsWrapper().setApplicantAddress(address);
data.getContactDetailsWrapper().setApplicantRepresented(YesOrNo.YES);
data.getContactDetailsWrapper().setApplicantSolicitorAddress(addressBlank);

GenericAboutToStartOrSubmitCallbackResponse<FinremCaseData> handle = handler.handle(finremCallbackRequest, AUTH_TOKEN);

assertEquals(1, handle.getErrors().size());
assertTrue(handle.getErrors().get(0).equals("Postcode field is required for applicant solicitor address."));
}

@Test
void givenConsentedCase_WhenEmptyRespondentSolicitorPostCode_thenHandlerWillShowMessage() {

FinremCallbackRequest finremCallbackRequest = buildCallbackRequest();
FinremCaseDetails caseDetails = finremCallbackRequest.getCaseDetails();
FinremCaseData data = caseDetails.getData();

Address address = new Address();
address.setPostCode("AB1 1AB");
Address addressBlank = new Address();
addressBlank.setPostCode("");
data.getContactDetailsWrapper().setApplicantAddress(address);
data.getContactDetailsWrapper().setRespondentAddress(address);
data.getContactDetailsWrapper().setApplicantRepresented(YesOrNo.YES);
data.getContactDetailsWrapper().setContestedRespondentRepresented(YesOrNo.YES);
data.getContactDetailsWrapper().setRespondentSolicitorAddress(addressBlank);

GenericAboutToStartOrSubmitCallbackResponse<FinremCaseData> handle = handler.handle(finremCallbackRequest, AUTH_TOKEN);

assertEquals(1, handle.getErrors().size());
assertTrue(handle.getErrors().get(0).equals("Postcode field is required for respondent solicitor address."));
}

@Test
void givenConsentedCase_WhenNullApplicantSolicitorPostCode_thenHandlerWillShowMessage() {

FinremCallbackRequest finremCallbackRequest = buildCallbackRequest();
FinremCaseDetails caseDetails = finremCallbackRequest.getCaseDetails();
FinremCaseData data = caseDetails.getData();

Address address = new Address();
address.setPostCode("AB1 1AB");
Address addressBlank = new Address();
addressBlank.setPostCode(null);
data.getContactDetailsWrapper().setApplicantAddress(address);
data.getContactDetailsWrapper().setApplicantRepresented(YesOrNo.YES);
data.getContactDetailsWrapper().setApplicantSolicitorAddress(addressBlank);

GenericAboutToStartOrSubmitCallbackResponse<FinremCaseData> handle = handler.handle(finremCallbackRequest, AUTH_TOKEN);

assertEquals(1, handle.getErrors().size());
assertTrue(handle.getErrors().get(0).equals("Postcode field is required for applicant solicitor address."));
}

@Test
void givenConsentedCase_WhenNullRespondentSolicitorPostCode_thenHandlerWillShowMessage() {

FinremCallbackRequest finremCallbackRequest = buildCallbackRequest();
FinremCaseDetails caseDetails = finremCallbackRequest.getCaseDetails();
FinremCaseData data = caseDetails.getData();

Address address = new Address();
address.setPostCode("AB1 1AB");
Address addressBlank = new Address();
addressBlank.setPostCode(null);
data.getContactDetailsWrapper().setApplicantAddress(address);
data.getContactDetailsWrapper().setRespondentAddress(address);
data.getContactDetailsWrapper().setApplicantRepresented(YesOrNo.YES);
data.getContactDetailsWrapper().setContestedRespondentRepresented(YesOrNo.YES);
data.getContactDetailsWrapper().setRespondentSolicitorAddress(addressBlank);

GenericAboutToStartOrSubmitCallbackResponse<FinremCaseData> handle = handler.handle(finremCallbackRequest, AUTH_TOKEN);

assertEquals(1, handle.getErrors().size());
assertTrue(handle.getErrors().get(0).equals("Postcode field is required for respondent solicitor address."));
}
}