From ef0198c18dede00f5cc2950e0510ee462fea8b33 Mon Sep 17 00:00:00 2001 From: UshaPanneerselvam1 <122611188+UshaPanneerselvam1@users.noreply.github.com> Date: Tue, 14 Nov 2023 14:08:43 +0000 Subject: [PATCH 1/3] CIV-8923 Refactoring tempAddress to tempCorrespondence (#3568) CIV-8923 specAoSApplicantCorrespondenceAddressdetails is being updated when defendant updates address --- .../RespondToClaimSpecCallbackHandler.java | 8 +++---- .../reform/civil/model/CaseDataParent.java | 12 +++++----- ...RespondToClaimSpecCallbackHandlerTest.java | 22 +++++++++---------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandler.java index 701d9c1c912..df862ffbf82 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandler.java @@ -1363,9 +1363,9 @@ private CallbackResponse setApplicantResponseDeadline(CallbackParams callbackPar AllocatedTrack allocatedTrack = caseData.getAllocatedTrack(); Party updatedRespondent1; - if (NO.equals(caseData.getTempAddress1Required())) { + if (NO.equals(caseData.getTempCorrespondenceAddress1Required())) { updatedRespondent1 = caseData.getRespondent1().toBuilder() - .primaryAddress(caseData.getTempAddress1()).build(); + .primaryAddress(caseData.getTempCorrespondenceAddress1()).build(); } else { updatedRespondent1 = caseData.getRespondent1().toBuilder() .primaryAddress(caseData.getRespondent1Copy().getPrimaryAddress()) @@ -1578,9 +1578,9 @@ && isAwaitingAnotherDefendantResponse(caseData)) { private static Party applyRespondent2Address(CaseData caseData, CaseData.CaseDataBuilder updatedData) { Party updatedRespondent2; - if (NO.equals(caseData.getTempAddress2Required())) { + if (NO.equals(caseData.getTempCorrespondenceAddress2Required())) { updatedRespondent2 = caseData.getRespondent2().toBuilder() - .primaryAddress(caseData.getTempAddress2()).build(); + .primaryAddress(caseData.getTempCorrespondenceAddress2()).build(); } else { updatedRespondent2 = caseData.getRespondent2().toBuilder() .primaryAddress(caseData.getRespondent2Copy().getPrimaryAddress()).build(); diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/CaseDataParent.java b/src/main/java/uk/gov/hmcts/reform/civil/model/CaseDataParent.java index 08b9556caf8..5db7728550f 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/CaseDataParent.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/CaseDataParent.java @@ -726,19 +726,19 @@ public boolean isApplicantNotRepresented() { /** * used to temporary hold addresses. */ - private final Address tempAddress1; + private final Address tempCorrespondenceAddress1; /** - * used with tempAddress1. + * used with tempCorrespondenceAddress1. */ - private final YesOrNo tempAddress1Required; + private final YesOrNo tempCorrespondenceAddress1Required; /** * used to temporary hold addresses. */ - private final Address tempAddress2; + private final Address tempCorrespondenceAddress2; /** - * used with tempAddress1. + * used with tempCorrespondenceAddress2. */ - private final YesOrNo tempAddress2Required; + private final YesOrNo tempCorrespondenceAddress2Required; @JsonIgnore public boolean isResponseAcceptedByClaimant() { diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandlerTest.java index 1ae04095de2..73040deeb42 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandlerTest.java @@ -789,8 +789,8 @@ void updateRespondent1AddressWhenUpdated() { .respondent1(PartyBuilder.builder().individual().build()) .atStateApplicantRespondToDefenceAndProceed() .build().toBuilder() - .tempAddress1Required(NO) - .tempAddress1(AddressBuilder.maximal().build()) + .tempCorrespondenceAddress1Required(NO) + .tempCorrespondenceAddress1(AddressBuilder.maximal().build()) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); @@ -829,11 +829,11 @@ void updateRespondent2AddressWhenUpdated() { .respondent2(PartyBuilder.builder().individual().build()) .respondent2Copy(PartyBuilder.builder().individual().build()) .build().toBuilder() - .tempAddress1Required(YES) - .tempAddress1(Address.builder().build()) + .tempCorrespondenceAddress1Required(YES) + .tempCorrespondenceAddress1(Address.builder().build()) .build().toBuilder() - .tempAddress2Required(NO) - .tempAddress2(newAddress2) + .tempCorrespondenceAddress2Required(NO) + .tempCorrespondenceAddress2(newAddress2) .respondentSolicitor2ServiceAddressRequired(NO) .respondentSolicitor2ServiceAddress(newAddress2) .build(); @@ -906,12 +906,12 @@ void defendantResponsePopulatesWitnessesData() { .respondent1DQWitnessesSmallClaim(res1witnesses) .respondent2DQWitnessesSmallClaim(res2witnesses) .build().toBuilder() - .tempAddress1Required(YES) - .tempAddress1(Address.builder().build()) + .tempCorrespondenceAddress1Required(YES) + .tempCorrespondenceAddress1(Address.builder().build()) .respondent2ResponseDate(dateTime) .respondent1ResponseDate(dateTime).build().toBuilder() - .tempAddress2Required(NO) - .tempAddress2(AddressBuilder.maximal().build()) + .tempCorrespondenceAddress2Required(NO) + .tempCorrespondenceAddress2(AddressBuilder.maximal().build()) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); @@ -1729,7 +1729,7 @@ void shouldUpdateCorrespondence1_whenProvided1v2ss_withSameResponse_withv2copyAn .build()) .respondent2Copy(PartyBuilder.builder().individual().build()) .respondent2SameLegalRepresentative(YES) - .tempAddress2Required(NO) + .tempCorrespondenceAddress2Required(NO) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); From 9ac65c6031804011f335dfc1c44ca0653d4cfe4b Mon Sep 17 00:00:00 2001 From: dtortolaV1 <93722198+dtortolaV1@users.noreply.github.com> Date: Tue, 14 Nov 2023 17:38:54 +0100 Subject: [PATCH 2/3] CIV-8923 revert (#3570) * Revert "CIV-8923 Refactoring tempAddress to tempCorrespondence (#3568)" This reverts commit ef0198c18dede00f5cc2950e0510ee462fea8b33. * Revert "CIV-8923 specAoSApplicantCorrespondenceAddressdetails is being updated when defendant updates address (#3547)" This reverts commit f8969cd124e507a5239387c1625d8bf051de2914. --- .../RespondToClaimSpecCallbackHandler.java | 90 +- .../reform/civil/model/CaseDataParent.java | 17 - .../civil/utils/UnavailabilityDatesUtils.java | 2 +- ...RespondToClaimSpecCallbackHandlerTest.java | 1378 +++++------------ 4 files changed, 463 insertions(+), 1024 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandler.java index df862ffbf82..5640b94350a 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandler.java @@ -184,7 +184,7 @@ protected Map callbacks() { .put(callbackKey(MID, "upload"), this::emptyCallbackResponse) .put(callbackKey(MID, "statement-of-truth"), this::resetStatementOfTruth) .put(callbackKey(MID, "validate-payment-date"), this::validateRespondentPaymentDate) - .put(callbackKey(MID, "specCorrespondenceAddress"), this::validateCorrespondenceAddress) + .put(callbackKey(MID, "specCorrespondenceAddress"), this::validateCorrespondenceApplicantAddress) .put(callbackKey(MID, "determineLoggedInSolicitor"), this::determineLoggedInSolicitor) .put(callbackKey(MID, "track"), this::handleDefendAllClaim) .put(callbackKey(MID, "specHandleResponseType"), this::handleRespondentResponseTypeForSpec) @@ -1060,26 +1060,12 @@ private AllocatedTrack getAllocatedTrack(CaseData caseData) { ); } - private CallbackResponse validateCorrespondenceAddress(CallbackParams callbackParams) { - CaseData caseData = callbackParams.getCaseData(); - if (caseData.getIsRespondent1() == YES - && caseData.getRespondentSolicitor1ServiceAddressRequired() == NO) { - List errors = postcodeValidator.validate( - caseData.getRespondentSolicitor1ServiceAddress().getPostCode()); - - return AboutToStartOrSubmitCallbackResponse.builder() - .errors(errors) - .build(); - } else if (caseData.getIsRespondent2() == YES - && caseData.getRespondentSolicitor2ServiceAddressRequired() == NO) { - List errors = postcodeValidator.validate( - caseData.getRespondentSolicitor2ServiceAddress().getPostCode()); - - return AboutToStartOrSubmitCallbackResponse.builder() - .errors(errors) - .build(); + private CallbackResponse validateCorrespondenceApplicantAddress(CallbackParams callbackParams) { + if (SpecJourneyConstantLRSpec.DEFENDANT_RESPONSE_SPEC.equals(callbackParams.getRequest().getEventId())) { + return validateCorrespondenceApplicantAddress(callbackParams, postcodeValidator); } - return AboutToStartOrSubmitCallbackResponse.builder().build(); + return AboutToStartOrSubmitCallbackResponse.builder() + .build(); } private CallbackResponse determineLoggedInSolicitor(CallbackParams callbackParams) { @@ -1132,10 +1118,6 @@ private CallbackResponse populateRespondent1Copy(CallbackParams callbackParams) .respondent1Copy(caseData.getRespondent1()) .respondent1ClaimResponseTestForSpec(caseData.getRespondent1ClaimResponseTypeForSpec()) .respondent2ClaimResponseTestForSpec(caseData.getRespondent2ClaimResponseTypeForSpec()) - .respondentSolicitor1ServiceAddress(Address.builder().build()) - .respondentSolicitor2ServiceAddress(Address.builder().build()) - .respondentSolicitor1ServiceAddressRequired(null) - .respondentSolicitor2ServiceAddressRequired(null) .showConditionFlags(initialShowTags); updatedCaseData.respondent1DetailsForClaimDetailsTab(caseData.getRespondent1().toBuilder().flags(null).build()); @@ -1283,9 +1265,9 @@ private CallbackResponse validateUnavailableDates(CallbackParams callbackParams) } private CallbackResponse validateDateOfBirth(CallbackParams callbackParams) { - Party respondent = callbackParams.getCaseData().getRespondent1Copy(); - if (respondent == null && callbackParams.getCaseData().getRespondent2Copy() != null) { - respondent = callbackParams.getCaseData().getRespondent2Copy(); + Party respondent = callbackParams.getCaseData().getRespondent1(); + if (respondent == null && callbackParams.getCaseData().getRespondent2() != null) { + respondent = callbackParams.getCaseData().getRespondent2(); } List errors = dateOfBirthValidator.validate(respondent); @@ -1363,9 +1345,9 @@ private CallbackResponse setApplicantResponseDeadline(CallbackParams callbackPar AllocatedTrack allocatedTrack = caseData.getAllocatedTrack(); Party updatedRespondent1; - if (NO.equals(caseData.getTempCorrespondenceAddress1Required())) { + if (NO.equals(caseData.getSpecAoSApplicantCorrespondenceAddressRequired())) { updatedRespondent1 = caseData.getRespondent1().toBuilder() - .primaryAddress(caseData.getTempCorrespondenceAddress1()).build(); + .primaryAddress(caseData.getSpecAoSApplicantCorrespondenceAddressdetails()).build(); } else { updatedRespondent1 = caseData.getRespondent1().toBuilder() .primaryAddress(caseData.getRespondent1Copy().getPrimaryAddress()) @@ -1442,8 +1424,21 @@ && ifResponseTypeIsPartOrFullAdmission(caseData)) { .businessProcess(BusinessProcess.ready(DEFENDANT_RESPONSE_SPEC)); if (caseData.getRespondent2() != null && caseData.getRespondent2Copy() != null) { - Party updatedRespondent2 = applyRespondent2Address(caseData, updatedData); - updatedData.respondent2DetailsForClaimDetailsTab(updatedRespondent2); + Party updatedRespondent2; + + if (NO.equals(caseData.getSpecAoSRespondent2HomeAddressRequired())) { + updatedRespondent2 = caseData.getRespondent2().toBuilder() + .primaryAddress(caseData.getSpecAoSRespondent2HomeAddressDetails()).build(); + } else { + updatedRespondent2 = caseData.getRespondent2().toBuilder() + .primaryAddress(caseData.getRespondent2Copy().getPrimaryAddress()).build(); + } + + updatedData + .respondent2(updatedRespondent2.toBuilder() + .flags(caseData.getRespondent2Copy().getFlags()).build()) + .respondent2Copy(null); + updatedData.respondent2DetailsForClaimDetailsTab(updatedRespondent2.toBuilder().flags(null).build()); } // moving statement of truth value to correct field, this was not possible in mid event. @@ -1500,10 +1495,8 @@ && ifResponseTypeIsPartOrFullAdmission(caseData)) { .build()); } - UnavailabilityDatesUtils.rollUpUnavailabilityDatesForRespondent( - updatedData, - toggleService.isUpdateContactDetailsEnabled() - ); + UnavailabilityDatesUtils.rollUpUnavailabilityDatesForRespondent(updatedData, + toggleService.isUpdateContactDetailsEnabled()); updatedData.respondent1DetailsForClaimDetailsTab(updatedData.build().getRespondent1().toBuilder().flags(null).build()); if (ofNullable(caseData.getRespondent2()).isPresent()) { @@ -1575,21 +1568,6 @@ && isAwaitingAnotherDefendantResponse(caseData)) { .build(); } - private static Party applyRespondent2Address(CaseData caseData, CaseData.CaseDataBuilder updatedData) { - Party updatedRespondent2; - - if (NO.equals(caseData.getTempCorrespondenceAddress2Required())) { - updatedRespondent2 = caseData.getRespondent2().toBuilder() - .primaryAddress(caseData.getTempCorrespondenceAddress2()).build(); - } else { - updatedRespondent2 = caseData.getRespondent2().toBuilder() - .primaryAddress(caseData.getRespondent2Copy().getPrimaryAddress()).build(); - } - - updatedData.respondent2(updatedRespondent2).respondent2Copy(null); - return updatedRespondent2; - } - private boolean ifResponseTypeIsPartOrFullAdmission(CaseData caseData) { return (RespondentResponseTypeSpec.PART_ADMISSION.equals(caseData.getRespondent1ClaimResponseTypeForSpec()) || RespondentResponseTypeSpec.PART_ADMISSION.equals( @@ -1604,19 +1582,19 @@ private void updateCorrespondenceAddress(CallbackParams callbackParams, CaseData.CaseDataBuilder updatedCaseData, CaseData caseData) { if (solicitorHasCaseRole(callbackParams, RESPONDENTSOLICITORONE) - && caseData.getRespondentSolicitor1ServiceAddressRequired() == YesOrNo.NO) { - Address newAddress = caseData.getRespondentSolicitor1ServiceAddress(); + && caseData.getSpecAoSRespondentCorrespondenceAddressRequired() == YesOrNo.NO) { + Address newAddress = caseData.getSpecAoSRespondentCorrespondenceAddressdetails(); updatedCaseData.specRespondentCorrespondenceAddressdetails(newAddress) - .respondentSolicitor1ServiceAddress(Address.builder().build()); + .specAoSRespondentCorrespondenceAddressdetails(Address.builder().build()); if (getMultiPartyScenario(caseData) == ONE_V_TWO_ONE_LEGAL_REP) { // to keep with heading tab updatedCaseData.specRespondent2CorrespondenceAddressdetails(newAddress); } } else if (solicitorHasCaseRole(callbackParams, RESPONDENTSOLICITORTWO) - && caseData.getRespondentSolicitor2ServiceAddressRequired() == YesOrNo.NO) { + && caseData.getSpecAoSRespondent2CorrespondenceAddressRequired() == YesOrNo.NO) { updatedCaseData.specRespondent2CorrespondenceAddressdetails( - caseData.getRespondentSolicitor2ServiceAddress()) - .respondentSolicitor2ServiceAddress(Address.builder().build()); + caseData.getSpecAoSRespondent2CorrespondenceAddressdetails()) + .specAoSRespondent2CorrespondenceAddressdetails(Address.builder().build()); } } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/CaseDataParent.java b/src/main/java/uk/gov/hmcts/reform/civil/model/CaseDataParent.java index 5db7728550f..7d2a5546ce9 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/CaseDataParent.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/CaseDataParent.java @@ -723,23 +723,6 @@ public boolean isApplicantNotRepresented() { private FastTrackAllocation fastTrackAllocation; - /** - * used to temporary hold addresses. - */ - private final Address tempCorrespondenceAddress1; - /** - * used with tempCorrespondenceAddress1. - */ - private final YesOrNo tempCorrespondenceAddress1Required; - /** - * used to temporary hold addresses. - */ - private final Address tempCorrespondenceAddress2; - /** - * used with tempCorrespondenceAddress2. - */ - private final YesOrNo tempCorrespondenceAddress2Required; - @JsonIgnore public boolean isResponseAcceptedByClaimant() { return applicant1AcceptAdmitAmountPaidSpec == YesOrNo.YES diff --git a/src/main/java/uk/gov/hmcts/reform/civil/utils/UnavailabilityDatesUtils.java b/src/main/java/uk/gov/hmcts/reform/civil/utils/UnavailabilityDatesUtils.java index 81a5e845f2e..5c394d09ee5 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/utils/UnavailabilityDatesUtils.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/utils/UnavailabilityDatesUtils.java @@ -76,7 +76,7 @@ public static void rollUpUnavailabilityDatesForRespondent(CaseData.CaseDataBuild .getUnavailableDates(); List> updatedUnavailableDates = addEventAndDate( - caseData.getRespondent2ResponseDate().toLocalDate(), + caseData.getRespondent1ResponseDate().toLocalDate(), DEFENDANT_RESPONSE_EVENT, respondent2DQUnavailableDates ); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandlerTest.java index 73040deeb42..6fbfc1fb527 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandlerTest.java @@ -19,7 +19,6 @@ import uk.gov.hmcts.reform.ccd.client.model.CallbackRequest; import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse; import uk.gov.hmcts.reform.ccd.client.model.SubmittedCallbackResponse; -import uk.gov.hmcts.reform.civil.callback.CallbackException; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.callback.CallbackType; import uk.gov.hmcts.reform.civil.constants.SpecJourneyConstantLRSpec; @@ -56,26 +55,23 @@ import uk.gov.hmcts.reform.civil.model.UnavailableDate; import uk.gov.hmcts.reform.civil.model.common.DynamicList; import uk.gov.hmcts.reform.civil.model.common.Element; +import uk.gov.hmcts.reform.civil.model.dq.RequestedCourt; import uk.gov.hmcts.reform.civil.model.dq.Respondent1DQ; import uk.gov.hmcts.reform.civil.model.dq.Respondent2DQ; +import uk.gov.hmcts.reform.civil.model.dq.SmallClaimHearing; import uk.gov.hmcts.reform.civil.model.dq.Witness; import uk.gov.hmcts.reform.civil.model.dq.Witnesses; -import uk.gov.hmcts.reform.civil.model.dq.RequestedCourt; -import uk.gov.hmcts.reform.civil.model.dq.Expert; -import uk.gov.hmcts.reform.civil.model.dq.Experts; -import uk.gov.hmcts.reform.civil.model.dq.ExpertDetails; -import uk.gov.hmcts.reform.civil.model.dq.SmallClaimHearing; import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService; import uk.gov.hmcts.reform.civil.referencedata.model.LocationRefData; import uk.gov.hmcts.reform.civil.sampledata.AddressBuilder; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.sampledata.PartyBuilder; +import uk.gov.hmcts.reform.civil.service.CoreCaseUserService; import uk.gov.hmcts.reform.civil.service.DeadlinesCalculator; import uk.gov.hmcts.reform.civil.service.ExitSurveyContentService; import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.service.Time; import uk.gov.hmcts.reform.civil.service.UserService; -import uk.gov.hmcts.reform.civil.service.CoreCaseUserService; import uk.gov.hmcts.reform.civil.service.citizenui.responsedeadline.DeadlineExtensionCalculatorService; import uk.gov.hmcts.reform.civil.service.flowstate.FlowFlag; import uk.gov.hmcts.reform.civil.service.flowstate.StateFlowEngine; @@ -83,8 +79,8 @@ import uk.gov.hmcts.reform.civil.utils.AssignCategoryId; import uk.gov.hmcts.reform.civil.utils.CaseFlagsInitialiser; import uk.gov.hmcts.reform.civil.utils.CourtLocationUtils; -import uk.gov.hmcts.reform.civil.utils.MonetaryConversions; import uk.gov.hmcts.reform.civil.utils.ElementUtils; +import uk.gov.hmcts.reform.civil.utils.MonetaryConversions; import uk.gov.hmcts.reform.civil.validation.DateOfBirthValidator; import uk.gov.hmcts.reform.civil.validation.PaymentDateValidator; import uk.gov.hmcts.reform.civil.validation.PostcodeValidator; @@ -103,9 +99,7 @@ import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; @@ -125,7 +119,6 @@ import static uk.gov.hmcts.reform.civil.enums.CaseRole.RESPONDENTSOLICITORTWO; import static uk.gov.hmcts.reform.civil.enums.RespondentResponsePartAdmissionPaymentTimeLRspec.IMMEDIATELY; import static uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpec.FULL_ADMISSION; -import static uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpec.FULL_DEFENCE; import static uk.gov.hmcts.reform.civil.enums.YesOrNo.NO; import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.DATE; @@ -205,82 +198,15 @@ public void setup() { ); } - @Test - void whenCallBackEventNotImplementedOrEventInvalid() { - // Given - String postCode = "postCode"; - CaseData caseData = CaseData.builder() - .build().toBuilder() - .respondentSolicitor1ServiceAddressRequired(NO) - .respondentSolicitor1ServiceAddress(Address.builder().postCode(postCode).build()) - .isRespondent1(YES) - .build(); - CallbackParams callbackParams = callbackParamsOf(caseData, CallbackType.MID, " ").toBuilder() - .request(CallbackRequest.builder().eventId(SpecJourneyConstantLRSpec.DEFENDANT_RESPONSE_SPEC) - .build()).build(); - - //When - CallbackException ex = assertThrows(CallbackException.class, () -> handler.handle(callbackParams), - - "A CallbackException was expected to be thrown but wasn't."); - // Then - assertThat(ex.getMessage()).contains("Callback for event"); - } - - @Test - void resetStatementOfTruth() { - CaseData caseData = CaseDataBuilder.builder().build(); - CallbackParams params = callbackParamsOf(caseData, CallbackType.MID, "statement-of-truth"); - CallbackRequest request = CallbackRequest.builder() - .eventId(SpecJourneyConstantLRSpec.DEFENDANT_RESPONSE_SPEC) - .build(); - params = params.toBuilder().request(request).build(); - - // When - CallbackResponse response = handler.handle(params); - - // Then - assertNotNull(response); - } - @Test void midSpecCorrespondenceAddress_checkAddressIfWasIncorrect() { // Given String postCode = "postCode"; CaseData caseData = CaseData.builder() - .build().toBuilder() - .respondentSolicitor1ServiceAddressRequired(NO) - .respondentSolicitor1ServiceAddress(Address.builder().postCode(postCode).build()) - .isRespondent1(YES) - .build(); - CallbackParams params = callbackParamsOf(caseData, CallbackType.MID, "specCorrespondenceAddress"); - CallbackRequest request = CallbackRequest.builder() - .eventId(SpecJourneyConstantLRSpec.DEFENDANT_RESPONSE_SPEC) - .build(); - params = params.toBuilder().request(request).build(); - - List errors = Collections.singletonList("error 1"); - Mockito.when(postcodeValidator.validate(postCode)).thenReturn(errors); - - // When - CallbackResponse response = handler.handle(params); - - // Then - assertEquals(errors, ((AboutToStartOrSubmitCallbackResponse) response).getErrors()); - } - - @Test - void midSpecCorrespondenceAddress_checkAddressIfWasIncorrectForSol2() { - // Given - String postCode = "postCode"; - CaseData caseData = CaseData.builder() - .build().toBuilder() - .respondentSolicitor1ServiceAddressRequired(YES) - .respondentSolicitor1ServiceAddress(Address.builder().postCode(postCode).build()) - .isRespondent1(YES) - .isRespondent2(YES) - .respondentSolicitor2ServiceAddressRequired(NO) - .respondentSolicitor2ServiceAddress(Address.builder().postCode(postCode).build()) + .specAoSApplicantCorrespondenceAddressRequired(YesOrNo.NO) + .specAoSApplicantCorrespondenceAddressdetails(Address.builder() + .postCode(postCode) + .build()) .build(); CallbackParams params = callbackParamsOf(caseData, CallbackType.MID, "specCorrespondenceAddress"); CallbackRequest request = CallbackRequest.builder() @@ -388,8 +314,10 @@ void testSpecDefendantResponseFastTrackOneVTwoLegalRep() { assertThat(response.getData()).isNotNull(); assertThat(response.getData()).containsEntry("responseClaimTrack", AllocatedTrack.FAST_CLAIM.name()); assertThat(response.getData()).containsEntry("specDisputesOrPartAdmission", "No"); - assertThat(response.getData()).containsEntry("specPaidLessAmountOrDisputesOrPartAdmission", - "No"); + assertThat(response.getData()).containsEntry( + "specPaidLessAmountOrDisputesOrPartAdmission", + "No" + ); } @Test @@ -419,8 +347,10 @@ void testSpecDefendantResponseFastTrackOneVTwoSameLegalRep() { assertThat(response.getData()).isNotNull(); assertThat(response.getData()).containsEntry("responseClaimTrack", AllocatedTrack.FAST_CLAIM.name()); assertThat(response.getData()).containsEntry("specDisputesOrPartAdmission", "No"); - assertThat(response.getData()).containsEntry("specPaidLessAmountOrDisputesOrPartAdmission", - "No"); + assertThat(response.getData()).containsEntry( + "specPaidLessAmountOrDisputesOrPartAdmission", + "No" + ); } @Test @@ -446,8 +376,10 @@ void testSpecDefendantResponseFastTrackTwoVOne() { assertThat(response.getData()).isNotNull(); assertThat(response.getData()).containsEntry("responseClaimTrack", AllocatedTrack.FAST_CLAIM.name()); assertThat(response.getData()).containsEntry("specDisputesOrPartAdmission", "No"); - assertThat(response.getData()).containsEntry("specPaidLessAmountOrDisputesOrPartAdmission", - "No"); + assertThat(response.getData()).containsEntry( + "specPaidLessAmountOrDisputesOrPartAdmission", + "No" + ); } @Test @@ -730,6 +662,9 @@ public void testValidateRespondentPaymentDate() { AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler .handle(params); + List expectedErrorArray = new ArrayList<>(); + expectedErrorArray.add("Date for when will the amount be paid must be today or in the future."); + // Then assertThat(response).isNotNull(); /* @@ -788,9 +723,8 @@ void updateRespondent1AddressWhenUpdated() { CaseData caseData = CaseDataBuilder.builder() .respondent1(PartyBuilder.builder().individual().build()) .atStateApplicantRespondToDefenceAndProceed() - .build().toBuilder() - .tempCorrespondenceAddress1Required(NO) - .tempCorrespondenceAddress1(AddressBuilder.maximal().build()) + .atSpecAoSApplicantCorrespondenceAddressRequired(NO) + .atSpecAoSApplicantCorrespondenceAddressDetails(AddressBuilder.maximal().build()) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); @@ -821,21 +755,15 @@ void updateRespondent2AddressWhenUpdated() { when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); - Address newAddress2 = AddressBuilder.defaults().build(); CaseData caseData = CaseDataBuilder.builder().atStateApplicantRespondToDefenceAndProceed() .respondent2DQ() .respondent1Copy(PartyBuilder.builder().individual().build()) + .atSpecAoSApplicantCorrespondenceAddressRequired(YES) .addRespondent2(YES) .respondent2(PartyBuilder.builder().individual().build()) .respondent2Copy(PartyBuilder.builder().individual().build()) - .build().toBuilder() - .tempCorrespondenceAddress1Required(YES) - .tempCorrespondenceAddress1(Address.builder().build()) - .build().toBuilder() - .tempCorrespondenceAddress2Required(NO) - .tempCorrespondenceAddress2(newAddress2) - .respondentSolicitor2ServiceAddressRequired(NO) - .respondentSolicitor2ServiceAddress(newAddress2) + .atSpecAoSRespondent2HomeAddressRequired(NO) + .atSpecAoSRespondent2HomeAddressDetails(AddressBuilder.maximal().build()) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); @@ -849,52 +777,28 @@ void updateRespondent2AddressWhenUpdated() { // Then assertThat(response.getData()) .extracting("respondent2").extracting("primaryAddress") - .extracting("AddressLine1").isEqualTo(newAddress2.getAddressLine1()); + .extracting("AddressLine1").isEqualTo("address line 1"); assertThat(response.getData()) .extracting("respondent2").extracting("primaryAddress") - .extracting("AddressLine2").isEqualTo(newAddress2.getAddressLine2()); + .extracting("AddressLine2").isEqualTo("address line 2"); assertThat(response.getData()) .extracting("respondent2").extracting("primaryAddress") - .extracting("AddressLine3").isEqualTo(newAddress2.getAddressLine3()); + .extracting("AddressLine3").isEqualTo("address line 3"); } @Test - void defendantResponsePopulatesWitnessesData() { + void updateRespondent2AddressWhenSpecAoSRespondent2HomeAddressRequiredIsNO() { // Given - LocalDateTime dateTime = LocalDateTime.of(2023, 6, 6, 6, 6, 6); - LocalDate date = dateTime.toLocalDate(); when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); - when(time.now()).thenReturn(dateTime); when(mockedStateFlow.isFlagSet(any())).thenReturn(true); when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); - when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); - when(toggleService.isHmcEnabled()).thenReturn(true); - - Witnesses res1witnesses = Witnesses.builder().details( - wrapElements( - Witness.builder() - .firstName("Witness") - .lastName("One") - .emailAddress("test-witness-one@example.com") - .phoneNumber("07865456789") - .reasonForWitness("great reasons") - .eventAdded("Defendant Response Event") - .dateAdded(date) - .build()) - ).build(); - - Witnesses res2witnesses = Witnesses.builder().details( - wrapElements( - Witness.builder() - .firstName("Witness") - .lastName("Two") - .emailAddress("test-witness-two@example.com") - .phoneNumber("07532628263") - .reasonForWitness("good reasons") - .eventAdded("Defendant Response Event") - .dateAdded(date) - .build()) - ).build(); + + Party partyWithPrimaryAddress = PartyBuilder.builder().individual().build(); + partyWithPrimaryAddress.setPrimaryAddress(AddressBuilder.maximal() + .addressLine1("address line 1") + .addressLine2("address line 2") + .addressLine3("address line 3") + .build()); CaseData caseData = CaseDataBuilder.builder().atStateApplicantRespondToDefenceAndProceed() .respondent2DQ() @@ -902,693 +806,422 @@ void defendantResponsePopulatesWitnessesData() { .addRespondent2(YES) .respondent2(PartyBuilder.builder().individual().build()) .respondent2Copy(PartyBuilder.builder().individual().build()) - .build().toBuilder() - .respondent1DQWitnessesSmallClaim(res1witnesses) - .respondent2DQWitnessesSmallClaim(res2witnesses) - .build().toBuilder() - .tempCorrespondenceAddress1Required(YES) - .tempCorrespondenceAddress1(Address.builder().build()) - .respondent2ResponseDate(dateTime) - .respondent1ResponseDate(dateTime).build().toBuilder() - .tempCorrespondenceAddress2Required(NO) - .tempCorrespondenceAddress2(AddressBuilder.maximal().build()) + .atSpecAoSRespondent2HomeAddressRequired(NO) + .atSpecAoSRespondent2HomeAddressDetails(AddressBuilder.maximal() + .addressLine1("new address line 1") + .build()) .build(); - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - when(deadlinesCalculator.calculateApplicantResponseDeadlineSpec(any(), any())) - .thenReturn(LocalDateTime.now()); - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); - - var objectMapper = new ObjectMapper(); - objectMapper.findAndRegisterModules(); - objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle( + callbackParamsOf(caseData, ABOUT_TO_SUBMIT)); // Then - - Witnesses actualRespondent1DQWitnesses = objectMapper.convertValue(response.getData().get("respondent1DQWitnesses"), new TypeReference<>() {}); - Witness actualRespondent1Witness = unwrapElements(actualRespondent1DQWitnesses.getDetails()).get(0); - assertThat(actualRespondent1Witness.getPartyID()).isNotNull(); - assertThat(actualRespondent1Witness.getFirstName()).isEqualTo("Witness"); - assertThat(actualRespondent1Witness.getLastName()).isEqualTo("One"); - assertThat(actualRespondent1Witness.getEmailAddress()).isEqualTo("test-witness-one@example.com"); - assertThat(actualRespondent1Witness.getPhoneNumber()).isEqualTo("07865456789"); - assertThat(actualRespondent1Witness.getReasonForWitness()).isEqualTo("great reasons"); - assertThat(actualRespondent1Witness.getEventAdded()).isEqualTo("Defendant Response Event"); - assertThat(actualRespondent1Witness.getDateAdded()).isEqualTo(date); - - Witnesses actualRespondent2DQWitnesses = objectMapper.convertValue(response.getData().get("respondent2DQWitnesses"), new TypeReference<>() {}); - Witness respondent2Witness = unwrapElements(actualRespondent2DQWitnesses.getDetails()).get(0); - assertThat(respondent2Witness.getPartyID()).isNotNull(); - assertThat(respondent2Witness.getFirstName()).isEqualTo("Witness"); - assertThat(respondent2Witness.getLastName()).isEqualTo("Two"); - assertThat(respondent2Witness.getEmailAddress()).isEqualTo("test-witness-two@example.com"); - assertThat(respondent2Witness.getPhoneNumber()).isEqualTo("07532628263"); - assertThat(respondent2Witness.getReasonForWitness()).isEqualTo("good reasons"); - assertThat(respondent2Witness.getEventAdded()).isEqualTo("Defendant Response Event"); - assertThat(respondent2Witness.getDateAdded()).isEqualTo(date); - - } - - @Nested - class HandleLocations { - - @Test - void oneVOne() { - // Given - DynamicList locationValues = DynamicList.fromList(List.of("Value 1")); - DynamicList preferredCourt = DynamicList.builder() - .listItems(locationValues.getListItems()) - .value(locationValues.getListItems().get(0)) - .build(); - Party defendant1 = Party.builder() - .type(Party.Type.COMPANY) - .companyName("company") - .build(); - CaseData caseData = CaseData.builder() - .caseAccessCategory(SPEC_CLAIM) - .ccdCaseReference(354L) - .respondent1(defendant1) - .respondent1Copy(defendant1) - .respondent1DQ( - Respondent1DQ.builder() - .respondToCourtLocation( - RequestedCourt.builder() - .responseCourtLocations(preferredCourt) - .reasonForHearingAtSpecificCourt("Reason") - .build() - ) - .build() - ) - .showConditionFlags(EnumSet.of( - DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_1 - )) - .build(); - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - - List locations = List.of(LocationRefData.builder().build()); - when(locationRefDataService.getCourtLocationsForDefaultJudgments(any())) - .thenReturn(locations); - LocationRefData completePreferredLocation = LocationRefData.builder() - .regionId("regionId") - .epimmsId("epimms") - .courtLocationCode("code") - .build(); - when(courtLocationUtils.findPreferredLocationData( - locations, preferredCourt - )).thenReturn(completePreferredLocation); - StateFlow flow = mock(StateFlow.class); - when(flow.isFlagSet(FlowFlag.TWO_RESPONDENT_REPRESENTATIVES)).thenReturn(false); - when(stateFlowEngine.evaluate(caseData)) - .thenReturn(flow); - when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), any(CaseRole.class))) - .thenReturn(true); - UserInfo userInfo = UserInfo.builder().uid("798").build(); - when(userService.getUserInfo(anyString())).thenReturn(userInfo); - - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); - - // Then - AbstractObjectAssert sent1 = assertThat(response.getData()) - .extracting("respondent1DQRequestedCourt"); - sent1.extracting("caseLocation") - .extracting("region") - .isEqualTo(completePreferredLocation.getRegionId()); - sent1.extracting("caseLocation") - .extracting("baseLocation") - .isEqualTo(completePreferredLocation.getEpimmsId()); - sent1.extracting("responseCourtCode") - .isEqualTo(completePreferredLocation.getCourtLocationCode()); - sent1.extracting("reasonForHearingAtSpecificCourt") - .isEqualTo("Reason"); - } - - @Test - void oneVTwo_SecondDefendantRepliesSameLegalRep() { - // Given - DynamicList locationValues = DynamicList.fromList(List.of("Value 1")); - DynamicList preferredCourt = DynamicList.builder() - .listItems(locationValues.getListItems()) - .value(locationValues.getListItems().get(0)) - .build(); - Party defendant1 = Party.builder() - .type(Party.Type.COMPANY) - .companyName("company") - .build(); - Party defendant2 = Party.builder() - .type(Party.Type.COMPANY) - .companyName("company2") - .build(); - CaseData caseData = CaseData.builder() - .respondent2SameLegalRepresentative(YES) - .caseAccessCategory(SPEC_CLAIM) - .ccdCaseReference(354L) - .defenceAdmitPartPaymentTimeRouteRequired(IMMEDIATELY) - .respondent2ClaimResponseTypeForSpec(FULL_ADMISSION) - .respondent1(defendant1) - .respondent1Copy(defendant1) - .respondent2(defendant2) - .respondent2Copy(defendant2) - .respondent1DQ( - Respondent1DQ.builder() - .respondToCourtLocation( - RequestedCourt.builder() - .responseCourtLocations(preferredCourt) - .reasonForHearingAtSpecificCourt("Reason") - .build() - ) - .build() - ) - .respondent2DQ( - Respondent2DQ.builder() - .respondToCourtLocation2( - RequestedCourt.builder() - .responseCourtLocations(preferredCourt) - .reasonForHearingAtSpecificCourt("Reason123") - .build() - ) - .build() - ) - .showConditionFlags(EnumSet.of( - DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_1, - DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_2 - )) - .build(); - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - - List locations = List.of(LocationRefData.builder().build()); - when(locationRefDataService.getCourtLocationsForDefaultJudgments(any())) - .thenReturn(locations); - LocationRefData completePreferredLocation = LocationRefData.builder() - .regionId("regionId") - .epimmsId("epimms") - .courtLocationCode("code") - .build(); - when(courtLocationUtils.findPreferredLocationData( - locations, preferredCourt - )).thenReturn(completePreferredLocation); - StateFlow flow = mock(StateFlow.class); - when(flow.isFlagSet(FlowFlag.TWO_RESPONDENT_REPRESENTATIVES)).thenReturn(true); - when(stateFlowEngine.evaluate(caseData)).thenReturn(flow); - when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), any(CaseRole.class))) - .thenReturn(true); - UserInfo userInfo = UserInfo.builder().uid("798").build(); - when(userService.getUserInfo(anyString())).thenReturn(userInfo); - LocalDate whenWillPay = LocalDate.now().plusDays(5); - given(deadlineExtensionCalculatorService.calculateExtendedDeadline(any(), anyInt())).willReturn(whenWillPay); - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - - // Then - AbstractObjectAssert sent2 = assertThat(response.getData()) - .extracting("respondent2DQRequestedCourt"); - sent2.extracting("caseLocation") - .extracting("region") - .isEqualTo(completePreferredLocation.getRegionId()); - sent2.extracting("caseLocation") - .extracting("baseLocation") - .isEqualTo(completePreferredLocation.getEpimmsId()); - sent2.extracting("responseCourtCode") - .isEqualTo(completePreferredLocation.getCourtLocationCode()); - sent2.extracting("reasonForHearingAtSpecificCourt") - .isEqualTo("Reason123"); - } - - @Test - void oneVTwo_SecondDefendantReplies() { - // Given - DynamicList locationValues = DynamicList.fromList(List.of("Value 1")); - DynamicList preferredCourt = DynamicList.builder() - .listItems(locationValues.getListItems()) - .value(locationValues.getListItems().get(0)) - .build(); - Party defendant1 = Party.builder() - .type(Party.Type.COMPANY) - .companyName("company") - .build(); - Party defendant2 = Party.builder() - .type(Party.Type.COMPANY) - .companyName("company 2") - .build(); - CaseData caseData = CaseData.builder() - .caseAccessCategory(SPEC_CLAIM) - .ccdCaseReference(354L) - .respondent1(defendant1) - .respondent1Copy(defendant1) - .respondent2(defendant2) - .respondent2Copy(defendant2) - .respondent1DQ( - Respondent1DQ.builder() - .respondToCourtLocation( - RequestedCourt.builder() - .responseCourtLocations(preferredCourt) - .reasonForHearingAtSpecificCourt("Reason") - .build() - ) - .build() - ) - .respondent2DQ( - Respondent2DQ.builder() - .respondToCourtLocation2( - RequestedCourt.builder() - .responseCourtLocations(preferredCourt) - .reasonForHearingAtSpecificCourt("Reason123") - .build() - ) - .build() - ) - .showConditionFlags(EnumSet.of( - DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_1, - DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_2 - )) - .build(); - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - - List locations = List.of(LocationRefData.builder().build()); - when(locationRefDataService.getCourtLocationsForDefaultJudgments(any())) - .thenReturn(locations); - LocationRefData completePreferredLocation = LocationRefData.builder() - .regionId("regionId") - .epimmsId("epimms") - .courtLocationCode("code") - .build(); - when(courtLocationUtils.findPreferredLocationData( - locations, preferredCourt - )).thenReturn(completePreferredLocation); - StateFlow flow = mock(StateFlow.class); - when(flow.isFlagSet(FlowFlag.TWO_RESPONDENT_REPRESENTATIVES)).thenReturn(true); - when(stateFlowEngine.evaluate(caseData)).thenReturn(flow); - when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), any(CaseRole.class))) - .thenReturn(true); - UserInfo userInfo = UserInfo.builder().uid("798").build(); - when(userService.getUserInfo(anyString())).thenReturn(userInfo); - - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); - - // Then - AbstractObjectAssert sent2 = assertThat(response.getData()) - .extracting("respondent2DQRequestedCourt"); - sent2.extracting("caseLocation") - .extracting("region") - .isEqualTo(completePreferredLocation.getRegionId()); - sent2.extracting("caseLocation") - .extracting("baseLocation") - .isEqualTo(completePreferredLocation.getEpimmsId()); - sent2.extracting("responseCourtCode") - .isEqualTo(completePreferredLocation.getCourtLocationCode()); - sent2.extracting("reasonForHearingAtSpecificCourt") - .isEqualTo("Reason123"); - } + assertThat(response.getData()) + .extracting("respondent2") + .extracting("primaryAddress") + .extracting("AddressLine1") + .isEqualTo("new address line 1"); } - } - - @Test - void shouldNullDocuments_whenInvokedAndCaseFileEnabled() { - // Given - when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); - when(mockedStateFlow.isFlagSet(any())).thenReturn(true); - when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); - when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); - when(toggleService.isCaseFileViewEnabled()).thenReturn(true); - var testDocument = ResponseDocument.builder() - .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl("binary-url").build()).build(); - - CaseData caseData = CaseData.builder() - .respondent1(PartyBuilder.builder().individual().build()) - .respondent1Copy(PartyBuilder.builder().individual().build()) - .respondent1DQ(Respondent1DQ.builder().build()) - .respondent2(PartyBuilder.builder().individual().build()) - .respondent2Copy(PartyBuilder.builder().individual().build()) - .respondent2DQ(Respondent2DQ.builder().build()) - .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_DEFENCE) - .respondent2ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_DEFENCE) - .ccdCaseReference(354L) - .respondent1SpecDefenceResponseDocument(testDocument) - .respondent2SpecDefenceResponseDocument(testDocument) - .build(); - - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); - - // Then - assertThat(response.getData().get("respondent1SpecDefenceResponseDocument")).isNull(); - assertThat(response.getData().get("respondent2SpecDefenceResponseDocument")).isNull(); - } - - @Test - void shouldUpdateExpertEvents_whenInvokedAndUpdateContactDetailsEnabled_For2DivergeResponse() { - // Given - LocalDateTime dateTime = LocalDateTime.of(2023, 6, 6, 6, 6, 6); - when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); - when(mockedStateFlow.isFlagSet(any())).thenReturn(true); - when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); - when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); - when(toggleService.isUpdateContactDetailsEnabled()).thenReturn(true); - - CaseData caseData = CaseData.builder() - .respondent1(PartyBuilder.builder().individual().build()) - .respondent1Copy(PartyBuilder.builder().individual().build()) - .respondent1DQ(Respondent1DQ.builder() - .respondent1DQExperts(Experts.builder() - .details(wrapElements(Expert.builder().build())).build()) - .build()) - .respondent2(PartyBuilder.builder().individual().build()) - .respondent2Copy(PartyBuilder.builder().individual().build()) - .respondent2DQ(Respondent2DQ.builder().build()) - .claimant1ClaimResponseTypeForSpec(FULL_DEFENCE) - .claimant2ClaimResponseTypeForSpec(FULL_ADMISSION) - .ccdCaseReference(354L) - .respondent1ResponseDate(dateTime).build().toBuilder() - .respondent2SameLegalRepresentative(YES) - .build(); - - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); - - // Then - assertThat(response.getData().get("respondent1DQExperts")).isNotNull(); - assertThat(response.getData().get("respondent2DQExperts")).isNull(); - - } - - @Test - void shouldUpdateExpertEvents_whenInvokedAndUpdateContactDetailsEnabled_CanAddApplicant2() { - // Given - LocalDateTime dateTime = LocalDateTime.of(2023, 6, 6, 6, 6, 6); - when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); - when(mockedStateFlow.isFlagSet(any())).thenReturn(true); - when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); - when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); - when(toggleService.isUpdateContactDetailsEnabled()).thenReturn(true); - - CaseData caseData = CaseData.builder() - .respondent1(PartyBuilder.builder().individual().build()) - .respondent1Copy(PartyBuilder.builder().individual().build()) - .respondent1DQ(Respondent1DQ.builder() - .respondent1DQExperts(Experts.builder() - .details(wrapElements(Expert.builder().build())).build()) - .build()) - .respondent2(PartyBuilder.builder().individual().build()) - .respondent2Copy(PartyBuilder.builder().individual().build()) - .respondent2DQ(Respondent2DQ.builder().build()) - .claimant1ClaimResponseTypeForSpec(FULL_DEFENCE) - .claimant2ClaimResponseTypeForSpec(FULL_ADMISSION) - .ccdCaseReference(354L) - .respondent1ResponseDate(dateTime).build().toBuilder() - .addApplicant2(YES) - .build(); + @Test + void updateRespondent2AddressWhenSpecAoSRespondent2HomeAddressRequiredIsNotNO() { + // Given + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(mockedStateFlow.isFlagSet(any())).thenReturn(true); + when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + Party partyWithPrimaryAddress = PartyBuilder.builder().individual().build(); + partyWithPrimaryAddress.setPrimaryAddress(AddressBuilder.maximal() + .addressLine1("address line 1") + .addressLine2("address line 2") + .addressLine3("address line 3") + .build()); - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); + CaseData caseData = CaseDataBuilder.builder().atStateApplicantRespondToDefenceAndProceed() + .respondent2DQ() + .respondent1Copy(PartyBuilder.builder().individual().build()) + .addRespondent2(YES) + .respondent2(PartyBuilder.builder().individual().build()) + .respondent2Copy(PartyBuilder.builder().individual().build()) + .atSpecAoSRespondent2HomeAddressRequired(YES) + .build(); - // Then - assertThat(response.getData().get("respondent1DQExperts")).isNotNull(); - assertThat(response.getData().get("respondent2DQExperts")).isNull(); + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle( + callbackParamsOf(caseData, ABOUT_TO_SUBMIT)); + // Then + assertThat(response.getData()) + .extracting("respondent2") + .extracting("primaryAddress") + .extracting("AddressLine1") + .isEqualTo("address line 1"); + assertThat(response.getData()) + .extracting("respondent2") + .extracting("primaryAddress") + .extracting("AddressLine2") + .isEqualTo("address line 2"); + assertThat(response.getData()) + .extracting("respondent2") + .extracting("primaryAddress") + .extracting("AddressLine3") + .isEqualTo("address line 3"); + } } @Test - void shouldUpdateExpertEvents_whenInvokedAndUpdateContactDetailsEnabled_FullAdmission() { + void defendantResponsePopulatesWitnessesData() { // Given LocalDateTime dateTime = LocalDateTime.of(2023, 6, 6, 6, 6, 6); + LocalDate date = dateTime.toLocalDate(); when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(time.now()).thenReturn(dateTime); when(mockedStateFlow.isFlagSet(any())).thenReturn(true); when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); - when(toggleService.isUpdateContactDetailsEnabled()).thenReturn(true); - - CaseData caseData = CaseData.builder() - .respondent1(PartyBuilder.builder().individual().build()) + when(toggleService.isHmcEnabled()).thenReturn(true); + + Witnesses res1witnesses = Witnesses.builder().details( + wrapElements( + Witness.builder() + .firstName("Witness") + .lastName("One") + .emailAddress("test-witness-one@example.com") + .phoneNumber("07865456789") + .reasonForWitness("great reasons") + .eventAdded("Defendant Response Event") + .dateAdded(date) + .build()) + ).build(); + + Witnesses res2witnesses = Witnesses.builder().details( + wrapElements( + Witness.builder() + .firstName("Witness") + .lastName("Two") + .emailAddress("test-witness-two@example.com") + .phoneNumber("07532628263") + .reasonForWitness("good reasons") + .eventAdded("Defendant Response Event") + .dateAdded(date) + .build()) + ).build(); + + CaseData caseData = CaseDataBuilder.builder().atStateApplicantRespondToDefenceAndProceed() + .respondent2DQ() .respondent1Copy(PartyBuilder.builder().individual().build()) - .respondent1DQ(Respondent1DQ.builder() - .respondent1DQExperts(Experts.builder() - .details(wrapElements(Expert.builder().build())).build()) - .build()) + .atSpecAoSApplicantCorrespondenceAddressRequired(YES) + .addRespondent2(YES) .respondent2(PartyBuilder.builder().individual().build()) .respondent2Copy(PartyBuilder.builder().individual().build()) - .respondent2DQ(Respondent2DQ.builder().build()) - .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_ADMISSION) - .respondent2ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_ADMISSION) - .ccdCaseReference(354L) - .respondent1ResponseDate(dateTime).build().toBuilder() - .build(); + .atSpecAoSRespondent2HomeAddressRequired(NO) + .atSpecAoSRespondent2HomeAddressDetails(AddressBuilder.maximal().build()) + .build().toBuilder() + .respondent1DQWitnessesSmallClaim(res1witnesses) + .respondent2DQWitnessesSmallClaim(res2witnesses) + .build().toBuilder() + .respondent2ResponseDate(dateTime) + .respondent1ResponseDate(dateTime).build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(deadlinesCalculator.calculateApplicantResponseDeadlineSpec(any(), any())) + .thenReturn(LocalDateTime.now()); // When AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler .handle(params); - // Then - assertThat(response.getData().get("respondent1DQExperts")).isNotNull(); - assertThat(response.getData().get("respondent2DQExperts")).isNull(); - - } - - @Test - void shouldUpdateExpertEvents_whenInvokedAndUpdateContactDetailsEnabled() { - // Given - LocalDateTime dateTime = LocalDateTime.of(2023, 6, 6, 6, 6, 6); - when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); - when(mockedStateFlow.isFlagSet(any())).thenReturn(true); - when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); - when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); - when(toggleService.isUpdateContactDetailsEnabled()).thenReturn(true); - - CaseData caseData = CaseData.builder() - .respondent1(PartyBuilder.builder().individual().build()) - .respondent1Copy(PartyBuilder.builder().individual().build()) - .respondent1DQ(Respondent1DQ.builder() - .respondent1DQExperts(Experts.builder() - .details(wrapElements(Expert.builder().build())).build()) - .build()) - .respondent2(PartyBuilder.builder().individual().build()) - .respondent2Copy(PartyBuilder.builder().individual().build()) - .respondent2DQ(Respondent2DQ.builder().build()) - .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_DEFENCE) - .respondent2ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_DEFENCE) - .ccdCaseReference(354L) - .respondent1ResponseDate(dateTime).build().toBuilder() - .build(); - - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); + var objectMapper = new ObjectMapper(); + objectMapper.findAndRegisterModules(); + objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); // Then - assertThat(response.getData().get("respondent1DQExperts")).isNotNull(); - assertThat(response.getData().get("respondent2DQExperts")).isNull(); - } - - @Test - void shouldUpdateExpertEvents_whenInvokedAndUpdateContactDetailsEnabled_V2DraftDirections() { - // Given - LocalDateTime dateTime = LocalDateTime.of(2023, 6, 6, 6, 6, 6); - when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); - when(mockedStateFlow.isFlagSet(any())).thenReturn(true); - when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); - when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); - when(toggleService.isUpdateContactDetailsEnabled()).thenReturn(true); - - CaseData caseData = CaseData.builder() - .respondent1(PartyBuilder.builder().individual().build()) - .respondent1Copy(PartyBuilder.builder().individual().build()) - .respondent1DQ(Respondent1DQ.builder() - .respondent1DQExperts(Experts.builder() - .details(wrapElements(Expert.builder().build())).build()) - .build()) - .respondent2(PartyBuilder.builder().individual().build()) - .respondent2Copy(PartyBuilder.builder().individual().build()) - .respondent2DQ(Respondent2DQ.builder() - .respondent2DQDraftDirections(Document.builder().build()).build()) - .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_DEFENCE) - .respondent2ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_DEFENCE) - .ccdCaseReference(354L) - .respondent1ResponseDate(dateTime).build().toBuilder() - .build(); - - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); - - // Then - assertThat(response.getData().get("respondent1DQExperts")).isNotNull(); - assertThat(response.getData().get("respondent2DQExperts")).isNull(); + Witnesses actualRespondent1DQWitnesses = objectMapper.convertValue(response.getData().get( + "respondent1DQWitnesses"), new TypeReference<>() { + }); + Witness actualRespondent1Witness = unwrapElements(actualRespondent1DQWitnesses.getDetails()).get(0); + assertThat(actualRespondent1Witness.getPartyID()).isNotNull(); + assertThat(actualRespondent1Witness.getFirstName()).isEqualTo("Witness"); + assertThat(actualRespondent1Witness.getLastName()).isEqualTo("One"); + assertThat(actualRespondent1Witness.getEmailAddress()).isEqualTo("test-witness-one@example.com"); + assertThat(actualRespondent1Witness.getPhoneNumber()).isEqualTo("07865456789"); + assertThat(actualRespondent1Witness.getReasonForWitness()).isEqualTo("great reasons"); + assertThat(actualRespondent1Witness.getEventAdded()).isEqualTo("Defendant Response Event"); + assertThat(actualRespondent1Witness.getDateAdded()).isEqualTo(date); + + Witnesses actualRespondent2DQWitnesses = objectMapper.convertValue(response.getData().get( + "respondent2DQWitnesses"), new TypeReference<>() { + }); + Witness respondent2Witness = unwrapElements(actualRespondent2DQWitnesses.getDetails()).get(0); + assertThat(respondent2Witness.getPartyID()).isNotNull(); + assertThat(respondent2Witness.getFirstName()).isEqualTo("Witness"); + assertThat(respondent2Witness.getLastName()).isEqualTo("Two"); + assertThat(respondent2Witness.getEmailAddress()).isEqualTo("test-witness-two@example.com"); + assertThat(respondent2Witness.getPhoneNumber()).isEqualTo("07532628263"); + assertThat(respondent2Witness.getReasonForWitness()).isEqualTo("good reasons"); + assertThat(respondent2Witness.getEventAdded()).isEqualTo("Defendant Response Event"); + assertThat(respondent2Witness.getDateAdded()).isEqualTo(date); } - @Test - void shouldUpdateWitnessEvents_whenInvokedAndUpdateContactDetailsEnabled() { - // Given - LocalDateTime dateTime = LocalDateTime.of(2023, 6, 6, 6, 6, 6); - when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); - when(mockedStateFlow.isFlagSet(any())).thenReturn(true); - when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); - when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); - when(toggleService.isUpdateContactDetailsEnabled()).thenReturn(true); - - CaseData caseData = CaseData.builder() - .respondent1(PartyBuilder.builder().individual().build()) - .respondent1Copy(PartyBuilder.builder().individual().build()) - .respondent1DQ(Respondent1DQ.builder() - .respondent1DQWitnesses(Witnesses.builder() - .details(wrapElements(Witness.builder().build())).build()) - .build()) - - .respondent2(PartyBuilder.builder().individual().build()) - .respondent2Copy(PartyBuilder.builder().individual().build()) - .respondent2DQ(Respondent2DQ.builder().build()) - .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_DEFENCE) - .respondent2ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_DEFENCE) - .ccdCaseReference(354L) - .respondent1ResponseDate(dateTime).build().toBuilder() - .build(); - - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + @Nested + class HandleLocations { - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); + @Test + void oneVOne() { + // Given + DynamicList locationValues = DynamicList.fromList(List.of("Value 1")); + DynamicList preferredCourt = DynamicList.builder() + .listItems(locationValues.getListItems()) + .value(locationValues.getListItems().get(0)) + .build(); + Party defendant1 = Party.builder() + .type(Party.Type.COMPANY) + .companyName("company") + .build(); + CaseData caseData = CaseData.builder() + .caseAccessCategory(SPEC_CLAIM) + .ccdCaseReference(354L) + .respondent1(defendant1) + .respondent1Copy(defendant1) + .respondent1DQ( + Respondent1DQ.builder() + .respondToCourtLocation( + RequestedCourt.builder() + .responseCourtLocations(preferredCourt) + .reasonForHearingAtSpecificCourt("Reason") + .build() + ) + .build() + ) + .showConditionFlags(EnumSet.of( + DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_1 + )) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - // Then - assertThat(response.getData().get("respondent1DQWitnesses")).isNotNull(); - assertThat(response.getData().get("respondent2DQWitnesses")).isNull(); + List locations = List.of(LocationRefData.builder().build()); + when(locationRefDataService.getCourtLocationsForDefaultJudgments(any())) + .thenReturn(locations); + LocationRefData completePreferredLocation = LocationRefData.builder() + .regionId("regionId") + .epimmsId("epimms") + .courtLocationCode("code") + .build(); + when(courtLocationUtils.findPreferredLocationData( + locations, preferredCourt + )).thenReturn(completePreferredLocation); + StateFlow flow = mock(StateFlow.class); + when(flow.isFlagSet(FlowFlag.TWO_RESPONDENT_REPRESENTATIVES)).thenReturn(false); + when(stateFlowEngine.evaluate(caseData)) + .thenReturn(flow); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), any(CaseRole.class))) + .thenReturn(true); + UserInfo userInfo = UserInfo.builder().uid("798").build(); + when(userService.getUserInfo(anyString())).thenReturn(userInfo); - } + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); - @Test - void shouldUpdateCorrespondence1_whenProvided() { - // Given - when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); - when(mockedStateFlow.isFlagSet(any())).thenReturn(true); - when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); - when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORONE))).thenReturn(true); - when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(false); - when(toggleService.isCaseFileViewEnabled()).thenReturn(true); - var testDocument = ResponseDocument.builder() - .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl("binary-url").build()).build(); + // Then + AbstractObjectAssert sent1 = assertThat(response.getData()) + .extracting("respondent1DQRequestedCourt"); + sent1.extracting("caseLocation") + .extracting("region") + .isEqualTo(completePreferredLocation.getRegionId()); + sent1.extracting("caseLocation") + .extracting("baseLocation") + .isEqualTo(completePreferredLocation.getEpimmsId()); + sent1.extracting("responseCourtCode") + .isEqualTo(completePreferredLocation.getCourtLocationCode()); + sent1.extracting("reasonForHearingAtSpecificCourt") + .isEqualTo("Reason"); + } - CaseData caseData = CaseData.builder() - .respondent1(PartyBuilder.builder().individual().build()) - .respondent1Copy(PartyBuilder.builder().individual().build()) - .respondent1DQ(Respondent1DQ.builder().build()) - .respondent2DQ(Respondent2DQ.builder().build()) - .ccdCaseReference(354L) - .respondent1SpecDefenceResponseDocument(testDocument) - .respondent2SpecDefenceResponseDocument(testDocument) - .isRespondent1(YesOrNo.YES) - .respondentSolicitor1ServiceAddressRequired(YesOrNo.NO) - .respondentSolicitor1ServiceAddress( - Address.builder() - .postCode("new postcode") - .build() - ) - .build(); + @Test + void oneVTwo_SecondDefendantRepliesSameLegalRep() { + // Given + DynamicList locationValues = DynamicList.fromList(List.of("Value 1")); + DynamicList preferredCourt = DynamicList.builder() + .listItems(locationValues.getListItems()) + .value(locationValues.getListItems().get(0)) + .build(); + Party defendant1 = Party.builder() + .type(Party.Type.COMPANY) + .companyName("company") + .build(); + CaseData caseData = CaseData.builder() + .respondent2SameLegalRepresentative(YES) + .caseAccessCategory(SPEC_CLAIM) + .ccdCaseReference(354L) + .defenceAdmitPartPaymentTimeRouteRequired(IMMEDIATELY) + .respondent2ClaimResponseTypeForSpec(FULL_ADMISSION) + .respondent1(defendant1) + .respondent1Copy(defendant1) + .respondent1DQ( + Respondent1DQ.builder() + .respondToCourtLocation( + RequestedCourt.builder() + .responseCourtLocations(preferredCourt) + .reasonForHearingAtSpecificCourt("Reason") + .build() + ) + .build() + ) + .respondent2DQ( + Respondent2DQ.builder() + .respondToCourtLocation2( + RequestedCourt.builder() + .responseCourtLocations(preferredCourt) + .reasonForHearingAtSpecificCourt("Reason123") + .build() + ) + .build() + ) + .showConditionFlags(EnumSet.of( + DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_1, + DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_2 + )) + .build(); - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + List locations = List.of(LocationRefData.builder().build()); + when(locationRefDataService.getCourtLocationsForDefaultJudgments(any())) + .thenReturn(locations); + LocationRefData completePreferredLocation = LocationRefData.builder() + .regionId("regionId") + .epimmsId("epimms") + .courtLocationCode("code") + .build(); + when(courtLocationUtils.findPreferredLocationData( + locations, preferredCourt + )).thenReturn(completePreferredLocation); + StateFlow flow = mock(StateFlow.class); + when(flow.isFlagSet(FlowFlag.TWO_RESPONDENT_REPRESENTATIVES)).thenReturn(true); + when(stateFlowEngine.evaluate(caseData)).thenReturn(flow); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), any(CaseRole.class))) + .thenReturn(true); + UserInfo userInfo = UserInfo.builder().uid("798").build(); + when(userService.getUserInfo(anyString())).thenReturn(userInfo); + LocalDate whenWillPay = LocalDate.now().plusDays(5); + given(deadlineExtensionCalculatorService.calculateExtendedDeadline(any(), anyInt())).willReturn(whenWillPay); - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - // Then - assertThat(response.getData().get("specRespondentCorrespondenceAddressdetails")) - .extracting("PostCode") - .isEqualTo("new postcode"); - assertThat(response.getData().get("respondentSolicitor1ServiceAddress")) - .extracting("PostCode") - .isNull(); - } + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - @Test - void shouldUpdateCorrespondence1_whenProvided1v2ss() { - // Given - when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); - when(mockedStateFlow.isFlagSet(any())).thenReturn(true); - when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); - when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORONE))).thenReturn(true); - when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(false); - when(toggleService.isCaseFileViewEnabled()).thenReturn(true); - var testDocument = ResponseDocument.builder() - .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl("binary-url").build()).build(); + // Then + AbstractObjectAssert sent2 = assertThat(response.getData()) + .extracting("respondent2DQRequestedCourt"); + sent2.extracting("caseLocation") + .extracting("region") + .isEqualTo(completePreferredLocation.getRegionId()); + sent2.extracting("caseLocation") + .extracting("baseLocation") + .isEqualTo(completePreferredLocation.getEpimmsId()); + sent2.extracting("responseCourtCode") + .isEqualTo(completePreferredLocation.getCourtLocationCode()); + sent2.extracting("reasonForHearingAtSpecificCourt") + .isEqualTo("Reason123"); + } - CaseData caseData = CaseData.builder() - .respondent1(PartyBuilder.builder().individual().build()) - .respondent1Copy(PartyBuilder.builder().individual().build()) - .respondent1DQ(Respondent1DQ.builder().build()) - .respondent2DQ(Respondent2DQ.builder().build()) - .ccdCaseReference(354L) - .respondent1SpecDefenceResponseDocument(testDocument) - .respondent2SpecDefenceResponseDocument(testDocument) - .isRespondent1(YesOrNo.YES) - .respondentSolicitor1ServiceAddressRequired(YesOrNo.NO) - .respondentSolicitor1ServiceAddress( - Address.builder() - .postCode("new postcode") - .build() - ) - .respondent2(Party.builder() - .type(Party.Type.COMPANY) - .companyName("Company 3") - .build()) - .respondent2SameLegalRepresentative(YES) - .build(); + @Test + void oneVTwo_SecondDefendantReplies() { + // Given + DynamicList locationValues = DynamicList.fromList(List.of("Value 1")); + DynamicList preferredCourt = DynamicList.builder() + .listItems(locationValues.getListItems()) + .value(locationValues.getListItems().get(0)) + .build(); + Party defendant1 = Party.builder() + .type(Party.Type.COMPANY) + .companyName("company") + .build(); + CaseData caseData = CaseData.builder() + .caseAccessCategory(SPEC_CLAIM) + .ccdCaseReference(354L) + .respondent1(defendant1) + .respondent1Copy(defendant1) + .respondent1DQ( + Respondent1DQ.builder() + .respondToCourtLocation( + RequestedCourt.builder() + .responseCourtLocations(preferredCourt) + .reasonForHearingAtSpecificCourt("Reason") + .build() + ) + .build() + ) + .respondent2DQ( + Respondent2DQ.builder() + .respondToCourtLocation2( + RequestedCourt.builder() + .responseCourtLocations(preferredCourt) + .reasonForHearingAtSpecificCourt("Reason123") + .build() + ) + .build() + ) + .showConditionFlags(EnumSet.of( + DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_1, + DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_2 + )) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + List locations = List.of(LocationRefData.builder().build()); + when(locationRefDataService.getCourtLocationsForDefaultJudgments(any())) + .thenReturn(locations); + LocationRefData completePreferredLocation = LocationRefData.builder() + .regionId("regionId") + .epimmsId("epimms") + .courtLocationCode("code") + .build(); + when(courtLocationUtils.findPreferredLocationData( + locations, preferredCourt + )).thenReturn(completePreferredLocation); + StateFlow flow = mock(StateFlow.class); + when(flow.isFlagSet(FlowFlag.TWO_RESPONDENT_REPRESENTATIVES)).thenReturn(true); + when(stateFlowEngine.evaluate(caseData)).thenReturn(flow); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), any(CaseRole.class))) + .thenReturn(true); + UserInfo userInfo = UserInfo.builder().uid("798").build(); + when(userService.getUserInfo(anyString())).thenReturn(userInfo); - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); - // Then - assertThat(response.getData().get("specRespondentCorrespondenceAddressdetails")) - .extracting("PostCode") - .isEqualTo("new postcode"); - assertThat(response.getData().get("respondentSolicitor1ServiceAddress")) - .extracting("PostCode") - .isNull(); - assertEquals( - response.getData().get("specRespondentCorrespondenceAddressdetails"), - response.getData().get("specRespondent2CorrespondenceAddressdetails") - ); - assertEquals( - response.getData().get("specRespondentCorrespondenceAddressRequired"), - response.getData().get("specRespondent2CorrespondenceAddressRequired") - ); + // Then + AbstractObjectAssert sent2 = assertThat(response.getData()) + .extracting("respondent2DQRequestedCourt"); + sent2.extracting("caseLocation") + .extracting("region") + .isEqualTo(completePreferredLocation.getRegionId()); + sent2.extracting("caseLocation") + .extracting("baseLocation") + .isEqualTo(completePreferredLocation.getEpimmsId()); + sent2.extracting("responseCourtCode") + .isEqualTo(completePreferredLocation.getCourtLocationCode()); + sent2.extracting("reasonForHearingAtSpecificCourt") + .isEqualTo("Reason123"); + } } @Test - void shouldUpdateCorrespondence1_whenProvided1v2ss_withSameResponse() { + void shouldNullDocuments_whenInvokedAndCaseFileEnabled() { // Given when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); when(mockedStateFlow.isFlagSet(any())).thenReturn(true); when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); - when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORONE))).thenReturn(true); - when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(false); + when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); when(toggleService.isCaseFileViewEnabled()).thenReturn(true); var testDocument = ResponseDocument.builder() - .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl("binary-url").build()).build(); + .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl( + "binary-url").build()).build(); CaseData caseData = CaseData.builder() .respondent1(PartyBuilder.builder().individual().build()) @@ -1598,19 +1231,6 @@ void shouldUpdateCorrespondence1_whenProvided1v2ss_withSameResponse() { .ccdCaseReference(354L) .respondent1SpecDefenceResponseDocument(testDocument) .respondent2SpecDefenceResponseDocument(testDocument) - .isRespondent1(YesOrNo.YES) - .respondentResponseIsSame(YES) - .respondentSolicitor1ServiceAddressRequired(YesOrNo.NO) - .respondentSolicitor1ServiceAddress( - Address.builder() - .postCode("new postcode") - .build() - ) - .respondent2(Party.builder() - .type(Party.Type.COMPANY) - .companyName("Company 3") - .build()) - .respondent2SameLegalRepresentative(YES) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); @@ -1620,24 +1240,12 @@ void shouldUpdateCorrespondence1_whenProvided1v2ss_withSameResponse() { .handle(params); // Then - assertThat(response.getData().get("specRespondentCorrespondenceAddressdetails")) - .extracting("PostCode") - .isEqualTo("new postcode"); - assertThat(response.getData().get("respondentSolicitor1ServiceAddress")) - .extracting("PostCode") - .isNull(); - assertEquals( - response.getData().get("specRespondentCorrespondenceAddressdetails"), - response.getData().get("specRespondent2CorrespondenceAddressdetails") - ); - assertEquals( - response.getData().get("specRespondentCorrespondenceAddressRequired"), - response.getData().get("specRespondent2CorrespondenceAddressRequired") - ); + assertThat(response.getData().get("respondent1SpecDefenceResponseDocument")).isNull(); + assertThat(response.getData().get("respondent2SpecDefenceResponseDocument")).isNull(); } @Test - void shouldUpdateCorrespondence1_whenProvided1v2ss_withSameResponse_withv2copy() { + void shouldUpdateCorrespondence1_whenProvided() { // Given when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); when(mockedStateFlow.isFlagSet(any())).thenReturn(true); @@ -1646,7 +1254,8 @@ void shouldUpdateCorrespondence1_whenProvided1v2ss_withSameResponse_withv2copy() when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(false); when(toggleService.isCaseFileViewEnabled()).thenReturn(true); var testDocument = ResponseDocument.builder() - .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl("binary-url").build()).build(); + .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl( + "binary-url").build()).build(); CaseData caseData = CaseData.builder() .respondent1(PartyBuilder.builder().individual().build()) @@ -1657,19 +1266,12 @@ void shouldUpdateCorrespondence1_whenProvided1v2ss_withSameResponse_withv2copy() .respondent1SpecDefenceResponseDocument(testDocument) .respondent2SpecDefenceResponseDocument(testDocument) .isRespondent1(YesOrNo.YES) - .respondentResponseIsSame(YES) - .respondentSolicitor1ServiceAddressRequired(YesOrNo.NO) - .respondentSolicitor1ServiceAddress( + .specAoSRespondentCorrespondenceAddressRequired(YesOrNo.NO) + .specAoSRespondentCorrespondenceAddressdetails( Address.builder() .postCode("new postcode") .build() ) - .respondent2(Party.builder() - .type(Party.Type.COMPANY) - .companyName("Company 3") - .build()) - .respondent2Copy(PartyBuilder.builder().individual().build()) - .respondent2SameLegalRepresentative(YES) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); @@ -1682,21 +1284,13 @@ void shouldUpdateCorrespondence1_whenProvided1v2ss_withSameResponse_withv2copy() assertThat(response.getData().get("specRespondentCorrespondenceAddressdetails")) .extracting("PostCode") .isEqualTo("new postcode"); - assertThat(response.getData().get("respondentSolicitor1ServiceAddress")) + assertThat(response.getData().get("specAoSRespondentCorrespondenceAddressdetails")) .extracting("PostCode") .isNull(); - assertEquals( - response.getData().get("specRespondentCorrespondenceAddressdetails"), - response.getData().get("specRespondent2CorrespondenceAddressdetails") - ); - assertEquals( - response.getData().get("specRespondentCorrespondenceAddressRequired"), - response.getData().get("specRespondent2CorrespondenceAddressRequired") - ); } @Test - void shouldUpdateCorrespondence1_whenProvided1v2ss_withSameResponse_withv2copyAndNoTempAdr() { + void shouldUpdateCorrespondence1_whenProvided1v2ss() { // Given when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); when(mockedStateFlow.isFlagSet(any())).thenReturn(true); @@ -1705,7 +1299,8 @@ void shouldUpdateCorrespondence1_whenProvided1v2ss_withSameResponse_withv2copyAn when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(false); when(toggleService.isCaseFileViewEnabled()).thenReturn(true); var testDocument = ResponseDocument.builder() - .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl("binary-url").build()).build(); + .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl( + "binary-url").build()).build(); CaseData caseData = CaseData.builder() .respondent1(PartyBuilder.builder().individual().build()) @@ -1716,9 +1311,8 @@ void shouldUpdateCorrespondence1_whenProvided1v2ss_withSameResponse_withv2copyAn .respondent1SpecDefenceResponseDocument(testDocument) .respondent2SpecDefenceResponseDocument(testDocument) .isRespondent1(YesOrNo.YES) - .respondentResponseIsSame(YES) - .respondentSolicitor1ServiceAddressRequired(YesOrNo.NO) - .respondentSolicitor1ServiceAddress( + .specAoSRespondentCorrespondenceAddressRequired(YesOrNo.NO) + .specAoSRespondentCorrespondenceAddressdetails( Address.builder() .postCode("new postcode") .build() @@ -1727,9 +1321,7 @@ void shouldUpdateCorrespondence1_whenProvided1v2ss_withSameResponse_withv2copyAn .type(Party.Type.COMPANY) .companyName("Company 3") .build()) - .respondent2Copy(PartyBuilder.builder().individual().build()) .respondent2SameLegalRepresentative(YES) - .tempCorrespondenceAddress2Required(NO) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); @@ -1742,7 +1334,7 @@ void shouldUpdateCorrespondence1_whenProvided1v2ss_withSameResponse_withv2copyAn assertThat(response.getData().get("specRespondentCorrespondenceAddressdetails")) .extracting("PostCode") .isEqualTo("new postcode"); - assertThat(response.getData().get("respondentSolicitor1ServiceAddress")) + assertThat(response.getData().get("specAoSRespondentCorrespondenceAddressdetails")) .extracting("PostCode") .isNull(); assertEquals( @@ -1764,21 +1356,20 @@ void shouldUpdateCorrespondence2_whenProvided() { when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); when(toggleService.isCaseFileViewEnabled()).thenReturn(true); var testDocument = ResponseDocument.builder() - .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl("binary-url").build()).build(); + .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl( + "binary-url").build()).build(); CaseData caseData = CaseData.builder() .respondent1(PartyBuilder.builder().individual().build()) .respondent1Copy(PartyBuilder.builder().individual().build()) .respondent1DQ(Respondent1DQ.builder().build()) - .respondent2(PartyBuilder.builder().individual().build()) - .respondent2Copy(PartyBuilder.builder().individual().build()) .respondent2DQ(Respondent2DQ.builder().build()) .ccdCaseReference(354L) .respondent1SpecDefenceResponseDocument(testDocument) .respondent2SpecDefenceResponseDocument(testDocument) .isRespondent2(YesOrNo.YES) - .respondentSolicitor2ServiceAddressRequired(YesOrNo.NO) - .respondentSolicitor2ServiceAddress( + .specAoSRespondent2CorrespondenceAddressRequired(YesOrNo.NO) + .specAoSRespondent2CorrespondenceAddressdetails( Address.builder() .postCode("new postcode") .build() @@ -1795,7 +1386,7 @@ void shouldUpdateCorrespondence2_whenProvided() { assertThat(response.getData().get("specRespondent2CorrespondenceAddressdetails")) .extracting("PostCode") .isEqualTo("new postcode"); - assertThat(response.getData().get("respondentSolicitor2ServiceAddress")) + assertThat(response.getData().get("specAoSRespondent2CorrespondenceAddressdetails")) .extracting("PostCode") .isNull(); } @@ -1825,58 +1416,6 @@ void shouldPopulateRespondent2Flag_WhenInvoked() { assertThat(response.getData().get("respondent2DocumentGeneration")).isEqualTo("userRespondent2"); } - @Test - void shouldPopulateRespondent2Flag_WhenInvokedWithSmallClaimExperts_1DQ() { - // Given - when(toggleService.isCaseFileViewEnabled()).thenReturn(true); - when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); - when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); - given(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).willReturn(true); - given(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORONE))).willReturn(false); - CaseData caseData = CaseDataBuilder.builder() - .atStateClaimDetailsNotified() - .respondent2(PartyBuilder.builder().individual().build()) - .addRespondent2(YES) - .respondent1(PartyBuilder.builder().individual().build()) - .respondent1Copy(PartyBuilder.builder().individual().build()) - .respondent1DQ(Respondent1DQ.builder() - .respondToClaimExperts(ExpertDetails.builder().build()).build()) - .respondent2DQ(Respondent2DQ.builder().build()) - .build(); - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); - // Given - assertThat(response.getData().get("respondent2DocumentGeneration")).isEqualTo("userRespondent2"); - } - - @Test - void shouldPopulateRespondent2Flag_WhenInvokedWithSmallClaimExperts_2DQ() { - // Given - when(toggleService.isCaseFileViewEnabled()).thenReturn(true); - when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); - when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); - given(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).willReturn(true); - given(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORONE))).willReturn(false); - CaseData caseData = CaseDataBuilder.builder() - .atStateClaimDetailsNotified() - .respondent2(PartyBuilder.builder().individual().build()) - .addRespondent2(YES) - .respondent1(PartyBuilder.builder().individual().build()) - .respondent1Copy(PartyBuilder.builder().individual().build()) - .respondent2DQ(Respondent2DQ.builder() - .respondToClaimExperts2(ExpertDetails.builder().build()).build()) - .respondent1DQ(Respondent1DQ.builder().build()) - .build(); - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); - // Given - assertThat(response.getData().get("respondent2DocumentGeneration")).isEqualTo("userRespondent2"); - } - @Test void shouldNotPopulateRespondent2Flag_WhenInvoked() { // Given @@ -1939,26 +1478,6 @@ void shouldSetMultiPartyResponseTypeFlags_Counter_Admit_OR_Admit_Part_combinatio .isEqualTo("COUNTER_ADMIT_OR_ADMIT_PART"); } - @Test - void shouldSetMultiPartyResponseTypeFlags_Counter_Admit_OR_Admit_Part_combination2_CanAddApplicant2() { - // Given - CaseData caseData = CaseDataBuilder.builder().atStateRespondent2v1BothNotFullDefence_CounterClaimX2() - .addApplicant2(YES) - .respondent1ClaimResponseTypeForSpec(FULL_ADMISSION) - .respondent1ClaimResponseTypeForSpec(FULL_ADMISSION) - .build(); - - CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID); - - // When - var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - - // Then - assertThat(response.getData()).extracting("multiPartyResponseTypeFlags") - .isEqualTo("COUNTER_ADMIT_OR_ADMIT_PART"); - } - - /** * if solicitor says that each defendant gets their response but then chooses the same * option from full defence/part admit/full admit/counterclaim, then it is not different response. @@ -2049,6 +1568,7 @@ void shouldReturnError_whenWitnessRequiredAndNullDetails() { void shouldReturnNoError_whenWitnessRequiredAndDetailsProvided() { // Given List> testWitness = wrapElements(Witness.builder().name("test witness").build()); + Witnesses witnesses = Witnesses.builder().witnessesToAppear(YES).details(testWitness).build(); CaseData caseData = CaseDataBuilder.builder() .respondent1DQ(Respondent1DQ.builder().build()) .respondent1DQWitnessesRequiredSpec(YES) @@ -2137,6 +1657,9 @@ void specificSummary_whenPartialAdmitNotPay() { // When SubmittedCallbackResponse response = (SubmittedCallbackResponse) handler.handle(params); + LocalDateTime responseDeadline = caseData.getApplicant1ResponseDeadline(); + String claimNumber = caseData.getLegacyCaseReference(); + // Then assertThat(response.getConfirmationBody()) .contains(caseData.getApplicant1().getPartyName()) @@ -2544,12 +2067,12 @@ void whenProvided_thenValidateCorrespondence1() { CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build() .toBuilder() .isRespondent1(YES) - .respondentSolicitor1ServiceAddressRequired(YesOrNo.NO) - .respondentSolicitor1ServiceAddress(Address.builder() + .specAoSRespondentCorrespondenceAddressRequired(YesOrNo.NO) + .specAoSRespondentCorrespondenceAddressdetails(Address.builder() .postCode("postal code") .build()) .build(); - CallbackParams params = callbackParamsOf(caseData, MID, "specCorrespondenceAddress"); + CallbackParams params = callbackParamsOf(caseData, MID, "confirm-details"); when(postcodeValidator.validate("postal code")).thenReturn(Collections.emptyList()); // When @@ -2566,12 +2089,12 @@ void whenProvided_thenValidateCorrespondence2() { CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build() .toBuilder() .isRespondent2(YES) - .respondentSolicitor2ServiceAddressRequired(YesOrNo.NO) - .respondentSolicitor2ServiceAddress(Address.builder() - .postCode("postal code") - .build()) + .specAoSRespondent2CorrespondenceAddressRequired(YesOrNo.NO) + .specAoSRespondent2CorrespondenceAddressdetails(Address.builder() + .postCode("postal code") + .build()) .build(); - CallbackParams params = callbackParamsOf(caseData, MID, "specCorrespondenceAddress"); + CallbackParams params = callbackParamsOf(caseData, MID, "confirm-details"); when(postcodeValidator.validate("postal code")).thenReturn(Collections.emptyList()); // When @@ -2801,55 +2324,10 @@ public void shouldThrowError_whenValidateRespondentExpertsMultipartyWithNoUnavai // Then assertThat(response.getErrors()).isNotEmpty(); } - - @Test - public void shouldThrowError_whenValidateRespondentExpertsMultipartyWithNoUnavailableDates_DisputesTheClaim() { - // Given - CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified() - .responseClaimTrack(SpecJourneyConstantLRSpec.DISPUTES_THE_CLAIM) - .respondent1DQ(Respondent1DQ.builder() - .respondent1DQHearingSmallClaim(SmallClaimHearing.builder().unavailableDatesRequired( - YES).build()).build()) - .build(); - List errors = Collections.singletonList("error 1"); - Mockito.when(dateValidator.validateFastClaimHearing(any())).thenReturn(errors); - CallbackParams params = callbackParamsOf(caseData, MID, "validate-unavailable-dates"); - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); - - // Then - assertThat(response.getErrors()).isNotEmpty(); - } - - @Test - public void shouldThrowError_whenValidateRespondentExpertsMultipartyWithNoUnavailableDates_V2() { - // Given - CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified() - .responseClaimTrack(SpecJourneyConstantLRSpec.SMALL_CLAIM) - .respondent1DQ(Respondent1DQ.builder() - .respondent1DQHearingSmallClaim(SmallClaimHearing.builder().unavailableDatesRequired( - YES).build()).build()) - .respondent2DQ(Respondent2DQ.builder() - .respondent2DQHearingSmallClaim(SmallClaimHearing.builder().unavailableDatesRequired( - YES).build()).build()) - .isRespondent2(YES) - .build(); - List errors = Collections.singletonList("error 1"); - Mockito.when(dateValidator.validateSmallClaimsHearing(any())).thenReturn(errors); - CallbackParams params = callbackParamsOf(caseData, MID, "validate-unavailable-dates"); - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); - - // Then - assertThat(response.getErrors()).isNotEmpty(); - } } @Test void handleEventsReturnsTheExpectedCallbackEvents() { assertThat(handler.handledEvents()).containsOnly(DEFENDANT_RESPONSE_SPEC); } - } From 7e2e30e56f5e8a861e0bed8a8fb8e16ddcf425a6 Mon Sep 17 00:00:00 2001 From: hmcts-version1-ignacio <107860328+hmcts-version1-ignacio@users.noreply.github.com> Date: Wed, 15 Nov 2023 09:49:09 +0000 Subject: [PATCH 3/3] CIV-11150 flight delay screen (#3483) * CIV-11150 Add new handler * CIV-11150 Add new handler * CIV-11150 Fix sonar issues * CIV-11150 Add new test and new changes * CIV-11150 Add new test and new changes * CIV-11150 Fix sonar issue * CIV-11150 Add claimType modifyer --------- Co-authored-by: Azam <106387766+Azam-Hmcts@users.noreply.github.com> Co-authored-by: krishnanuthalapati <32389208+krishnanuthalapati@users.noreply.github.com> --- .../hmcts/reform/civil/enums/ClaimType.java | 3 +- .../user/CreateClaimSpecCallbackHandler.java | 19 ++++++++ .../hmcts/reform/civil/model/CaseData.java | 3 ++ .../civil/service/FeatureToggleService.java | 4 ++ .../CreateClaimSpecCallbackHandlerTest.java | 43 +++++++++++++++++++ .../service/FeatureToggleServiceTest.java | 9 ++++ 6 files changed, 80 insertions(+), 1 deletion(-) diff --git a/src/main/java/uk/gov/hmcts/reform/civil/enums/ClaimType.java b/src/main/java/uk/gov/hmcts/reform/civil/enums/ClaimType.java index 2f56dbbaeb5..37c90e0f65b 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/enums/ClaimType.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/enums/ClaimType.java @@ -12,7 +12,8 @@ public enum ClaimType { BREACH_OF_CONTRACT(FeeType.HIGHER), CONSUMER(FeeType.HIGHER), CONSUMER_CREDIT(FeeType.HIGHER), - OTHER(FeeType.HIGHER); + OTHER(FeeType.HIGHER), + FLIGHT_DELAY(null); private final FeeType feeType; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandler.java index ffc3d2b47b4..7dc8d457b95 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandler.java @@ -17,6 +17,7 @@ import uk.gov.hmcts.reform.civil.config.ToggleConfiguration; import uk.gov.hmcts.reform.civil.config.ClaimUrlsConfiguration; import uk.gov.hmcts.reform.civil.enums.CaseCategory; +import uk.gov.hmcts.reform.civil.enums.ClaimType; import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario; import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.model.Address; @@ -230,6 +231,7 @@ protected Map callbacks() { ) .put(callbackKey(MID, "validate-spec-defendant-legal-rep-email"), this::validateSpecRespondentRepEmail) .put(callbackKey(MID, "validate-spec-defendant2-legal-rep-email"), this::validateSpecRespondent2RepEmail) + .put(callbackKey(MID, "is-flight-delay-claim"), this::isFlightDelayClaim) .build(); } @@ -900,6 +902,23 @@ private CallbackResponse validateSpecRespondent2RepEmail(CallbackParams callback .build(); } + private CallbackResponse isFlightDelayClaim(CallbackParams callbackParams) { + CaseData.CaseDataBuilder caseDataBuilder = callbackParams.getCaseData().toBuilder(); + + if (toggleService.isSdoR2Enabled()) { + caseDataBuilder.isFlightDelayClaim(callbackParams.getCaseData().getIsFlightDelayClaim()); + if (callbackParams.getCaseData().getIsFlightDelayClaim().equals(YES)) { + caseDataBuilder.claimType(ClaimType.FLIGHT_DELAY); + } else { + caseDataBuilder.claimType(null); + } + } + + return AboutToStartOrSubmitCallbackResponse.builder() + .data(caseDataBuilder.build().toMap(objectMapper)) + .build(); + } + private CallbackResponse setRespondent2SameLegalRepToNo(CallbackParams callbackParams) { CaseData.CaseDataBuilder caseDataBuilder = callbackParams.getCaseData().toBuilder(); diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/CaseData.java b/src/main/java/uk/gov/hmcts/reform/civil/model/CaseData.java index 953b02321d3..96dd6656365 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/CaseData.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/CaseData.java @@ -635,6 +635,9 @@ public boolean hasNoOngoingBusinessProcess() { private final TransferCaseDetails transferCaseDetails; + //SDO-R2 + private YesOrNo isFlightDelayClaim; + /** * There are several fields that can hold the I2P of applicant1 depending * on multiparty scenario, which complicates all conditions depending on it. diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/FeatureToggleService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/FeatureToggleService.java index f4aa4bc5382..8b11403a6fc 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/FeatureToggleService.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/FeatureToggleService.java @@ -88,4 +88,8 @@ public boolean isCaseProgressionEnabled() { public boolean isEarlyAdoptersEnabled() { return featureToggleApi.isFeatureEnabled("early-adopters"); } + + public boolean isSdoR2Enabled() { + return featureToggleApi.isFeatureEnabled("isSdoR2Enabled"); + } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandlerTest.java index c3b3ccad55a..72f96b705a7 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandlerTest.java @@ -5,6 +5,8 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -1620,6 +1622,47 @@ void shouldReturnErrors_whenRequiredAddressIsYesAndNotValid() { } } + @Nested + class IsFlightDelayClaimMidCallback { + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void shouldSetIsFlightDelayClaim_whenPopulatedAndSdoR2Enabled(Boolean toggleStat) { + // Given + YesOrNo yesOrNo = toggleStat ? YES : NO; + CaseData caseData = CaseData.builder().isFlightDelayClaim(yesOrNo) + .build(); + + CallbackParams params = callbackParamsOf(caseData, MID, "is-flight-delay-claim"); + // When + when(toggleService.isSdoR2Enabled()).thenReturn(true); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + // Then + assertThat(response.getData()).containsEntry("isFlightDelayClaim", toggleStat ? "Yes" : "No"); + if (toggleStat) { + assertThat(response.getData()).containsEntry("claimType", "FLIGHT_DELAY"); + } else { + assertThat(response.getData()).doesNotHaveToString("claimType"); + } + } + + @Test + void shouldSetIsFlightDelayClaim_whenPopulatedAndSdoR2Disabled() { + // Given + CaseData caseData = CaseData.builder().isFlightDelayClaim(YES) + .build(); + + CallbackParams params = callbackParamsOf(caseData, MID, "is-flight-delay-claim"); + // When + when(toggleService.isSdoR2Enabled()).thenReturn(false); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + // Then + assertThat(response.getData()).doesNotHaveToString("isFlightDelayClaim"); + assertThat(response.getData()).doesNotHaveToString("claimType"); + } + } + @Nested class AboutToSubmitCallbackV1 { diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/FeatureToggleServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/FeatureToggleServiceTest.java index cba681c75a8..764bd837d0b 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/FeatureToggleServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/FeatureToggleServiceTest.java @@ -179,6 +179,15 @@ void shouldReturnCorrectValue_whenEarlyAdopterEnabled(Boolean toggleStat) { assertThat(featureToggleService.isEarlyAdoptersEnabled()).isEqualTo(toggleStat); } + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void shouldReturnCorrectValue_whenIsSdoR2Enabled(Boolean toggleStat) { + var sdoR2Key = "isSdoR2Enabled"; + givenToggle(sdoR2Key, toggleStat); + + assertThat(featureToggleService.isSdoR2Enabled()).isEqualTo(toggleStat); + } + private void givenToggle(String feature, boolean state) { when(featureToggleApi.isFeatureEnabled(eq(feature))) .thenReturn(state);