diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01067.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01067.docx index 1016e0a18c4..bf518dcc5e4 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01067.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01067.docx differ diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01068.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01068.docx index ca775174502..07e3a3b1e8c 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01068.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01068.docx differ diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01069.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01069.docx index fe1a842c34e..8a359232e14 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01069.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01069.docx differ diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01073.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01073.docx index e44df45adc1..75da4c61c2c 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01073.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01073.docx differ diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01075.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01075.docx index 52a6f485c03..6cd12684e8a 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01075.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01075.docx differ diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01076.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01076.docx index 9d6e2d9cb1d..8c4163027d4 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01076.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01076.docx differ diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01078.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01078.docx index 6ebdfc6bb62..40d0ed38627 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01078.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01078.docx differ diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/civil/controllers/cases/CasesControllerTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/civil/controllers/cases/CasesControllerTest.java index 4f9174d907a..627fda38600 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/civil/controllers/cases/CasesControllerTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/civil/controllers/cases/CasesControllerTest.java @@ -12,13 +12,12 @@ import uk.gov.hmcts.reform.civil.exceptions.CaseDataInvalidException; import uk.gov.hmcts.reform.civil.exceptions.CaseNotFoundException; import uk.gov.hmcts.reform.civil.exceptions.UserNotFoundOnCaseException; -import uk.gov.hmcts.reform.civil.exceptions.CaseNotFoundException; -import uk.gov.hmcts.reform.civil.exceptions.UserNotFoundOnCaseException; import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.bulkclaims.CaseworkerSubmitEventDTo; import uk.gov.hmcts.reform.civil.model.citizenui.DashboardClaimInfo; import uk.gov.hmcts.reform.civil.model.citizenui.DashboardResponse; +import uk.gov.hmcts.reform.civil.model.citizenui.dto.ExtendedDeadlineDto; import uk.gov.hmcts.reform.civil.model.citizenui.dto.EventDto; import uk.gov.hmcts.reform.civil.model.repaymentplan.ClaimantProposedPlan; import uk.gov.hmcts.reform.civil.service.CoreCaseDataService; @@ -42,6 +41,7 @@ import java.util.Map; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; @@ -228,10 +228,10 @@ void shouldSubmitEventSuccessfully() { @SneakyThrows void shouldCalculateDeadlineSuccessfully() { LocalDate extensionDate = LocalDate.of(2022, 6, 6); - when(deadlineExtensionCalculatorService.calculateExtendedDeadline(any())).thenReturn(extensionDate); + when(deadlineExtensionCalculatorService.calculateExtendedDeadline(any(), anyInt())).thenReturn(extensionDate); doPost( BEARER_TOKEN, - extensionDate, + ExtendedDeadlineDto.builder().responseDate(extensionDate).plusDays(5).build(), CALCULATE_DEADLINE_URL ) .andExpect(content().json(toJson(extensionDate))) diff --git a/src/main/java/uk/gov/hmcts/reform/civil/controllers/cases/CasesController.java b/src/main/java/uk/gov/hmcts/reform/civil/controllers/cases/CasesController.java index 47814b87877..b83ea9be12c 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/controllers/cases/CasesController.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/controllers/cases/CasesController.java @@ -24,6 +24,7 @@ import uk.gov.hmcts.reform.civil.exceptions.CaseDataInvalidException; import uk.gov.hmcts.reform.civil.model.bulkclaims.CaseworkerSubmitEventDTo; import uk.gov.hmcts.reform.civil.model.citizenui.DashboardResponse; +import uk.gov.hmcts.reform.civil.model.citizenui.dto.ExtendedDeadlineDto; import uk.gov.hmcts.reform.civil.model.citizenui.dto.EventDto; import uk.gov.hmcts.reform.civil.model.citizenui.dto.RepaymentDecisionType; import uk.gov.hmcts.reform.civil.model.repaymentplan.ClaimantProposedPlan; @@ -174,8 +175,9 @@ public ResponseEntity submitEvent( @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "401", description = "Not Authorized")}) - public ResponseEntity calculateNewResponseDeadline(@RequestBody LocalDate extendedDeadline) { - LocalDate calculatedDeadline = deadlineExtensionCalculatorService.calculateExtendedDeadline(extendedDeadline); + public ResponseEntity calculateNewResponseDeadline(@RequestBody ExtendedDeadlineDto deadlineDateDetails) { + LocalDate calculatedDeadline = deadlineExtensionCalculatorService.calculateExtendedDeadline( + deadlineDateDetails.getResponseDate(), deadlineDateDetails.getPlusDays()); return new ResponseEntity<>(calculatedDeadline, HttpStatus.OK); } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/TriggerGenAppLocationUpdateCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/TriggerGenAppLocationUpdateCallbackHandler.java index 6b392415a0c..6a7c730596d 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/TriggerGenAppLocationUpdateCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/TriggerGenAppLocationUpdateCallbackHandler.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Map; +import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.TRIGGER_LOCATION_UPDATE; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.TRIGGER_UPDATE_GA_LOCATION; @@ -44,9 +45,10 @@ public List handledEvents() { private CallbackResponse triggerGaEvent(CallbackParams callbackParams) { CaseData caseData = callbackParams.getCaseData(); + String authToken = callbackParams.getParams().get(BEARER_TOKEN).toString(); try { if (caseData.getGeneralApplications() != null && !caseData.getGeneralApplications().isEmpty()) { - caseData = helperService.updateApplicationLocationDetailsInClaim(caseData); + caseData = helperService.updateApplicationLocationDetailsInClaim(caseData, authToken); helperService.triggerEvent(caseData, TRIGGER_LOCATION_UPDATE); } } catch (Exception e) { diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadHandlerBase.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadHandlerBase.java index e69ffd03ba7..5277c8351c6 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadHandlerBase.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadHandlerBase.java @@ -118,23 +118,22 @@ abstract class EvidenceUploadHandlerBase extends CallbackHandler { protected static final String RESPONDENT_ONE_PRE_TRIAL_SUMMARY = "RespondentOnePreTrialSummary"; protected static final String RESPONDENT_ONE_TRIAL_SKELETON = "RespondentOneTrialSkeleton"; protected static final String RESPONDENT_ONE_PRECEDENT_H = "RespondentOneUploadedPrecedentH"; - protected static final String RESPONDENT_ONE_ANY_PRECEDENT_H = "respondentOneAnyPrecedentH"; protected static final String RESPONDENT_TWO_DISCLOSURE_LIST = "RespondentTwoDisclosureList"; protected static final String RESPONDENT_TWO_PRE_TRIAL_SUMMARY = "RespondentTwoPreTrialSummary"; protected static final String RESPONDENT_TWO_TRIAL_SKELETON = "RespondentTwoTrialSkeleton"; protected static final String RESPONDENT_TWO_PRECEDENT_H = "RespondentTwoUploadedPrecedentH"; - protected static final String RESPONDENT_TWO_ANY_PRECEDENT_H = "respondentTwoAnyPrecedentH"; + protected static final String RESPONDENT_ONE_SCHEDULE_OF_COSTS = "RespondentSchedulesOfCost"; + protected static final String RESPONDENT_TWO_SCHEDULE_OF_COSTS = "RespondentTwoSchedulesOfCost"; protected static final String APPLICANT_DISCLOSURE_LIST = "ApplicantDisclosureList"; protected static final String APPLICANT_PRE_TRIAL_SUMMARY = "ApplicantPreTrialSummary"; protected static final String APPLICANT_TRIAL_SKELETON = "ApplicantTrialSkeleton"; protected static final String APPLICANT_PRECEDENT_H = "ApplicantUploadedPrecedentH"; - protected static final String APPLICANT_ANY_PRECEDENT_H = "ApplicantAnyPrecedentH"; protected static final String APPLICANT_TWO_DISCLOSURE_LIST = "ApplicantTwoDisclosureList"; protected static final String APPLICANT_TWO_PRE_TRIAL_SUMMARY = "ApplicantTwoPreTrialSummary"; protected static final String APPLICANT_TWO_TRIAL_SKELETON = "ApplicantTwoTrialSkeleton"; protected static final String APPLICANT_TWO_PRECEDENT_H = "ApplicantTwoUploadedPrecedentH"; - protected static final String APPLICANT_TWO_ANY_PRECEDENT_H = "ApplicantTwoAnyPrecedentH"; - + protected static final String APPLICANT_SCHEDULE_OF_COSTS = "ApplicantSchedulesOfCost"; + protected static final String APPLICANT_TWO_SCHEDULE_OF_COSTS = "ApplicantTwoSchedulesOfCost"; // Notification Strings used for email protected static StringBuilder notificationString = new StringBuilder(); protected static final String DISCLOSURE_LIST_TEXT = "%s - Disclosure list"; @@ -635,7 +634,7 @@ CallbackResponse documentUploadTime(CallbackParams callbackParams) { TRIAL_SKELETON_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); setCategoryIdAndRenameDoc(caseData.getDocumentAuthoritiesRes(), document -> document.getValue().getDocumentUpload(), RESPONDENT_ONE_PRECEDENT_H, TRIAL_AUTHORITIES_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); - setCategoryIdAndRenameDoc(caseData.getDocumentCostsRes(), document -> document.getValue().getDocumentUpload(), RESPONDENT_ONE_ANY_PRECEDENT_H, + setCategoryIdAndRenameDoc(caseData.getDocumentCostsRes(), document -> document.getValue().getDocumentUpload(), RESPONDENT_ONE_SCHEDULE_OF_COSTS, TRIAL_COSTS_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); setCategoryIdAndRenameDoc(caseData.getDocumentEvidenceForTrialRes(), document -> document.getValue().getDocumentUpload(), RESPONDENT_ONE_TRIAL_DOC_CORRESPONDENCE, TRIAL_DOC_CORRESPONDENCE_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); @@ -671,7 +670,7 @@ CallbackResponse documentUploadTime(CallbackParams callbackParams) { TRIAL_SKELETON_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); setCategoryIdAndRenameDoc(caseData.getDocumentAuthoritiesRes2(), document -> document.getValue().getDocumentUpload(), RESPONDENT_TWO_PRECEDENT_H, TRIAL_AUTHORITIES_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); - setCategoryIdAndRenameDoc(caseData.getDocumentCostsRes2(), document -> document.getValue().getDocumentUpload(), RESPONDENT_TWO_ANY_PRECEDENT_H, + setCategoryIdAndRenameDoc(caseData.getDocumentCostsRes2(), document -> document.getValue().getDocumentUpload(), RESPONDENT_TWO_SCHEDULE_OF_COSTS, TRIAL_COSTS_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); setCategoryIdAndRenameDoc(caseData.getDocumentEvidenceForTrialRes2(), document -> document.getValue().getDocumentUpload(), RESPONDENT_TWO_TRIAL_DOC_CORRESPONDENCE, TRIAL_DOC_CORRESPONDENCE_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); @@ -708,7 +707,7 @@ CallbackResponse documentUploadTime(CallbackParams callbackParams) { TRIAL_SKELETON_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); setCategoryIdAndRenameDoc(caseData.getDocumentAuthorities(), document -> document.getValue().getDocumentUpload(), APPLICANT_PRECEDENT_H, TRIAL_AUTHORITIES_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); - setCategoryIdAndRenameDoc(caseData.getDocumentCosts(), document -> document.getValue().getDocumentUpload(), APPLICANT_ANY_PRECEDENT_H, + setCategoryIdAndRenameDoc(caseData.getDocumentCosts(), document -> document.getValue().getDocumentUpload(), APPLICANT_SCHEDULE_OF_COSTS, TRIAL_COSTS_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); setCategoryIdAndRenameDoc(caseData.getDocumentEvidenceForTrial(), document -> document.getValue().getDocumentUpload(), APPLICANT_TRIAL_DOC_CORRESPONDENCE, TRIAL_DOC_CORRESPONDENCE_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); @@ -745,7 +744,7 @@ CallbackResponse documentUploadTime(CallbackParams callbackParams) { TRIAL_SKELETON_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); setCategoryIdAndRenameDoc(caseData.getDocumentAuthoritiesApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_PRECEDENT_H, TRIAL_AUTHORITIES_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); - setCategoryIdAndRenameDoc(caseData.getDocumentCostsApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_ANY_PRECEDENT_H, + setCategoryIdAndRenameDoc(caseData.getDocumentCostsApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_SCHEDULE_OF_COSTS, TRIAL_COSTS_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); setCategoryIdAndRenameDoc(caseData.getDocumentEvidenceForTrialApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_TRIAL_DOC_CORRESPONDENCE, TRIAL_DOC_CORRESPONDENCE_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); @@ -872,7 +871,7 @@ private CaseData copyResp1ChangesToResp2(CaseData caseData, CaseData.CaseDataBui evidenceDocToCopy = compareAndCopy(caseDataBefore.getDocumentCostsRes(), caseData.getDocumentCostsRes(), caseData.getDocumentCostsRes2()); - evidenceDocToAdd = deepCopyUploadEvidenceDocumentType(evidenceDocToCopy, RESPONDENT_TWO_ANY_PRECEDENT_H); + evidenceDocToAdd = deepCopyUploadEvidenceDocumentType(evidenceDocToCopy, RESPONDENT_TWO_SCHEDULE_OF_COSTS); builder.documentCostsRes2(evidenceDocToAdd); evidenceDocToCopy = compareAndCopy(caseDataBefore.getDocumentEvidenceForTrialRes(), @@ -984,7 +983,7 @@ private CaseData copyApp1ChangesToApp2(CaseData caseData, CaseData.CaseDataBuild evidenceDocToCopy = compareAndCopy(caseDataBefore.getDocumentCosts(), caseData.getDocumentCosts(), caseData.getDocumentCostsApp2()); - evidenceDocToAdd = deepCopyUploadEvidenceDocumentType(evidenceDocToCopy, APPLICANT_TWO_ANY_PRECEDENT_H); + evidenceDocToAdd = deepCopyUploadEvidenceDocumentType(evidenceDocToCopy, APPLICANT_TWO_SCHEDULE_OF_COSTS); builder.documentCostsApp2(evidenceDocToAdd); evidenceDocToCopy = compareAndCopy(caseDataBefore.getDocumentEvidenceForTrial(), diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/GenerateDirectionOrderCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/GenerateDirectionOrderCallbackHandler.java index 57967679b5d..91e5960c66b 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/GenerateDirectionOrderCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/GenerateDirectionOrderCallbackHandler.java @@ -14,6 +14,7 @@ import uk.gov.hmcts.reform.civil.enums.CaseState; import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario; import uk.gov.hmcts.reform.civil.enums.YesOrNo; +import uk.gov.hmcts.reform.civil.enums.finalorders.CostEnums; import uk.gov.hmcts.reform.civil.enums.finalorders.FinalOrderToggle; import uk.gov.hmcts.reform.civil.enums.finalorders.HearingLengthFinalOrderList; import uk.gov.hmcts.reform.civil.model.BusinessProcess; @@ -66,6 +67,9 @@ import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.TWO_V_ONE; import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.getMultiPartyScenario; import static uk.gov.hmcts.reform.civil.enums.caseprogression.FinalOrderSelection.ASSISTED_ORDER; +import static uk.gov.hmcts.reform.civil.enums.finalorders.CostEnums.CLAIMANT; +import static uk.gov.hmcts.reform.civil.enums.finalorders.CostEnums.STANDARD_BASIS; +import static uk.gov.hmcts.reform.civil.enums.finalorders.CostEnums.SUBJECT_DETAILED_ASSESSMENT; import static uk.gov.hmcts.reform.civil.enums.finalorders.FinalOrderRepresentationList.CLAIMANT_AND_DEFENDANT; import static uk.gov.hmcts.reform.civil.model.common.DynamicList.fromList; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element; @@ -289,6 +293,10 @@ private DynamicList populateCurrentHearingLocation(CaseData caseData, String aut .assistedOrderCostsFirstDropdownDate(advancedDate) .assistedOrderAssessmentThirdDropdownDate(advancedDate) .makeAnOrderForCostsYesOrNo(YesOrNo.NO) + .makeAnOrderForCostsList(CLAIMANT) + .assistedOrderClaimantDefendantFirstDropdown(SUBJECT_DETAILED_ASSESSMENT) + .assistedOrderAssessmentSecondDropdownList1(STANDARD_BASIS) + .assistedOrderAssessmentSecondDropdownList2(CostEnums.NO) .build()) .publicFundingCostsProtection(YesOrNo.NO) .finalOrderAppealComplex(FinalOrderAppeal.builder() diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/ManageContactInformationCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/ManageContactInformationCallbackHandler.java index f7570b2557a..1ce5e75b370 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/ManageContactInformationCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/ManageContactInformationCallbackHandler.java @@ -27,6 +27,7 @@ import uk.gov.hmcts.reform.civil.model.dq.Witness; import uk.gov.hmcts.reform.civil.service.CoreCaseUserService; import uk.gov.hmcts.reform.civil.service.UserService; +import uk.gov.hmcts.reform.civil.utils.CaseFlagsInitialiser; import uk.gov.hmcts.reform.civil.validation.PostcodeValidator; import uk.gov.hmcts.reform.idam.client.models.UserInfo; @@ -97,6 +98,7 @@ public class ManageContactInformationCallbackHandler extends CallbackHandler { private final UserService userService; private final ObjectMapper objectMapper; private final CaseDetailsConverter caseDetailsConverter; + private final CaseFlagsInitialiser caseFlagsInitialiser; private final PostcodeValidator postcodeValidator; @Override @@ -345,6 +347,9 @@ private CallbackResponse submitChanges(CallbackParams callbackParams) { updateExperts(caseData.getUpdateDetailsForm().getPartyChosenId(), caseData, builder); updateWitnesses(caseData.getUpdateDetailsForm().getPartyChosenId(), caseData, builder); + // last step before clearing update details form + caseFlagsInitialiser.initialiseCaseFlags(MANAGE_CONTACT_INFORMATION, builder); + // clear updateDetailsForm builder.updateDetailsForm(UpdateDetailsForm.builder().manageContactDetailsEventUsed(YES).build()); diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestJudgementByAdmissionForSpecCuiCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestJudgementByAdmissionForSpecCuiCallbackHandler.java index 9ebf5ff394e..aebd58fee07 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestJudgementByAdmissionForSpecCuiCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestJudgementByAdmissionForSpecCuiCallbackHandler.java @@ -18,9 +18,7 @@ import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.service.JudgementService; -import uk.gov.hmcts.reform.civil.service.citizenui.responsedeadline.DeadlineExtensionCalculatorService; -import java.time.LocalDate; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -43,7 +41,6 @@ public class RequestJudgementByAdmissionForSpecCuiCallbackHandler extends Callba private final JudgementService judgementService; private final CaseDetailsConverter caseDetailsConverter; private final FeatureToggleService featureToggleService; - private final DeadlineExtensionCalculatorService deadlineCalculatorService; @Override protected Map callbacks() { @@ -67,9 +64,7 @@ private CallbackResponse validateDefaultJudgementEligibility(CallbackParams call CaseData.CaseDataBuilder caseDataBuilder = caseData.toBuilder(); ArrayList errors = new ArrayList<>(); if (caseData.isJudgementDateNotPermitted()) { - LocalDate extendedResponseDate = caseData.getRespondent1ResponseDate().toLocalDate().plusDays(5); - LocalDate extendedRespondent1ResponseDate = deadlineCalculatorService.calculateExtendedDeadline(extendedResponseDate); - errors.add(format(NOT_VALID_DJ_BY_ADMISSION, caseData.setUpJudgementFormattedPermittedDate(extendedRespondent1ResponseDate))); + errors.add(format(NOT_VALID_DJ_BY_ADMISSION, caseData.setUpJudgementFormattedPermittedDate(caseData.getRespondToClaimAdmitPartLRspec().getWhenWillThisAmountBePaid()))); } return AboutToStartOrSubmitCallbackResponse.builder() 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 691bf0b241a..701d9c1c912 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 @@ -20,6 +20,7 @@ import uk.gov.hmcts.reform.civil.enums.DocCategory; import uk.gov.hmcts.reform.civil.enums.MultiPartyResponseTypeFlags; import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario; +import uk.gov.hmcts.reform.civil.enums.RespondentResponsePartAdmissionPaymentTimeLRspec; import uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpec; import uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpecPaidStatus; import uk.gov.hmcts.reform.civil.enums.TimelineUploadTypeSpec; @@ -55,6 +56,7 @@ 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.citizenui.responsedeadline.DeadlineExtensionCalculatorService; import uk.gov.hmcts.reform.civil.service.flowstate.StateFlowEngine; import uk.gov.hmcts.reform.civil.utils.AssignCategoryId; import uk.gov.hmcts.reform.civil.utils.CaseFlagsInitialiser; @@ -164,6 +166,7 @@ public class RespondToClaimSpecCallbackHandler extends CallbackHandler private final CourtLocationUtils courtLocationUtils; private final CaseFlagsInitialiser caseFlagsInitialiser; private final AssignCategoryId assignCategoryId; + private final DeadlineExtensionCalculatorService deadlineCalculatorService; @Override public List handledEvents() { @@ -181,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::validateCorrespondenceApplicantAddress) + .put(callbackKey(MID, "specCorrespondenceAddress"), this::validateCorrespondenceAddress) .put(callbackKey(MID, "determineLoggedInSolicitor"), this::determineLoggedInSolicitor) .put(callbackKey(MID, "track"), this::handleDefendAllClaim) .put(callbackKey(MID, "specHandleResponseType"), this::handleRespondentResponseTypeForSpec) @@ -1057,12 +1060,26 @@ private AllocatedTrack getAllocatedTrack(CaseData caseData) { ); } - private CallbackResponse validateCorrespondenceApplicantAddress(CallbackParams callbackParams) { - if (SpecJourneyConstantLRSpec.DEFENDANT_RESPONSE_SPEC.equals(callbackParams.getRequest().getEventId())) { - return validateCorrespondenceApplicantAddress(callbackParams, postcodeValidator); + 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(); } - return AboutToStartOrSubmitCallbackResponse.builder() - .build(); + return AboutToStartOrSubmitCallbackResponse.builder().build(); } private CallbackResponse determineLoggedInSolicitor(CallbackParams callbackParams) { @@ -1115,6 +1132,10 @@ 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()); @@ -1262,9 +1283,9 @@ private CallbackResponse validateUnavailableDates(CallbackParams callbackParams) } private CallbackResponse validateDateOfBirth(CallbackParams callbackParams) { - Party respondent = callbackParams.getCaseData().getRespondent1(); - if (respondent == null && callbackParams.getCaseData().getRespondent2() != null) { - respondent = callbackParams.getCaseData().getRespondent2(); + Party respondent = callbackParams.getCaseData().getRespondent1Copy(); + if (respondent == null && callbackParams.getCaseData().getRespondent2Copy() != null) { + respondent = callbackParams.getCaseData().getRespondent2Copy(); } List errors = dateOfBirthValidator.validate(respondent); @@ -1342,9 +1363,9 @@ private CallbackResponse setApplicantResponseDeadline(CallbackParams callbackPar AllocatedTrack allocatedTrack = caseData.getAllocatedTrack(); Party updatedRespondent1; - if (NO.equals(caseData.getSpecAoSApplicantCorrespondenceAddressRequired())) { + if (NO.equals(caseData.getTempAddress1Required())) { updatedRespondent1 = caseData.getRespondent1().toBuilder() - .primaryAddress(caseData.getSpecAoSApplicantCorrespondenceAddressdetails()).build(); + .primaryAddress(caseData.getTempAddress1()).build(); } else { updatedRespondent1 = caseData.getRespondent1().toBuilder() .primaryAddress(caseData.getRespondent1Copy().getPrimaryAddress()) @@ -1383,7 +1404,9 @@ && ofNullable(caseData.getRespondent2Copy()).isPresent()) { if (caseData.getDefenceAdmitPartPaymentTimeRouteRequired() != null && caseData.getDefenceAdmitPartPaymentTimeRouteRequired() == IMMEDIATELY && ifResponseTypeIsPartOrFullAdmission(caseData)) { - LocalDate whenBePaid = deadlinesCalculator.calculateWhenToBePaid(responseDate); + LocalDate whenBePaid = deadlineCalculatorService.calculateExtendedDeadline( + LocalDate.now(), + RespondentResponsePartAdmissionPaymentTimeLRspec.DAYS_TO_PAY_IMMEDIATELY); updatedData.respondToClaimAdmitPartLRspec(RespondToClaimAdmitPartLRspec.builder() .whenWillThisAmountBePaid(whenBePaid).build()); } @@ -1419,21 +1442,8 @@ && ifResponseTypeIsPartOrFullAdmission(caseData)) { .businessProcess(BusinessProcess.ready(DEFENDANT_RESPONSE_SPEC)); if (caseData.getRespondent2() != null && caseData.getRespondent2Copy() != null) { - 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()); + Party updatedRespondent2 = applyRespondent2Address(caseData, updatedData); + updatedData.respondent2DetailsForClaimDetailsTab(updatedRespondent2); } // moving statement of truth value to correct field, this was not possible in mid event. @@ -1490,8 +1500,10 @@ && 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()) { @@ -1563,6 +1575,21 @@ && isAwaitingAnotherDefendantResponse(caseData)) { .build(); } + private static Party applyRespondent2Address(CaseData caseData, CaseData.CaseDataBuilder updatedData) { + Party updatedRespondent2; + + if (NO.equals(caseData.getTempAddress2Required())) { + updatedRespondent2 = caseData.getRespondent2().toBuilder() + .primaryAddress(caseData.getTempAddress2()).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( @@ -1577,19 +1604,19 @@ private void updateCorrespondenceAddress(CallbackParams callbackParams, CaseData.CaseDataBuilder updatedCaseData, CaseData caseData) { if (solicitorHasCaseRole(callbackParams, RESPONDENTSOLICITORONE) - && caseData.getSpecAoSRespondentCorrespondenceAddressRequired() == YesOrNo.NO) { - Address newAddress = caseData.getSpecAoSRespondentCorrespondenceAddressdetails(); + && caseData.getRespondentSolicitor1ServiceAddressRequired() == YesOrNo.NO) { + Address newAddress = caseData.getRespondentSolicitor1ServiceAddress(); updatedCaseData.specRespondentCorrespondenceAddressdetails(newAddress) - .specAoSRespondentCorrespondenceAddressdetails(Address.builder().build()); + .respondentSolicitor1ServiceAddress(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.getSpecAoSRespondent2CorrespondenceAddressRequired() == YesOrNo.NO) { + && caseData.getRespondentSolicitor2ServiceAddressRequired() == YesOrNo.NO) { updatedCaseData.specRespondent2CorrespondenceAddressdetails( - caseData.getSpecAoSRespondent2CorrespondenceAddressdetails()) - .specAoSRespondent2CorrespondenceAddressdetails(Address.builder().build()); + caseData.getRespondentSolicitor2ServiceAddress()) + .respondentSolicitor2ServiceAddress(Address.builder().build()); } } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandler.java index 49a3a85d317..ecbac578256 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandler.java @@ -16,6 +16,7 @@ import uk.gov.hmcts.reform.civil.enums.AllocatedTrack; import uk.gov.hmcts.reform.civil.enums.CaseCategory; import uk.gov.hmcts.reform.civil.enums.CaseState; +import uk.gov.hmcts.reform.civil.enums.RespondentResponsePartAdmissionPaymentTimeLRspec; import uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpec; import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.handler.callback.user.spec.CaseDataToTextGenerator; @@ -568,11 +569,10 @@ private String setUpPayDateToString(CaseData caseData) { .format(DateTimeFormatter.ofPattern(datePattern, Locale.ENGLISH)); } if (caseData.getRespondent1ResponseDate() != null) { - LocalDate extendedResponseDate = caseData.getRespondent1ResponseDate().toLocalDate().plusDays(5); - return deadlineCalculatorService.calculateExtendedDeadline(extendedResponseDate).format(DateTimeFormatter.ofPattern( - datePattern, - Locale.ENGLISH - )); + return deadlineCalculatorService.calculateExtendedDeadline( + caseData.getRespondent1ResponseDate().toLocalDate(), + RespondentResponsePartAdmissionPaymentTimeLRspec.DAYS_TO_PAY_IMMEDIATELY) + .format(DateTimeFormatter.ofPattern(datePattern, Locale.ENGLISH)); } return null; } 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 63d6365fd37..953b02321d3 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 @@ -874,9 +874,9 @@ && isApplicant1NotRepresented() @JsonIgnore public boolean isJudgementDateNotPermitted() { - return nonNull(getRespondent1ResponseDate()) - && getRespondent1ResponseDate() - .toLocalDate().plusDays(5).atTime(DeadlinesCalculator.END_OF_BUSINESS_DAY).isAfter(LocalDateTime.now()); + return nonNull(getRespondToClaimAdmitPartLRspec().getWhenWillThisAmountBePaid()) + && getRespondToClaimAdmitPartLRspec().getWhenWillThisAmountBePaid() + .atTime(DeadlinesCalculator.END_OF_BUSINESS_DAY).isAfter(LocalDateTime.now()); } @JsonIgnore 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 7d2a5546ce9..08b9556caf8 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,6 +723,23 @@ public boolean isApplicantNotRepresented() { private FastTrackAllocation fastTrackAllocation; + /** + * used to temporary hold addresses. + */ + private final Address tempAddress1; + /** + * used with tempAddress1. + */ + private final YesOrNo tempAddress1Required; + /** + * used to temporary hold addresses. + */ + private final Address tempAddress2; + /** + * used with tempAddress1. + */ + private final YesOrNo tempAddress2Required; + @JsonIgnore public boolean isResponseAcceptedByClaimant() { return applicant1AcceptAdmitAmountPaidSpec == YesOrNo.YES diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/citizenui/dto/ExtendedDeadlineDto.java b/src/main/java/uk/gov/hmcts/reform/civil/model/citizenui/dto/ExtendedDeadlineDto.java new file mode 100644 index 00000000000..58c4a1182de --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/citizenui/dto/ExtendedDeadlineDto.java @@ -0,0 +1,18 @@ +package uk.gov.hmcts.reform.civil.model.citizenui.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ExtendedDeadlineDto { + + private LocalDate responseDate; + private Integer plusDays; +} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/sealedclaim/ResponseRepaymentDetailsForm.java b/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/sealedclaim/ResponseRepaymentDetailsForm.java index ecacb8ca9f9..ae474fb8326 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/sealedclaim/ResponseRepaymentDetailsForm.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/sealedclaim/ResponseRepaymentDetailsForm.java @@ -78,9 +78,9 @@ public static ResponseRepaymentDetailsForm toSealedClaimResponseCommonContent(Ca .build(); } - private static void addRepaymentMethod(CaseData caseData, ResponseRepaymentDetailsForm.ResponseRepaymentDetailsFormBuilder builder, BigDecimal totalAmount) { + private static void addRepaymentMethod(CaseData caseData, ResponseRepaymentDetailsFormBuilder builder, BigDecimal totalAmount) { if (caseData.isPayImmediately()) { - addPayByDatePayImmediately(builder, totalAmount); + addPayByDatePayImmediately(builder, totalAmount, caseData.getRespondToClaimAdmitPartLRspec().getWhenWillThisAmountBePaid()); } else if (caseData.isPayByInstallment()) { addRepaymentPlan(caseData, builder, totalAmount); } else if (caseData.isPayBySetDate()) { @@ -94,10 +94,8 @@ private static void addPayBySetDate(CaseData caseData, ResponseRepaymentDetailsF .whyNotPayImmediately(caseData.getResponseToClaimAdmitPartWhyNotPayLRspec()); } - private static void addPayByDatePayImmediately(ResponseRepaymentDetailsForm.ResponseRepaymentDetailsFormBuilder builder, BigDecimal totalClaimAmount) { - builder.payBy(LocalDate.now() - .plusDays(RespondentResponsePartAdmissionPaymentTimeLRspec.DAYS_TO_PAY_IMMEDIATELY)) - .amountToPay(totalClaimAmount + ""); + private static void addPayByDatePayImmediately(ResponseRepaymentDetailsFormBuilder builder, BigDecimal totalClaimAmount, LocalDate responseDate) { + builder.payBy(responseDate).amountToPay(totalClaimAmount + ""); } private static void addRepaymentPlan(CaseData caseData, ResponseRepaymentDetailsForm.ResponseRepaymentDetailsFormBuilder builder, BigDecimal totalClaimAmount) { @@ -142,7 +140,7 @@ private static void fullDefenceData(CaseData caseData, ResponseRepaymentDetailsF } } - private static void partAdmissionData(CaseData caseData, ResponseRepaymentDetailsForm.ResponseRepaymentDetailsFormBuilder builder) { + private static void partAdmissionData(CaseData caseData, ResponseRepaymentDetailsFormBuilder builder) { addDetailsOnWhyClaimIsRejected(caseData, builder); if (caseData.getSpecDefenceAdmittedRequired() == YesOrNo.YES) { alreadyPaid(caseData, builder); diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/genapplication/CaseLocationCivil.java b/src/main/java/uk/gov/hmcts/reform/civil/model/genapplication/CaseLocationCivil.java index edc224ba820..20bc4d13f5a 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/genapplication/CaseLocationCivil.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/genapplication/CaseLocationCivil.java @@ -14,4 +14,6 @@ public class CaseLocationCivil { private String region; private String siteName; private String baseLocation; + private String address; + private String postcode; } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/GenAppStateHelperService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/GenAppStateHelperService.java index 2569a7ad87b..f0d0abaf206 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/GenAppStateHelperService.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/GenAppStateHelperService.java @@ -14,6 +14,7 @@ import uk.gov.hmcts.reform.civil.model.genapplication.GADetailsRespondentSol; import uk.gov.hmcts.reform.civil.model.genapplication.GeneralApplication; import uk.gov.hmcts.reform.civil.model.genapplication.GeneralApplicationsDetails; +import uk.gov.hmcts.reform.civil.referencedata.model.LocationRefData; import java.util.ArrayList; import java.util.HashMap; @@ -31,6 +32,7 @@ public class GenAppStateHelperService { private final CoreCaseDataService coreCaseDataService; private final CaseDetailsConverter caseDetailsConverter; + private final InitiateGeneralApplicationService genAppService; private final ObjectMapper objectMapper; @@ -69,16 +71,19 @@ public boolean triggerEvent(CaseData caseData, CaseEvent event) { return true; } - public CaseData updateApplicationLocationDetailsInClaim(CaseData caseData) { + public CaseData updateApplicationLocationDetailsInClaim(CaseData caseData, String authToken) { if (!Collections.isEmpty(caseData.getGeneralApplications())) { List genApps = new ArrayList<>(); CaseData finalCaseData = caseData; + LocationRefData locationDetails = genAppService.getWorkAllocationLocationDetails(finalCaseData.getCaseManagementLocation().getBaseLocation(), authToken); caseData.getGeneralApplications().forEach(generalApplicationElement -> { GeneralApplication generalApplication = generalApplicationElement.getValue(); generalApplication.getCaseManagementLocation().setBaseLocation(finalCaseData.getCaseManagementLocation().getBaseLocation()); generalApplication.getCaseManagementLocation().setRegion(finalCaseData.getCaseManagementLocation().getRegion()); - generalApplication.getCaseManagementLocation().setSiteName(finalCaseData.getLocationName()); + generalApplication.getCaseManagementLocation().setSiteName(locationDetails.getSiteName()); + generalApplication.getCaseManagementLocation().setAddress(locationDetails.getCourtAddress()); + generalApplication.getCaseManagementLocation().setPostcode(locationDetails.getPostcode()); Map genAppMap = generalApplication.toMap(objectMapper); genAppMap.put("isCcmccLocation", YesOrNo.NO); generalApplication = objectMapper.convertValue(genAppMap, GeneralApplication.class); diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/InitiateGeneralApplicationService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/InitiateGeneralApplicationService.java index a6191151527..f70a80f9ad5 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/InitiateGeneralApplicationService.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/InitiateGeneralApplicationService.java @@ -179,6 +179,13 @@ private GeneralApplication buildApplication(CaseData.CaseDataBuilder dataBuilder Pair caseLocation = getWorkAllocationLocation(caseData, authToken); //Setting Work Allocation location and location name + if (Objects.isNull(caseLocation.getLeft().getSiteName()) + && Objects.nonNull(caseLocation.getLeft().getBaseLocation())) { + LocationRefData locationDetails = getWorkAllocationLocationDetails(caseLocation.getLeft().getBaseLocation(), authToken); + caseLocation.getLeft().setSiteName(locationDetails.getSiteName()); + caseLocation.getLeft().setAddress(locationDetails.getCourtAddress()); + caseLocation.getLeft().setPostcode(locationDetails.getPostcode()); + } applicationBuilder.caseManagementLocation(caseLocation.getLeft()); applicationBuilder.isCcmccLocation(caseLocation.getRight() ? YES : NO); applicationBuilder.locationName(hasSDOBeenMade(caseData.getCcdState()) @@ -343,6 +350,8 @@ public Pair getWorkAllocationLocation(CaseData caseD .region(ccmccLocation.getRegionId()) .baseLocation(ccmccLocation.getEpimmsId()) .siteName(ccmccLocation.getSiteName()) + .address(ccmccLocation.getCourtAddress()) + .postcode(ccmccLocation.getPostcode()) .build(); return Pair.of(courtLocation, true); } @@ -369,6 +378,15 @@ private CaseLocationCivil getClaimant1PreferredLocation(CaseData caseData) { .build(); } + public LocationRefData getWorkAllocationLocationDetails(String baseLocation, String authToken) { + List locationDetails = locationRefDataService.getCourtLocationsByEpimmsId(authToken, baseLocation); + if (locationDetails != null && !locationDetails.isEmpty()) { + return locationDetails.get(0); + } else { + return LocationRefData.builder().build(); + } + } + private boolean isDefendant1RespondedFirst(CaseData caseData) { return caseData.getRespondent2ResponseDate() == null || (caseData.getRespondent1ResponseDate() != null diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/citizenui/responsedeadline/DeadlineExtensionCalculatorService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/citizenui/responsedeadline/DeadlineExtensionCalculatorService.java index 0e6e5479803..71bf64f61c1 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/citizenui/responsedeadline/DeadlineExtensionCalculatorService.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/citizenui/responsedeadline/DeadlineExtensionCalculatorService.java @@ -6,16 +6,28 @@ import java.time.LocalDate; +import static java.util.Objects.requireNonNull; + @Service @RequiredArgsConstructor public class DeadlineExtensionCalculatorService { private final WorkingDayIndicator workingDayIndicator; + int workingDaysCounter; - public LocalDate calculateExtendedDeadline(LocalDate dateProposed) { - return workingDayIndicator.isWorkingDay(dateProposed) - ? dateProposed - : workingDayIndicator.getNextWorkingDay(dateProposed); + public LocalDate calculateExtendedDeadline(LocalDate responseDate, int plusDays) { + workingDaysCounter = 0; + requireNonNull(responseDate); + if (plusDays == 0) { + return workingDayIndicator.getNextWorkingDay(responseDate); + } + return calculateWorkingDays(responseDate.plusDays(1), plusDays); } + public LocalDate calculateWorkingDays(LocalDate responseDate, int plusDays) { + if (workingDayIndicator.isWorkingDay(responseDate)) { + workingDaysCounter++; + } + return workingDaysCounter == plusDays ? responseDate : calculateWorkingDays(responseDate.plusDays(1), plusDays); + } } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/sealedclaim/SealedClaimLipResponseFormGenerator.java b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/sealedclaim/SealedClaimLipResponseFormGenerator.java index 42a5ae911ac..bc971235285 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/sealedclaim/SealedClaimLipResponseFormGenerator.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/sealedclaim/SealedClaimLipResponseFormGenerator.java @@ -1,27 +1,17 @@ package uk.gov.hmcts.reform.civil.service.docmosis.sealedclaim; import lombok.RequiredArgsConstructor; - import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.civil.documentmanagement.DocumentManagementService; import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; import uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType; import uk.gov.hmcts.reform.civil.documentmanagement.model.PDF; -import uk.gov.hmcts.reform.civil.enums.RespondentResponsePartAdmissionPaymentTimeLRspec; -import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.docmosis.DocmosisDocument; -import uk.gov.hmcts.reform.civil.model.docmosis.sealedclaim.ResponseRepaymentDetailsForm; import uk.gov.hmcts.reform.civil.model.docmosis.sealedclaim.SealedClaimLipResponseForm; import uk.gov.hmcts.reform.civil.service.docmosis.DocumentGeneratorService; -import uk.gov.hmcts.reform.civil.service.citizenui.responsedeadline.DeadlineExtensionCalculatorService; import uk.gov.hmcts.reform.civil.service.docmosis.TemplateDataGenerator; -import java.time.LocalDate; -import java.util.Objects; - -import static uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpec.FULL_ADMISSION; -import static uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpec.PART_ADMISSION; import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.DEFENDANT_RESPONSE_LIP_SPEC; @Service @@ -30,12 +20,10 @@ public class SealedClaimLipResponseFormGenerator implements TemplateDataGenerato private final DocumentGeneratorService documentGeneratorService; private final DocumentManagementService documentManagementService; - private final DeadlineExtensionCalculatorService deadlineCalculatorService; @Override public SealedClaimLipResponseForm getTemplateData(CaseData caseData) { - SealedClaimLipResponseForm templateData = SealedClaimLipResponseForm.toTemplate(caseData); - return getRespondent1RepaymentDate(caseData, templateData); + return SealedClaimLipResponseForm.toTemplate(caseData); } public CaseDocument generate(final CaseData caseData, final String authorization) { @@ -54,30 +42,4 @@ public CaseDocument generate(final CaseData caseData, final String authorization new PDF(fileName, docmosisDocument.getBytes(), DocumentType.DEFENDANT_DEFENCE) ); } - - private SealedClaimLipResponseForm getRespondent1RepaymentDate(final CaseData caseData, SealedClaimLipResponseForm templateData) { - if (!Objects.isNull(caseData.getRespondent1ClaimResponseTypeForSpec())) { - if (hasPayByDatePayImmediately(caseData)) { - return addPayByDatePayImmediately(caseData, templateData); - } - } - return templateData; - } - - private SealedClaimLipResponseForm addPayByDatePayImmediately(CaseData caseData, SealedClaimLipResponseForm templateData) { - if (caseData.isPayImmediately()) { - LocalDate extendedDate = LocalDate.now().plusDays(RespondentResponsePartAdmissionPaymentTimeLRspec.DAYS_TO_PAY_IMMEDIATELY); - LocalDate payDeadlineDate = deadlineCalculatorService.calculateExtendedDeadline(extendedDate); - ResponseRepaymentDetailsForm responseRepaymentDetailsForm = templateData.getCommonDetails().toBuilder().payBy( - payDeadlineDate).build(); - SealedClaimLipResponseForm.SealedClaimLipResponseFormBuilder templateFormData = templateData.toBuilder(); - return templateFormData.commonDetails(responseRepaymentDetailsForm).build(); - } - return templateData; - } - - private boolean hasPayByDatePayImmediately(CaseData caseData) { - return (FULL_ADMISSION.equals(caseData.getRespondent1ClaimResponseTypeForSpec()) || (PART_ADMISSION.equals( - caseData.getRespondent1ClaimResponseTypeForSpec()) && caseData.getSpecDefenceAdmittedRequired() == YesOrNo.NO)); - } } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/utils/CaseFlagUtils.java b/src/main/java/uk/gov/hmcts/reform/civil/utils/CaseFlagUtils.java index 62a60317e95..cfc0249f777 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/utils/CaseFlagUtils.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/utils/CaseFlagUtils.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.reform.civil.utils; +import uk.gov.hmcts.reform.ccd.model.OrganisationPolicy; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.PartyFlagStructure; import uk.gov.hmcts.reform.civil.model.caseflags.FlagDetail; @@ -22,18 +23,45 @@ import static uk.gov.hmcts.reform.civil.enums.YesOrNo.NO; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.unwrapElements; +import static uk.gov.hmcts.reform.civil.utils.ElementUtils.wrapElements; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_LEGAL_REP_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_ORG_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_TWO_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_TWO_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_TWO_ORG_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_LEGAL_REP_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_ORG_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_LEGAL_REP_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_ORG_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.PartyUtils.appendWithNewPartyId; import uk.gov.hmcts.reform.civil.model.LitigationFriend; import uk.gov.hmcts.reform.civil.model.Party; +import uk.gov.hmcts.reform.civil.prd.model.Organisation; +import uk.gov.hmcts.reform.civil.service.OrganisationService; public class CaseFlagUtils { - public static String RESPONDENT_SOLICITOR_ONE_WITNESS = "Respondent solicitor 1 witness"; - public static String RESPONDENT_SOLICITOR_ONE_EXPERT = "Respondent solicitor 1 expert"; - public static String RESPONDENT_SOLICITOR_TWO_WITNESS = "Respondent solicitor 2 witness"; - public static String RESPONDENT_SOLICITOR_TWO_EXPERT = "Respondent solicitor 2 expert"; - public static String APPLICANT_SOLICITOR_WITNESS = "Applicant solicitor witness"; - public static String APPLICANT_SOLICITOR_EXPERT = "Applicant solicitor expert"; + public static final String RESPONDENT_SOLICITOR_ONE_WITNESS = "Respondent solicitor 1 witness"; + public static final String RESPONDENT_SOLICITOR_ONE_EXPERT = "Respondent solicitor 1 expert"; + public static final String RESPONDENT_SOLICITOR_TWO_WITNESS = "Respondent solicitor 2 witness"; + public static final String RESPONDENT_SOLICITOR_TWO_EXPERT = "Respondent solicitor 2 expert"; + public static final String APPLICANT_SOLICITOR_WITNESS = "Applicant solicitor witness"; + public static final String APPLICANT_SOLICITOR_EXPERT = "Applicant solicitor expert"; + public static final String APPLICANT_ONE = "Applicant 1"; + public static final String APPLICANT_TWO = "Applicant 2"; + public static final String APPLICANT_ONE_LITIGATION_FRIEND = "Applicant 1 Litigation Friend"; + public static final String APPLICANT_TWO_LITIGATION_FRIEND = "Applicant 2 Litigation Friend"; + public static final String RESPONDENT_ONE = "Respondent 1"; + public static final String RESPONDENT_TWO = "Respondent 2"; + public static final String RESPONDENT_ONE_LITIGATION_FRIEND = "Respondent 1 Litigation Friend"; + public static final String RESPONDENT_TWO_LITIGATION_FRIEND = "Respondent 2 Litigation Friend"; private CaseFlagUtils() { //NO-OP @@ -49,7 +77,7 @@ public static Flags createFlags(String flagsPartyName, String roleOnCase) { private static PartyFlagStructure createPartiesCaseFlagsField(String partyId, String firstName, String lastName, String email, String phone, String roleOnCase) { - String partyName = String.format("%s %s", firstName, lastName); + String partyName = formattedPartyNameForFlags(firstName, lastName); return PartyFlagStructure.builder() .partyID(partyId) .firstName(firstName) @@ -72,7 +100,7 @@ public static LitigationFriend updateLitFriend(String roleOnCase, LitigationFrie // ToDo: Remove the use of fullName after H&L changes are default ===================================== litFriendToUpdate.getFullName() != null ? litFriendToUpdate.getFullName() // ==================================================================================================== - : String.format("%s %s", litFriendToUpdate.getFirstName(), litFriendToUpdate.getLastName()), + : formattedPartyNameForFlags(litFriendToUpdate.getFirstName(), litFriendToUpdate.getLastName()), roleOnCase)).build() : null; } @@ -171,6 +199,129 @@ public static void addApplicantExpertAndWitnessFlagsStructure(CaseData.CaseDataB } } + public static void createOrUpdateFlags(CaseData.CaseDataBuilder builder, CaseData caseData, OrganisationService organisationService) { + String partyChosen = caseData.getUpdateDetailsForm().getPartyChosenId(); + // claimant/defendant + updatePartyFlags(builder, caseData, partyChosen); + // litigation friend + updateLitigationFriendFlags(builder, caseData, partyChosen); + // attending for org/company + updateOrgIndividualsFlags(builder, caseData, partyChosen); + // attending for legal rep + updateLRIndividualsFlags(builder, caseData, partyChosen, organisationService); + } + + private static void updateLRIndividualsFlags(CaseData.CaseDataBuilder builder, CaseData caseData, String partyChosen, OrganisationService organisationService) { + if ((CLAIMANT_ONE_LEGAL_REP_INDIVIDUALS_ID).equals(partyChosen)) { + String legalRepFirmName = getLegalRepFirmName( + caseData.getApplicant1OrganisationPolicy(), + organisationService, + APPLICANT_ONE); + builder.applicant1LRIndividuals(updatePartyNameForPartyFlagStructures(caseData.getApplicant1LRIndividuals(), legalRepFirmName)); + } + if ((DEFENDANT_ONE_LEGAL_REP_INDIVIDUALS_ID).equals(partyChosen)) { + String legalRepFirmName = getLegalRepFirmName( + caseData.getRespondent1OrganisationPolicy(), + organisationService, + RESPONDENT_ONE); + builder.respondent1LRIndividuals(updatePartyNameForPartyFlagStructures(caseData.getRespondent1LRIndividuals(), legalRepFirmName)); + } + if ((DEFENDANT_TWO_LEGAL_REP_INDIVIDUALS_ID).equals(partyChosen)) { + String legalRepFirmName = getLegalRepFirmName( + caseData.getRespondent2OrganisationPolicy(), + organisationService, + RESPONDENT_TWO); + builder.respondent2LRIndividuals(updatePartyNameForPartyFlagStructures(caseData.getRespondent2LRIndividuals(), legalRepFirmName)); + } + } + + private static void updateOrgIndividualsFlags(CaseData.CaseDataBuilder builder, CaseData caseData, String partyChosen) { + if ((CLAIMANT_ONE_ORG_INDIVIDUALS_ID).equals(partyChosen)) { + builder.applicant1OrgIndividuals(updatePartyNameForPartyFlagStructures(caseData.getApplicant1OrgIndividuals(), caseData.getApplicant1().getPartyName())); + } + if ((CLAIMANT_TWO_ORG_INDIVIDUALS_ID).equals(partyChosen)) { + builder.applicant2OrgIndividuals(updatePartyNameForPartyFlagStructures(caseData.getApplicant2OrgIndividuals(), caseData.getApplicant2().getPartyName())); + } + if ((DEFENDANT_ONE_ORG_INDIVIDUALS_ID).equals(partyChosen)) { + builder.respondent1OrgIndividuals(updatePartyNameForPartyFlagStructures(caseData.getRespondent1OrgIndividuals(), caseData.getRespondent1().getPartyName())); + } + if ((DEFENDANT_TWO_ORG_INDIVIDUALS_ID).equals(partyChosen)) { + builder.respondent2OrgIndividuals(updatePartyNameForPartyFlagStructures(caseData.getRespondent2OrgIndividuals(), caseData.getRespondent2().getPartyName())); + } + } + + private static void updateLitigationFriendFlags(CaseData.CaseDataBuilder builder, CaseData caseData, String partyChosen) { + if ((CLAIMANT_ONE_LITIGATION_FRIEND_ID).equals(partyChosen)) { + builder.applicant1LitigationFriend(updatePartyNameForLitigationFriendFlags(caseData.getApplicant1LitigationFriend())); + } + if ((CLAIMANT_TWO_LITIGATION_FRIEND_ID).equals(partyChosen)) { + builder.applicant2LitigationFriend(updatePartyNameForLitigationFriendFlags(caseData.getApplicant2LitigationFriend())); + } + if ((DEFENDANT_ONE_LITIGATION_FRIEND_ID).equals(partyChosen)) { + builder.respondent1LitigationFriend(updatePartyNameForLitigationFriendFlags(caseData.getRespondent1LitigationFriend())); + } + if ((DEFENDANT_TWO_LITIGATION_FRIEND_ID).equals(partyChosen)) { + builder.respondent2LitigationFriend(updatePartyNameForLitigationFriendFlags(caseData.getRespondent2LitigationFriend())); + } + } + + private static void updatePartyFlags(CaseData.CaseDataBuilder builder, CaseData caseData, String partyChosen) { + if ((CLAIMANT_ONE_ID).equals(partyChosen)) { + builder.applicant1(updatePartyNameForFlags(caseData.getApplicant1())); + } + if ((CLAIMANT_TWO_ID).equals(partyChosen)) { + builder.applicant2(updatePartyNameForFlags(caseData.getApplicant2())); + } + if ((DEFENDANT_ONE_ID).equals(partyChosen)) { + builder.respondent1(updatePartyNameForFlags(caseData.getRespondent1())); + } + if ((DEFENDANT_TWO_ID).equals(partyChosen)) { + builder.respondent2(updatePartyNameForFlags(caseData.getRespondent2())); + } + } + + private static List> updatePartyNameForPartyFlagStructures(List> individuals, + String roleOnCase) { + if (individuals != null && !individuals.isEmpty()) { + List partyFlagStructures = unwrapElements(individuals); + List updatedList = new ArrayList<>(); + for (PartyFlagStructure partyFlagStructure : partyFlagStructures) { + String formattedPartyNameForFlags = formattedPartyNameForFlags(partyFlagStructure.getFirstName(), partyFlagStructure.getLastName()); + if (partyFlagStructure.getFlags() == null) { + // new party so initialise flags and party ID + updatedList.add( + appendWithNewPartyId(partyFlagStructure + .toBuilder() + .flags(createFlags(formattedPartyNameForFlags, roleOnCase)).build())); + } else { + // existing party with flags so just update the name + updatedList.add( + partyFlagStructure + .toBuilder() + .flags(partyFlagStructure.getFlags().toBuilder() + .partyName(formattedPartyNameForFlags) + .build()).build()); + } + } + return wrapElements(updatedList); + } + return null; + } + + private static Party updatePartyNameForFlags(Party party) { + return party.toBuilder().flags(party.getFlags().toBuilder() + .partyName(party.getPartyName()) + .build()).build(); + } + + private static LitigationFriend updatePartyNameForLitigationFriendFlags(LitigationFriend litigationFriend) { + return litigationFriend.toBuilder() + .flags(litigationFriend.getFlags().toBuilder() + .partyName(litigationFriend.getFullName() != null ? litigationFriend.getFullName() + : formattedPartyNameForFlags(litigationFriend.getFirstName(), litigationFriend.getLastName())) + .build()).build(); + } + public static List getAllCaseFlags(CaseData caseData) { var flagCollection = new ArrayList(); flagCollection.addAll(getFlagDetails(caseData.getCaseFlags())); @@ -222,4 +373,17 @@ public static List filter(List flagDetails, Predicate true)) .collect(Collectors.toList()); } + + private static String formattedPartyNameForFlags(String firstName, String lastName) { + return String.format("%s %s", firstName, lastName); + } + + private static String getLegalRepFirmName(OrganisationPolicy organisationPolicy, + OrganisationService organisationService, + String party) { + String organisationID = organisationPolicy.getOrganisation().getOrganisationID(); + return organisationService.findOrganisationById(organisationID) + .map(Organisation::getName) + .orElse(String.format("legal representative for %s", party.toLowerCase())); + } } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/utils/CaseFlagsInitialiser.java b/src/main/java/uk/gov/hmcts/reform/civil/utils/CaseFlagsInitialiser.java index 8955dff6ea4..708b197e462 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/utils/CaseFlagsInitialiser.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/utils/CaseFlagsInitialiser.java @@ -5,16 +5,27 @@ import uk.gov.hmcts.reform.civil.callback.CaseEvent; import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.service.OrganisationService; import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; +import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.APPLICANT_ONE; +import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.APPLICANT_ONE_LITIGATION_FRIEND; +import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.APPLICANT_TWO; +import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.APPLICANT_TWO_LITIGATION_FRIEND; +import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.RESPONDENT_ONE; +import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.RESPONDENT_ONE_LITIGATION_FRIEND; +import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.RESPONDENT_TWO; +import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.RESPONDENT_TWO_LITIGATION_FRIEND; import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.addApplicantExpertAndWitnessFlagsStructure; import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.addRespondentDQPartiesFlagStructure; +import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.createOrUpdateFlags; @Component @AllArgsConstructor public class CaseFlagsInitialiser { private final FeatureToggleService featureToggleService; + private final OrganisationService organisationService; public void initialiseCaseFlags(CaseEvent caseEvent, CaseData.CaseDataBuilder dataBuilder) { if (!featureToggleService.isCaseFlagsEnabled()) { @@ -42,6 +53,10 @@ public void initialiseCaseFlags(CaseEvent caseEvent, CaseData.CaseDataBuilder da addApplicantExpertAndWitnessFlagsStructure(dataBuilder, caseData); break; } + case MANAGE_CONTACT_INFORMATION: { + createOrUpdateFlags(dataBuilder, caseData, organisationService); + break; + } default: } } @@ -62,26 +77,26 @@ private void initialiseRespondentLitigationFriendFlags(CaseData.CaseDataBuilder dataBuilder .respondent1LitigationFriend( CaseFlagUtils.updateLitFriend( - "Respondent 1 Litigation Friend", + RESPONDENT_ONE_LITIGATION_FRIEND, caseData.getRespondent1LitigationFriend() )) .respondent2LitigationFriend( CaseFlagUtils.updateLitFriend( - "Respondent 2 Litigation Friend", + RESPONDENT_TWO_LITIGATION_FRIEND, caseData.getRespondent2LitigationFriend() )); } private void initialiseApplicantAndRespondentFlags(CaseData.CaseDataBuilder dataBuilder, CaseData caseData) { dataBuilder - .applicant1(CaseFlagUtils.updateParty("Applicant 1", caseData.getApplicant1())) - .applicant2(CaseFlagUtils.updateParty("Applicant 2", caseData.getApplicant2())) - .respondent1(CaseFlagUtils.updateParty("Respondent 1", caseData.getRespondent1())) - .respondent2(CaseFlagUtils.updateParty("Respondent 2", caseData.getRespondent2())) + .applicant1(CaseFlagUtils.updateParty(APPLICANT_ONE, caseData.getApplicant1())) + .applicant2(CaseFlagUtils.updateParty(APPLICANT_TWO, caseData.getApplicant2())) + .respondent1(CaseFlagUtils.updateParty(RESPONDENT_ONE, caseData.getRespondent1())) + .respondent2(CaseFlagUtils.updateParty(RESPONDENT_TWO, caseData.getRespondent2())) .applicant1LitigationFriend(CaseFlagUtils.updateLitFriend( - "Applicant 1 Litigation Friend", caseData.getApplicant1LitigationFriend())) + APPLICANT_ONE_LITIGATION_FRIEND, caseData.getApplicant1LitigationFriend())) .applicant2LitigationFriend(CaseFlagUtils.updateLitFriend( - "Applicant 2 Litigation Friend", caseData.getApplicant2LitigationFriend())); + APPLICANT_TWO_LITIGATION_FRIEND, caseData.getApplicant2LitigationFriend())); } private boolean shouldReinitialiseRespondentDQFlags(CaseData caseData) { 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 5c394d09ee5..81a5e845f2e 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.getRespondent1ResponseDate().toLocalDate(), + caseData.getRespondent2ResponseDate().toLocalDate(), DEFENDANT_RESPONSE_EVENT, respondent2DQUnavailableDates ); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/TriggerGenAppLocationUpdateCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/TriggerGenAppLocationUpdateCallbackHandlerTest.java index e82e3a302b3..53cd99df257 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/TriggerGenAppLocationUpdateCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/TriggerGenAppLocationUpdateCallbackHandlerTest.java @@ -46,6 +46,8 @@ class TriggerGenAppLocationUpdateCallbackHandlerTest extends BaseCallbackHandler @MockBean private GenAppStateHelperService helperService; + private static final String authToken = "Bearer TestAuthToken"; + @Test void handleEventsReturnsTheExpectedCallbackEvent() { assertThat(handler.handledEvents()).contains(TRIGGER_UPDATE_GA_LOCATION); @@ -60,12 +62,12 @@ void shouldTriggerGeneralApplicationEvent_whenCaseHasGeneralApplication() { true, true, getOriginalStatusOfGeneralApplication() ); - when(helperService.updateApplicationLocationDetailsInClaim(caseData)).thenReturn(caseData); + when(helperService.updateApplicationLocationDetailsInClaim(any(), any())).thenReturn(caseData); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); assertThat(response.getErrors()).isNull(); - verify(helperService, times(1)).updateApplicationLocationDetailsInClaim(caseData); + verify(helperService, times(1)).updateApplicationLocationDetailsInClaim(any(), any()); verify(helperService, times(1)).triggerEvent(caseData, TRIGGER_LOCATION_UPDATE); verify(helperService, times(1)).triggerEvent(caseData, TRIGGER_LOCATION_UPDATE); verifyNoMoreInteractions(helperService); @@ -93,7 +95,7 @@ void triggerGeneralApplicationEventThrowsException_HandleFailure() { ); String expectedErrorMessage = "Could not trigger event to update location on application under case: " + caseData.getCcdCaseReference(); - when(helperService.updateApplicationLocationDetailsInClaim(caseData)).thenReturn(caseData); + when(helperService.updateApplicationLocationDetailsInClaim(any(), any())).thenReturn(caseData); when(helperService.triggerEvent(any(CaseData.class), eq(TRIGGER_LOCATION_UPDATE))) .thenThrow(new RuntimeException()); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadApplicantHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadApplicantHandlerTest.java index cda6fc74fc7..3704297d425 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadApplicantHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadApplicantHandlerTest.java @@ -843,7 +843,7 @@ void should_do_naming_convention(String selected) { assertThat(updatedData.getDocumentCostsApp2().get(0).getValue() .getDocumentUpload().getDocumentFileName()).isEqualTo(TEST_FILE_NAME); assertThat(updatedData.getDocumentCostsApp2().get(0).getValue() - .getDocumentUpload().getCategoryID()).isEqualTo(EvidenceUploadHandlerBase.APPLICANT_TWO_ANY_PRECEDENT_H); + .getDocumentUpload().getCategoryID()).isEqualTo(EvidenceUploadHandlerBase.APPLICANT_TWO_SCHEDULE_OF_COSTS); assertThat(updatedData.getNotificationText()).isEqualTo(NotificationWhenBothClaimant); } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadRespondentHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadRespondentHandlerTest.java index 455cd043a2e..d5c32eeac09 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadRespondentHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadRespondentHandlerTest.java @@ -1451,7 +1451,7 @@ void should_do_naming_convention_resp1(String selected) { assertThat(updatedData.getDocumentCostsRes2().get(0).getValue() .getDocumentUpload().getDocumentFileName()).isEqualTo(TEST_FILE_NAME); assertThat(updatedData.getDocumentCostsRes2().get(0).getValue() - .getDocumentUpload().getCategoryID()).isEqualTo(EvidenceUploadHandlerBase.RESPONDENT_TWO_ANY_PRECEDENT_H); + .getDocumentUpload().getCategoryID()).isEqualTo(EvidenceUploadHandlerBase.RESPONDENT_TWO_SCHEDULE_OF_COSTS); assertThat(updatedData.getNotificationText()).contains(NotificationWhenBothDefendant); } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/GenerateDirectionOrderCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/GenerateDirectionOrderCallbackHandlerTest.java index ca123fb867f..9891b5f8586 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/GenerateDirectionOrderCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/GenerateDirectionOrderCallbackHandlerTest.java @@ -275,6 +275,18 @@ void shouldPopulateFields_whenIsCalledAfterSdo() { assertThat(response.getData()).extracting("assistedOrderMakeAnOrderForCosts") .extracting("makeAnOrderForCostsQOCSYesOrNo") .isEqualTo("No"); + assertThat(response.getData()).extracting("assistedOrderMakeAnOrderForCosts") + .extracting("makeAnOrderForCostsList") + .isEqualTo("CLAIMANT"); + assertThat(response.getData()).extracting("assistedOrderMakeAnOrderForCosts") + .extracting("assistedOrderClaimantDefendantFirstDropdown") + .isEqualTo("SUBJECT_DETAILED_ASSESSMENT"); + assertThat(response.getData()).extracting("assistedOrderMakeAnOrderForCosts") + .extracting("assistedOrderAssessmentSecondDropdownList1") + .isEqualTo("STANDARD_BASIS"); + assertThat(response.getData()).extracting("assistedOrderMakeAnOrderForCosts") + .extracting("assistedOrderAssessmentSecondDropdownList2") + .isEqualTo("NO"); assertThat(response.getData()).extracting("publicFundingCostsProtection") .isEqualTo("No"); assertThat(response.getData()).extracting("finalOrderAppealComplex") diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ManageContactInformationCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ManageContactInformationCallbackHandlerTest.java index de083369ffa..8ff9b667be7 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ManageContactInformationCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ManageContactInformationCallbackHandlerTest.java @@ -36,6 +36,7 @@ import uk.gov.hmcts.reform.civil.model.dq.Witnesses; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.service.CoreCaseUserService; +import uk.gov.hmcts.reform.civil.utils.CaseFlagsInitialiser; import uk.gov.hmcts.reform.civil.validation.PostcodeValidator; import uk.gov.hmcts.reform.idam.client.models.UserInfo; import java.time.LocalDate; @@ -86,6 +87,9 @@ class ManageContactInformationCallbackHandlerTest extends BaseCallbackHandlerTes @Autowired private ObjectMapper mapper; + @MockBean + private CaseFlagsInitialiser caseFlagInitialiser; + @MockBean private CoreCaseUserService coreCaseUserService; diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestJudgementByAdmissionForSpecCuiCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestJudgementByAdmissionForSpecCuiCallbackHandlerTest.java index 3f906a4b330..4587d7afc7a 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestJudgementByAdmissionForSpecCuiCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestJudgementByAdmissionForSpecCuiCallbackHandlerTest.java @@ -11,7 +11,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.ccd.client.model.SubmittedCallbackResponse; -import uk.gov.hmcts.reform.civil.bankholidays.WorkingDayIndicator; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.enums.CaseState; import uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpec; @@ -21,26 +20,24 @@ import uk.gov.hmcts.reform.civil.model.CCJPaymentDetails; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.Fee; +import uk.gov.hmcts.reform.civil.model.RespondToClaimAdmitPartLRspec; import uk.gov.hmcts.reform.civil.sampledata.CallbackParamsBuilder; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.service.JudgementService; -import uk.gov.hmcts.reform.civil.service.citizenui.responsedeadline.DeadlineExtensionCalculatorService; import uk.gov.hmcts.reform.civil.utils.MonetaryConversions; import java.math.BigDecimal; import java.time.LocalDate; import java.time.LocalDateTime; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START; -import static uk.gov.hmcts.reform.civil.callback.CallbackType.MID; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; +import static uk.gov.hmcts.reform.civil.callback.CallbackType.MID; import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.REQUEST_JUDGEMENT_ADMISSION_SPEC; import static uk.gov.hmcts.reform.civil.enums.CaseState.AWAITING_APPLICANT_INTENTION; @@ -70,23 +67,18 @@ public class RequestJudgementByAdmissionForSpecCuiCallbackHandlerTest extends Ba @MockBean private CaseDetailsConverter caseDetailsConverter; - @MockBean - private DeadlineExtensionCalculatorService deadlineCalculatorService; - @MockBean - private WorkingDayIndicator workingDayIndicator; @Nested class AboutToStartCallback { @Test void shouldReturnError_WhenAboutToStartIsInvoked() { + LocalDate whenWillPay = LocalDate.now().plusDays(5); CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build().toBuilder() .respondent1ResponseDate(LocalDateTime.now()) .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_ADMISSION) .ccdState(AWAITING_APPLICANT_INTENTION) + .respondToClaimAdmitPartLRspec(RespondToClaimAdmitPartLRspec.builder().whenWillThisAmountBePaid(whenWillPay).build()) .build(); - given(workingDayIndicator.isWorkingDay(any())).willReturn(true); - LocalDate proposedExtensionDeadline = LocalDate.now(); - given(deadlineCalculatorService.calculateExtendedDeadline(any())).willReturn(proposedExtensionDeadline); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_START, caseData).build(); AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler .handle(params); @@ -95,10 +87,12 @@ void shouldReturnError_WhenAboutToStartIsInvoked() { @Test void shouldNotReturnError_WhenAboutToStartIsInvokedOneDefendant() { + LocalDate whenWillPay = LocalDate.of(2023, 10, 11); CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build().toBuilder() .respondent1ResponseDate(LocalDateTime.now().minusDays(15)) .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_ADMISSION) .ccdState(AWAITING_APPLICANT_INTENTION) + .respondToClaimAdmitPartLRspec(RespondToClaimAdmitPartLRspec.builder().whenWillThisAmountBePaid(whenWillPay).build()) .build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_START, caseData).build(); AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler 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 ac9d11481ef..1ae04095de2 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,6 +19,7 @@ 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; @@ -55,31 +56,35 @@ 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; import uk.gov.hmcts.reform.civil.stateflow.StateFlow; 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.ElementUtils; import uk.gov.hmcts.reform.civil.utils.MonetaryConversions; +import uk.gov.hmcts.reform.civil.utils.ElementUtils; import uk.gov.hmcts.reform.civil.validation.DateOfBirthValidator; import uk.gov.hmcts.reform.civil.validation.PaymentDateValidator; import uk.gov.hmcts.reform.civil.validation.PostcodeValidator; @@ -98,8 +103,11 @@ 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; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; @@ -117,6 +125,7 @@ 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; @@ -162,6 +171,8 @@ class RespondToClaimSpecCallbackHandlerTest extends BaseCallbackHandlerTest { private CourtLocationUtils courtLocationUtils; @Mock private CaseFlagsInitialiser caseFlagsInitialiser; + @Mock + private DeadlineExtensionCalculatorService deadlineExtensionCalculatorService; @Spy private List confirmationTextGenerators = List.of( @@ -194,15 +205,82 @@ 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() - .specAoSApplicantCorrespondenceAddressRequired(YesOrNo.NO) - .specAoSApplicantCorrespondenceAddressdetails(Address.builder() - .postCode(postCode) - .build()) + .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()) .build(); CallbackParams params = callbackParamsOf(caseData, CallbackType.MID, "specCorrespondenceAddress"); CallbackRequest request = CallbackRequest.builder() @@ -310,10 +388,8 @@ 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 @@ -343,10 +419,8 @@ 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 @@ -372,10 +446,8 @@ 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 @@ -658,9 +730,6 @@ 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(); /* @@ -719,8 +788,9 @@ void updateRespondent1AddressWhenUpdated() { CaseData caseData = CaseDataBuilder.builder() .respondent1(PartyBuilder.builder().individual().build()) .atStateApplicantRespondToDefenceAndProceed() - .atSpecAoSApplicantCorrespondenceAddressRequired(NO) - .atSpecAoSApplicantCorrespondenceAddressDetails(AddressBuilder.maximal().build()) + .build().toBuilder() + .tempAddress1Required(NO) + .tempAddress1(AddressBuilder.maximal().build()) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); @@ -751,17 +821,21 @@ void updateRespondent2AddressWhenUpdated() { when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); - Address changedAddress = AddressBuilder.maximal().build(); - + 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()) - .atSpecAoSRespondent2HomeAddressRequired(NO) - .atSpecAoSRespondent2HomeAddressDetails(AddressBuilder.maximal().build()) + .build().toBuilder() + .tempAddress1Required(YES) + .tempAddress1(Address.builder().build()) + .build().toBuilder() + .tempAddress2Required(NO) + .tempAddress2(newAddress2) + .respondentSolicitor2ServiceAddressRequired(NO) + .respondentSolicitor2ServiceAddress(newAddress2) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); @@ -775,28 +849,52 @@ void updateRespondent2AddressWhenUpdated() { // Then assertThat(response.getData()) .extracting("respondent2").extracting("primaryAddress") - .extracting("AddressLine1").isEqualTo("address line 1"); + .extracting("AddressLine1").isEqualTo(newAddress2.getAddressLine1()); assertThat(response.getData()) .extracting("respondent2").extracting("primaryAddress") - .extracting("AddressLine2").isEqualTo("address line 2"); + .extracting("AddressLine2").isEqualTo(newAddress2.getAddressLine2()); assertThat(response.getData()) .extracting("respondent2").extracting("primaryAddress") - .extracting("AddressLine3").isEqualTo("address line 3"); + .extracting("AddressLine3").isEqualTo(newAddress2.getAddressLine3()); } @Test - void updateRespondent2AddressWhenSpecAoSRespondent2HomeAddressRequiredIsNO() { + 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); - - Party partyWithPrimaryAddress = PartyBuilder.builder().individual().build(); - partyWithPrimaryAddress.setPrimaryAddress(AddressBuilder.maximal() - .addressLine1("address line 1") - .addressLine2("address line 2") - .addressLine3("address line 3") - .build()); + 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(); CaseData caseData = CaseDataBuilder.builder().atStateApplicantRespondToDefenceAndProceed() .respondent2DQ() @@ -804,420 +902,693 @@ void updateRespondent2AddressWhenSpecAoSRespondent2HomeAddressRequiredIsNO() { .addRespondent2(YES) .respondent2(PartyBuilder.builder().individual().build()) .respondent2Copy(PartyBuilder.builder().individual().build()) - .atSpecAoSRespondent2HomeAddressRequired(NO) - .atSpecAoSRespondent2HomeAddressDetails(AddressBuilder.maximal() - .addressLine1("new address line 1") - .build()) + .build().toBuilder() + .respondent1DQWitnessesSmallClaim(res1witnesses) + .respondent2DQWitnessesSmallClaim(res2witnesses) + .build().toBuilder() + .tempAddress1Required(YES) + .tempAddress1(Address.builder().build()) + .respondent2ResponseDate(dateTime) + .respondent1ResponseDate(dateTime).build().toBuilder() + .tempAddress2Required(NO) + .tempAddress2(AddressBuilder.maximal().build()) .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(deadlinesCalculator.calculateApplicantResponseDeadlineSpec(any(), any())) + .thenReturn(LocalDateTime.now()); + // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle( - callbackParamsOf(caseData, ABOUT_TO_SUBMIT)); + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + var objectMapper = new ObjectMapper(); + objectMapper.findAndRegisterModules(); + objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); // Then - assertThat(response.getData()) - .extracting("respondent2") - .extracting("primaryAddress") - .extracting("AddressLine1") - .isEqualTo("new address line 1"); + + 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 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); + @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"); + } + } - 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() - .respondent1Copy(PartyBuilder.builder().individual().build()) - .addRespondent2(YES) - .respondent2(PartyBuilder.builder().individual().build()) - .respondent2Copy(PartyBuilder.builder().individual().build()) - .atSpecAoSRespondent2HomeAddressRequired(YES) - .build(); + @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(); - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle( - callbackParamsOf(caseData, ABOUT_TO_SUBMIT)); + 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(); - // 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"); - } + 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 defendantResponsePopulatesWitnessesData() { + void shouldUpdateExpertEvents_whenInvokedAndUpdateContactDetailsEnabled_For2DivergeResponse() { // 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(); - - CaseData caseData = CaseDataBuilder.builder().atStateApplicantRespondToDefenceAndProceed() - .respondent2DQ() + when(toggleService.isUpdateContactDetailsEnabled()).thenReturn(true); + + CaseData caseData = CaseData.builder() + .respondent1(PartyBuilder.builder().individual().build()) .respondent1Copy(PartyBuilder.builder().individual().build()) - .atSpecAoSApplicantCorrespondenceAddressRequired(YES) - .addRespondent2(YES) + .respondent1DQ(Respondent1DQ.builder() + .respondent1DQExperts(Experts.builder() + .details(wrapElements(Expert.builder().build())).build()) + .build()) .respondent2(PartyBuilder.builder().individual().build()) .respondent2Copy(PartyBuilder.builder().individual().build()) - .atSpecAoSRespondent2HomeAddressRequired(NO) - .atSpecAoSRespondent2HomeAddressDetails(AddressBuilder.maximal().build()) - .build().toBuilder() - .respondent1DQWitnessesSmallClaim(res1witnesses) - .respondent2DQWitnessesSmallClaim(res2witnesses) - .build().toBuilder() - .respondent2ResponseDate(dateTime) - .respondent1ResponseDate(dateTime).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(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); + // 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(); + + 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_FullAdmission() { + // 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_ADMISSION) + .respondent2ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_ADMISSION) + .ccdCaseReference(354L) + .respondent1ResponseDate(dateTime).build().toBuilder() + .build(); - 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); + 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(); } - @Nested - class HandleLocations { + @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); - @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); + 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(); - 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); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); + // 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"); - } + // Then + assertThat(response.getData().get("respondent1DQExperts")).isNotNull(); + assertThat(response.getData().get("respondent2DQExperts")).isNull(); - @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); + } + + @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(); + + } + + @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); + + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + // Then + assertThat(response.getData().get("respondent1DQWitnesses")).isNotNull(); + assertThat(response.getData().get("respondent2DQWitnesses")).isNull(); + + } + + @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(); + + 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(); - 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); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); + // 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"); - } + // Then + assertThat(response.getData().get("specRespondentCorrespondenceAddressdetails")) + .extracting("PostCode") + .isEqualTo("new postcode"); + assertThat(response.getData().get("respondentSolicitor1ServiceAddress")) + .extracting("PostCode") + .isNull(); + } - @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); + @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(); - 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); + 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(); - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - // 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"); - } + // 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") + ); } @Test - void shouldNullDocuments_whenInvokedAndCaseFileEnabled() { + void shouldUpdateCorrespondence1_whenProvided1v2ss_withSameResponse() { // 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(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(); + .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl("binary-url").build()).build(); CaseData caseData = CaseData.builder() .respondent1(PartyBuilder.builder().individual().build()) @@ -1227,6 +1598,19 @@ void shouldNullDocuments_whenInvokedAndCaseFileEnabled() { .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); @@ -1236,12 +1620,24 @@ void shouldNullDocuments_whenInvokedAndCaseFileEnabled() { .handle(params); // Then - assertThat(response.getData().get("respondent1SpecDefenceResponseDocument")).isNull(); - assertThat(response.getData().get("respondent2SpecDefenceResponseDocument")).isNull(); + 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") + ); } @Test - void shouldUpdateCorrespondence1_whenProvided() { + void shouldUpdateCorrespondence1_whenProvided1v2ss_withSameResponse_withv2copy() { // Given when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); when(mockedStateFlow.isFlagSet(any())).thenReturn(true); @@ -1250,8 +1646,7 @@ void shouldUpdateCorrespondence1_whenProvided() { 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()) @@ -1262,12 +1657,19 @@ void shouldUpdateCorrespondence1_whenProvided() { .respondent1SpecDefenceResponseDocument(testDocument) .respondent2SpecDefenceResponseDocument(testDocument) .isRespondent1(YesOrNo.YES) - .specAoSRespondentCorrespondenceAddressRequired(YesOrNo.NO) - .specAoSRespondentCorrespondenceAddressdetails( + .respondentResponseIsSame(YES) + .respondentSolicitor1ServiceAddressRequired(YesOrNo.NO) + .respondentSolicitor1ServiceAddress( 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); @@ -1280,13 +1682,21 @@ void shouldUpdateCorrespondence1_whenProvided() { assertThat(response.getData().get("specRespondentCorrespondenceAddressdetails")) .extracting("PostCode") .isEqualTo("new postcode"); - assertThat(response.getData().get("specAoSRespondentCorrespondenceAddressdetails")) + 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") + ); } @Test - void shouldUpdateCorrespondence1_whenProvided1v2ss() { + void shouldUpdateCorrespondence1_whenProvided1v2ss_withSameResponse_withv2copyAndNoTempAdr() { // Given when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); when(mockedStateFlow.isFlagSet(any())).thenReturn(true); @@ -1295,8 +1705,7 @@ void shouldUpdateCorrespondence1_whenProvided1v2ss() { 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()) @@ -1307,8 +1716,9 @@ void shouldUpdateCorrespondence1_whenProvided1v2ss() { .respondent1SpecDefenceResponseDocument(testDocument) .respondent2SpecDefenceResponseDocument(testDocument) .isRespondent1(YesOrNo.YES) - .specAoSRespondentCorrespondenceAddressRequired(YesOrNo.NO) - .specAoSRespondentCorrespondenceAddressdetails( + .respondentResponseIsSame(YES) + .respondentSolicitor1ServiceAddressRequired(YesOrNo.NO) + .respondentSolicitor1ServiceAddress( Address.builder() .postCode("new postcode") .build() @@ -1317,7 +1727,9 @@ void shouldUpdateCorrespondence1_whenProvided1v2ss() { .type(Party.Type.COMPANY) .companyName("Company 3") .build()) + .respondent2Copy(PartyBuilder.builder().individual().build()) .respondent2SameLegalRepresentative(YES) + .tempAddress2Required(NO) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); @@ -1330,7 +1742,7 @@ void shouldUpdateCorrespondence1_whenProvided1v2ss() { assertThat(response.getData().get("specRespondentCorrespondenceAddressdetails")) .extracting("PostCode") .isEqualTo("new postcode"); - assertThat(response.getData().get("specAoSRespondentCorrespondenceAddressdetails")) + assertThat(response.getData().get("respondentSolicitor1ServiceAddress")) .extracting("PostCode") .isNull(); assertEquals( @@ -1352,20 +1764,21 @@ 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) - .specAoSRespondent2CorrespondenceAddressRequired(YesOrNo.NO) - .specAoSRespondent2CorrespondenceAddressdetails( + .respondentSolicitor2ServiceAddressRequired(YesOrNo.NO) + .respondentSolicitor2ServiceAddress( Address.builder() .postCode("new postcode") .build() @@ -1382,7 +1795,7 @@ void shouldUpdateCorrespondence2_whenProvided() { assertThat(response.getData().get("specRespondent2CorrespondenceAddressdetails")) .extracting("PostCode") .isEqualTo("new postcode"); - assertThat(response.getData().get("specAoSRespondent2CorrespondenceAddressdetails")) + assertThat(response.getData().get("respondentSolicitor2ServiceAddress")) .extracting("PostCode") .isNull(); } @@ -1412,6 +1825,58 @@ 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 @@ -1474,6 +1939,26 @@ 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. @@ -1564,7 +2049,6 @@ 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) @@ -1653,9 +2137,6 @@ 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()) @@ -2063,12 +2544,12 @@ void whenProvided_thenValidateCorrespondence1() { CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build() .toBuilder() .isRespondent1(YES) - .specAoSRespondentCorrespondenceAddressRequired(YesOrNo.NO) - .specAoSRespondentCorrespondenceAddressdetails(Address.builder() + .respondentSolicitor1ServiceAddressRequired(YesOrNo.NO) + .respondentSolicitor1ServiceAddress(Address.builder() .postCode("postal code") .build()) .build(); - CallbackParams params = callbackParamsOf(caseData, MID, "confirm-details"); + CallbackParams params = callbackParamsOf(caseData, MID, "specCorrespondenceAddress"); when(postcodeValidator.validate("postal code")).thenReturn(Collections.emptyList()); // When @@ -2085,12 +2566,12 @@ void whenProvided_thenValidateCorrespondence2() { CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build() .toBuilder() .isRespondent2(YES) - .specAoSRespondent2CorrespondenceAddressRequired(YesOrNo.NO) - .specAoSRespondent2CorrespondenceAddressdetails(Address.builder() - .postCode("postal code") - .build()) + .respondentSolicitor2ServiceAddressRequired(YesOrNo.NO) + .respondentSolicitor2ServiceAddress(Address.builder() + .postCode("postal code") + .build()) .build(); - CallbackParams params = callbackParamsOf(caseData, MID, "confirm-details"); + CallbackParams params = callbackParamsOf(caseData, MID, "specCorrespondenceAddress"); when(postcodeValidator.validate("postal code")).thenReturn(Collections.emptyList()); // When @@ -2320,10 +2801,55 @@ 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); } + } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandlerTest.java index 9eae8beac2d..9b5371b1f9f 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandlerTest.java @@ -94,6 +94,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START; @@ -1369,8 +1370,8 @@ void shouldSetUpPaymentDateToString() { when(featureToggleService.isPinInPostEnabled()).thenReturn(true); given(workingDayIndicator.isWorkingDay(any())).willReturn(true); - LocalDate whenWillPay = LocalDate.now().plusDays(5); - given(deadlineCalculatorService.calculateExtendedDeadline(any())).willReturn(whenWillPay); + LocalDate whenWillPay = LocalDate.now(); + given(deadlineCalculatorService.calculateExtendedDeadline(any(), anyInt())).willReturn(whenWillPay); RespondToClaimAdmitPartLRspec respondToClaimAdmitPartLRspec = RespondToClaimAdmitPartLRspec.builder() @@ -1397,9 +1398,8 @@ void shouldSetUpPaymentDateToString() { void shouldSetUpPaymentDateToStringForPartAdmitPaid() { when(featureToggleService.isPinInPostEnabled()).thenReturn(true); - given(workingDayIndicator.isWorkingDay(any())).willReturn(true); LocalDate whenWillPay = LocalDate.now().plusDays(5); - given(deadlineCalculatorService.calculateExtendedDeadline(any())).willReturn(whenWillPay); + given(deadlineCalculatorService.calculateExtendedDeadline(any(), anyInt())).willReturn(whenWillPay); RespondToClaim respondToAdmittedClaim = RespondToClaim.builder() @@ -1428,8 +1428,8 @@ void shouldSetUpPaymentDateForResponseDateToString() { when(featureToggleService.isPinInPostEnabled()).thenReturn(true); given(workingDayIndicator.isWorkingDay(any())).willReturn(true); - LocalDate whenWillPay = LocalDate.now().plusDays(5); - given(deadlineCalculatorService.calculateExtendedDeadline(any())).willReturn(whenWillPay); + LocalDate whenWillPay = LocalDate.now(); + given(deadlineCalculatorService.calculateExtendedDeadline(any(), anyInt())).willReturn(whenWillPay); CaseData caseData = CaseData.builder() .respondent1ResponseDate(LocalDateTime.now()) diff --git a/src/test/java/uk/gov/hmcts/reform/civil/sampledata/CaseDataBuilder.java b/src/test/java/uk/gov/hmcts/reform/civil/sampledata/CaseDataBuilder.java index 4b2a4a05581..df35ed83ab4 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/sampledata/CaseDataBuilder.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/sampledata/CaseDataBuilder.java @@ -488,6 +488,15 @@ public class CaseDataBuilder { private NotSuitableSdoOptions notSuitableSdoOptions; + private List> applicant1LRIndividuals; + private List> respondent1LRIndividuals; + private List> respondent2LRIndividuals; + + private List> applicant1OrgIndividuals; + private List> applicant2OrgIndividuals; + private List> respondent1OrgIndividuals; + private List> respondent2OrgIndividuals; + protected String hearingReference; protected ListingOrRelisting listingOrRelisting; @@ -6131,6 +6140,125 @@ public CaseDataBuilder atTrialHearingWitnessOfFactWithNegativeInputs() { return this; } + public CaseDataBuilder addApplicantLRIndividual(String firstName, String lastName) { + List> individual = + wrapElements(PartyFlagStructure.builder() + .partyID("app-lr-ind-party-id") + .firstName(firstName) + .lastName(lastName) + .email("abc@def.ghi") + .phone("07777777777") + .build()); + if (this.applicant1LRIndividuals != null && !this.applicant1LRIndividuals.isEmpty()) { + this.applicant1LRIndividuals.addAll(individual); + } else { + this.applicant1LRIndividuals = individual; + } + return this; + } + + public CaseDataBuilder addRespondent1LRIndividual(String firstName, String lastName) { + List> individual = + wrapElements(PartyFlagStructure.builder() + .partyID("res-1-lr-ind-party-id") + .firstName(firstName) + .lastName(lastName) + .email("abc@def.ghi") + .phone("07777777777") + .build()); + if (this.respondent1LRIndividuals != null && !this.respondent1LRIndividuals.isEmpty()) { + this.respondent1LRIndividuals.addAll(individual); + } else { + this.respondent1LRIndividuals = individual; + } + return this; + } + + public CaseDataBuilder addRespondent2LRIndividual(String firstName, String lastName) { + List> individual = + wrapElements(PartyFlagStructure.builder() + .partyID("res-2-lr-ind-party-id") + .firstName(firstName) + .lastName(lastName) + .email("abc@def.ghi") + .phone("07777777777") + .build()); + if (this.respondent2LRIndividuals != null && !this.respondent2LRIndividuals.isEmpty()) { + this.respondent2LRIndividuals.addAll(individual); + } else { + this.respondent2LRIndividuals = individual; + } + return this; + } + + public CaseDataBuilder addApplicant1OrgIndividual(String firstName, String lastName) { + List> individual = + wrapElements(PartyFlagStructure.builder() + .partyID("app-1-org-ind-party-id") + .firstName(firstName) + .lastName(lastName) + .email("abc@def.ghi") + .phone("07777777777") + .build()); + if (this.applicant1OrgIndividuals != null && !this.applicant1OrgIndividuals.isEmpty()) { + this.applicant1OrgIndividuals.addAll(individual); + } else { + this.applicant1OrgIndividuals = individual; + } + return this; + } + + public CaseDataBuilder addApplicant2OrgIndividual(String firstName, String lastName) { + List> individual = + wrapElements(PartyFlagStructure.builder() + .partyID("app-2-org-ind-party-id") + .firstName(firstName) + .lastName(lastName) + .email("abc@def.ghi") + .phone("07777777777") + .build()); + if (this.applicant2OrgIndividuals != null && !this.applicant2OrgIndividuals.isEmpty()) { + this.applicant2OrgIndividuals.addAll(individual); + } else { + this.applicant2OrgIndividuals = individual; + } + return this; + } + + public CaseDataBuilder addRespondent1OrgIndividual(String firstName, String lastName) { + List> individual = + wrapElements(PartyFlagStructure.builder() + .partyID("res-1-org-ind-party-id") + .firstName(firstName) + .lastName(lastName) + .email("abc@def.ghi") + .phone("07777777777") + .build()); + if (this.respondent1OrgIndividuals != null && !this.respondent1OrgIndividuals.isEmpty()) { + this.respondent1OrgIndividuals.addAll(individual); + } else { + this.respondent1OrgIndividuals = individual; + } + return this; + } + + public CaseDataBuilder addRespondent2OrgIndividual(String firstName, String lastName) { + List> individual = + wrapElements(PartyFlagStructure.builder() + .partyID("res-2-org-ind-party-id") + .firstName(firstName) + .lastName(lastName) + .email("abc@def.ghi") + .phone("07777777777") + .build()); + if (this.respondent2OrgIndividuals != null && !this.respondent2OrgIndividuals.isEmpty()) { + this.respondent2OrgIndividuals.addAll(individual); + } else { + this.respondent2OrgIndividuals = individual; + } + return this; + } + public static CaseDataBuilder builder() { return new CaseDataBuilder(); } @@ -6416,6 +6544,13 @@ public CaseData build() { .drawDirectionsOrderRequired(drawDirectionsOrderRequired) .transferCourtLocationList(transferCourtLocationList) .reasonForTransfer(reasonForTransfer) + .applicant1LRIndividuals(applicant1LRIndividuals) + .respondent1LRIndividuals(respondent1LRIndividuals) + .respondent2LRIndividuals(respondent2LRIndividuals) + .applicant1OrgIndividuals(applicant1OrgIndividuals) + .applicant2OrgIndividuals(applicant2OrgIndividuals) + .respondent1OrgIndividuals(respondent1OrgIndividuals) + .respondent2OrgIndividuals(respondent2OrgIndividuals) .build(); } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/GenAppStateHelperServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/GenAppStateHelperServiceTest.java index 6aa26270c72..f6626efde69 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/GenAppStateHelperServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/GenAppStateHelperServiceTest.java @@ -18,14 +18,19 @@ import uk.gov.hmcts.reform.civil.model.genapplication.CaseLocationCivil; import uk.gov.hmcts.reform.civil.model.genapplication.GADetailsRespondentSol; import uk.gov.hmcts.reform.civil.model.genapplication.GeneralApplicationsDetails; +import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService; +import uk.gov.hmcts.reform.civil.referencedata.model.LocationRefData; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.sampledata.GeneralApplicationDetailsBuilder; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; @@ -50,13 +55,19 @@ class GenAppStateHelperServiceTest { @MockBean private CoreCaseDataService coreCaseDataService; + @MockBean + private InitiateGeneralApplicationService genAppService; @Autowired private CaseDetailsConverter caseDetailsConverter; + @MockBean + private LocationRefDataService locationRefDataService; + private static final String APPLICATION_CLOSED_TEXT = "Application Closed"; private static final String APPLICATION_OFFLINE_TEXT = "Proceeds In Heritage"; private static final String SET_DATE = "2022-08-31T22:50:11.2509019"; + private static final String authToken = "Bearer TestAuthToken"; @Nested class StatusChangeInApplicationDetailsInClaim { @@ -393,6 +404,10 @@ private CaseDetails getCaseDetails( @Test void updateApplicationLocationDetailsLists() { + when(locationRefDataService.getCourtLocationsByEpimmsId(any(), any())) + .thenReturn(getSampleCourLocationsRefObject()); + when(genAppService.getWorkAllocationLocationDetails(any(), any())) + .thenReturn(getSampleCourLocationsRefObject1()); CaseData caseData = GeneralApplicationDetailsBuilder.builder() .getTestCaseDataWithDetails(CaseData.builder().build(), true, @@ -404,8 +419,10 @@ void updateApplicationLocationDetailsLists() { Pair caseLocation = Pair.of(CaseLocationCivil.builder() .region("2") .baseLocation("00000").siteName("locationOfRegion2") + .address("Prince William House, Peel Cross Road, Salford") + .postcode("M5 4RR") .build(), false); - CaseData updatedData = service.updateApplicationLocationDetailsInClaim(caseData); + CaseData updatedData = service.updateApplicationLocationDetailsInClaim(caseData, authToken); assertThat(getGADetailsFromUpdatedCaseData(updatedData, "1234")).isNotNull(); assertThat(updatedData.getGeneralApplications().get(0).getValue().getCaseManagementLocation()).isEqualTo(caseLocation.getLeft()); @@ -416,6 +433,23 @@ void updateApplicationLocationDetailsLists() { assertThat(updatedData.getGeneralApplications().get(2).getValue().getIsCcmccLocation()).isEqualTo(YesOrNo.NO); } + protected List getSampleCourLocationsRefObject() { + return new ArrayList<>(List.of( + LocationRefData.builder() + .epimmsId("00000").siteName("locationOfRegion2").courtAddress("Prince William House, Peel Cross Road, Salford") + .postcode("M5 4RR") + .courtLocationCode("court1").build() + )); + } + + protected LocationRefData getSampleCourLocationsRefObject1() { + return + LocationRefData.builder() + .epimmsId("00000").siteName("locationOfRegion2").courtAddress("Prince William House, Peel Cross Road, Salford") + .postcode("M5 4RR") + .courtLocationCode("court1").build(); + } + @Test void noLocationUpdatesToCaseDataIfThereAreNoGeneralApplications() { setupForApplicationOffline(); @@ -427,8 +461,7 @@ void noLocationUpdatesToCaseDataIfThereAreNoGeneralApplications() { Map.of() ); - CaseData response = service.updateApplicationLocationDetailsInClaim( - caseData); + CaseData response = service.updateApplicationLocationDetailsInClaim(caseData, authToken); CaseData updatedData = mapper.convertValue(response, CaseData.class); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/InitiateGeneralApplicationServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/InitiateGeneralApplicationServiceTest.java index 3eabd89f790..c4e659ce307 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/InitiateGeneralApplicationServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/InitiateGeneralApplicationServiceTest.java @@ -901,7 +901,8 @@ void shouldPopulateApplicantDetails() { CaseData caseData = GeneralApplicationDetailsBuilder.builder() .getTestCaseDataForConsentUnconsentCheck(GARespondentOrderAgreement.builder().hasAgreed(NO).build()); when(locationRefDataService.getCcmccLocation(any())) - .thenReturn(LocationRefData.builder().regionId("9").epimmsId("574546").siteName("CCMCC").build()); + .thenReturn(LocationRefData.builder().regionId("9").epimmsId("574546").siteName("CCMCC") + .courtAddress("Prince William House, Peel Cross Road, Salford").postcode("M5 4RR").build()); CaseData result = service.buildCaseData(caseData.toBuilder(), caseData, UserDetails.builder() .email(APPLICANT_EMAIL_ID_CONSTANT).id(STRING_NUM_CONSTANT).build(), CallbackParams.builder().toString()); @@ -914,11 +915,98 @@ void shouldPopulateApplicantDetails() { assertThat(result.getGeneralApplications().get(0).getValue().getLocationName()) .isEqualTo("CCMCC"); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getAddress()) + .isEqualTo("Prince William House, Peel Cross Road, Salford"); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getPostcode()) + .isEqualTo("M5 4RR"); assertThat(result.getGeneralApplications().get(0).getValue().getGeneralAppRespondentSolicitors() .stream().filter(e -> STRING_NUM_CONSTANT.equals(e.getValue().getId())).count()).isEqualTo(0); } + @Test + void shouldPopulateLocationDetailsForBaseLocation() { + when(locationRefDataService.getCourtLocationsByEpimmsId(any(), any())).thenReturn(getSampleCourLocationsRefObject()); + CaseData caseData = GeneralApplicationDetailsBuilder.builder() + .getCaseDataForWorkAllocation(null, null, INDIVIDUAL, applicant1DQ, respondent1DQ, + respondent2DQ); + CaseData result = service.buildCaseData(caseData.toBuilder(), caseData, UserDetails.builder() + .email(APPLICANT_EMAIL_ID_CONSTANT).build(), CallbackParams.builder().toString()); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getBaseLocation()) + .isEqualTo("11111"); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getSiteName()) + .isEqualTo("locationOfRegion2"); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getAddress()) + .isEqualTo("Prince William House, Peel Cross Road, Salford"); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getPostcode()) + .isEqualTo("M5 4RR"); + } + + protected List getSampleCourLocationsRefObject() { + return new ArrayList<>(List.of( + LocationRefData.builder() + .epimmsId("11111").siteName("locationOfRegion2").courtAddress("Prince William House, Peel Cross Road, Salford") + .postcode("M5 4RR") + .courtLocationCode("court1").build() + )); + } + + protected List getEmptyCourLocationsRefObject() { + return new ArrayList<>(List.of( + LocationRefData.builder().build() + )); + } + + protected List getSampleCourtLocationsRefObjectMultipleValues() { + return new ArrayList<>(List.of( + LocationRefData.builder() + .epimmsId("11111").siteName("locationOfRegion2").courtAddress("Prince William House, Peel Cross Road, Salford") + .postcode("M5 4RR") + .courtLocationCode("court1").build(), + + LocationRefData.builder() + .epimmsId("11111").siteName("locationOfRegion2").courtAddress("Prince William House, Peel Cross Road, Salford") + .postcode("M5 4RR") + .courtLocationCode("court1").build() + )); + } + + @Test + void shouldPopulateLocationDetailsForBaseLocationWhereListIsEmpty() { + when(locationRefDataService.getCourtLocationsByEpimmsId(any(), any())).thenReturn(getEmptyCourLocationsRefObject()); + CaseData caseData = GeneralApplicationDetailsBuilder.builder() + .getCaseDataForWorkAllocation(null, null, INDIVIDUAL, applicant1DQ, respondent1DQ, + respondent2DQ); + CaseData result = service.buildCaseData(caseData.toBuilder(), caseData, UserDetails.builder() + .email(APPLICANT_EMAIL_ID_CONSTANT).build(), CallbackParams.builder().toString()); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getBaseLocation()) + .isEqualTo("11111"); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getSiteName()) + .isNull(); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getAddress()) + .isNull(); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getPostcode()) + .isNull(); + } + + @Test + void shouldPopulateLocationDetailsForBaseLocationWithMultipleListValues() { + when(locationRefDataService.getCourtLocationsByEpimmsId(any(), any())).thenReturn(getSampleCourtLocationsRefObjectMultipleValues()); + CaseData caseData = GeneralApplicationDetailsBuilder.builder() + .getCaseDataForWorkAllocation(null, null, INDIVIDUAL, applicant1DQ, respondent1DQ, + respondent2DQ); + CaseData result = service.buildCaseData(caseData.toBuilder(), caseData, UserDetails.builder() + .email(APPLICANT_EMAIL_ID_CONSTANT).build(), CallbackParams.builder().toString()); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getBaseLocation()) + .isEqualTo("11111"); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getSiteName()) + .isEqualTo("locationOfRegion2"); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getAddress()) + .isEqualTo("Prince William House, Peel Cross Road, Salford"); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getPostcode()) + .isEqualTo("M5 4RR"); + } + @Test void shouldPopulateWorkAllocationLocationOnAboutToSubmit_beforeSDOHasBeenMade() { when(locationRefDataService.getCcmccLocation(any())) diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/citizenui/responsedeadline/DeadlineExtensionCalculatorServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/citizenui/responsedeadline/DeadlineExtensionCalculatorServiceTest.java index 736974f4cce..dcc0e6f718c 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/citizenui/responsedeadline/DeadlineExtensionCalculatorServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/citizenui/responsedeadline/DeadlineExtensionCalculatorServiceTest.java @@ -26,30 +26,54 @@ public class DeadlineExtensionCalculatorServiceTest { @Test void shouldReturnTheSameGivenDateWhenDateIsWorkday() { - given(workingDayIndicator.isWorkingDay(any())).willReturn(true); + given(workingDayIndicator.getNextWorkingDay(any())).willReturn(LocalDate.now()); LocalDate proposedExtensionDeadline = LocalDate.now(); LocalDate calculatedDeadline = deadlineExtensionCalculatorService.calculateExtendedDeadline( - proposedExtensionDeadline); + proposedExtensionDeadline, 0); assertThat(calculatedDeadline).isEqualTo(proposedExtensionDeadline); - verify(workingDayIndicator).isWorkingDay(proposedExtensionDeadline); - verify(workingDayIndicator, never()).getNextWorkingDay(proposedExtensionDeadline); + verify(workingDayIndicator).getNextWorkingDay(proposedExtensionDeadline); + verify(workingDayIndicator, never()).isWorkingDay(proposedExtensionDeadline); } @Test void shouldReturnNextWorkingDayWhenDateIsHoliday() { - given(workingDayIndicator.isWorkingDay(any())).willReturn(false); + LocalDate proposedExtensionDeadline = LocalDate.of(2022, 6, 3); LocalDate calculatedNextWorkingDay = LocalDate.of(2022, 6, 4); + given(workingDayIndicator.getNextWorkingDay(any())).willReturn(calculatedNextWorkingDay); - LocalDate proposedExtensionDeadline = LocalDate.of(2022, 6, 3); LocalDate calculatedDeadline = deadlineExtensionCalculatorService.calculateExtendedDeadline( - proposedExtensionDeadline); + proposedExtensionDeadline, 0); assertThat(calculatedDeadline).isEqualTo(calculatedNextWorkingDay); - verify(workingDayIndicator).isWorkingDay(proposedExtensionDeadline); - verify(workingDayIndicator).getNextWorkingDay(proposedExtensionDeadline); + verify(workingDayIndicator, never()).isWorkingDay(calculatedNextWorkingDay); + } + + @Test + void shouldReturnFifthWorkingDayFromTheGivenDateWhen_NoHoliday_NoWeekend_InBetween() { + given(workingDayIndicator.isWorkingDay(any())).willReturn(true); + LocalDate proposedExtensionDeadline = LocalDate.of(2023, 11, 17); + LocalDate expectedExtensionDeadline = LocalDate.of(2023, 11, 22); + + LocalDate calculatedDeadline = deadlineExtensionCalculatorService.calculateExtendedDeadline( + proposedExtensionDeadline, 5); + + assertThat(calculatedDeadline).isEqualTo(expectedExtensionDeadline); + } + + @Test + void shouldReturnFifthWorkingDayFromTheGivenDateWhen_Holiday_InBetween() { + given(workingDayIndicator.isWorkingDay(any())).willReturn(true); + given(workingDayIndicator.isWorkingDay(LocalDate.of(2023, 11, 19))).willReturn(false); + LocalDate proposedExtensionDeadline = LocalDate.of(2023, 11, 17); + LocalDate expectedExtensionDeadline = LocalDate.of(2023, 11, 23); + + LocalDate calculatedDeadline = deadlineExtensionCalculatorService.calculateExtendedDeadline( + proposedExtensionDeadline, 5); + + assertThat(calculatedDeadline).isEqualTo(expectedExtensionDeadline); } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/sealedclaim/SealedClaimLipResponseFormGeneratorTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/sealedclaim/SealedClaimLipResponseFormGeneratorTest.java index 299d334a0e7..ab25f0fbe0e 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/sealedclaim/SealedClaimLipResponseFormGeneratorTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/sealedclaim/SealedClaimLipResponseFormGeneratorTest.java @@ -118,15 +118,20 @@ void shouldGenerateDocumentSuccessfully() { @Test void admitPayImmediate() { - CaseData caseData = commonData() + LocalDate whenWillPay = LocalDate.now().plusDays(5); + CaseData.CaseDataBuilder builder = commonData() .respondent1(company("B")) .respondent2(individual("C")) .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_ADMISSION) .defenceAdmitPartPaymentTimeRouteRequired(RespondentResponsePartAdmissionPaymentTimeLRspec.IMMEDIATELY) - .build(); + .respondToClaimAdmitPartLRspec( + RespondToClaimAdmitPartLRspec.builder() + .whenWillThisAmountBePaid(whenWillPay) + .build() + ); SealedClaimLipResponseForm templateData = generator - .getTemplateData(caseData); + .getTemplateData(builder.build()); Assertions.assertEquals(LocalDate.now(), templateData.getGenerationDate()); } @@ -174,6 +179,7 @@ void admitPayByDate() { @Test void partAdmitPayImmediate() { + LocalDate whenWillPay = LocalDate.now().plusDays(5); CaseData.CaseDataBuilder builder = commonData() .respondent1(company("B")) .respondent2(individual("C")) @@ -181,7 +187,12 @@ void partAdmitPayImmediate() { .specDefenceAdmittedRequired(YesOrNo.NO) .respondToAdmittedClaimOwingAmount(BigDecimal.valueOf(2000)) .detailsOfWhyDoesYouDisputeTheClaim("Reason to dispute the claim") - .defenceAdmitPartPaymentTimeRouteRequired(RespondentResponsePartAdmissionPaymentTimeLRspec.IMMEDIATELY); + .defenceAdmitPartPaymentTimeRouteRequired(RespondentResponsePartAdmissionPaymentTimeLRspec.IMMEDIATELY) + .respondToClaimAdmitPartLRspec( + RespondToClaimAdmitPartLRspec.builder() + .whenWillThisAmountBePaid(whenWillPay) + .build() + ); CaseData caseData = timeline(financialDetails(builder)) .build(); @@ -340,11 +351,17 @@ void counterClaim() { @Test void shouldGenerateDocumentSuccessfullyForFullAdmit() { //Given + LocalDate whenWillPay = LocalDate.now().plusDays(5); CaseData caseData = commonData() .respondent1(company("B")) .respondent2(individual("C")) .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_ADMISSION) .defenceAdmitPartPaymentTimeRouteRequired(RespondentResponsePartAdmissionPaymentTimeLRspec.IMMEDIATELY) + .respondToClaimAdmitPartLRspec( + RespondToClaimAdmitPartLRspec.builder() + .whenWillThisAmountBePaid(whenWillPay) + .build() + ) .build(); String fileName = "someName"; DocmosisDocument docmosisDocument = mock(DocmosisDocument.class); @@ -365,6 +382,7 @@ void shouldGenerateDocumentSuccessfullyForFullAdmit() { @Test void shouldGenerateDocumentSuccessfullyForPartAdmit() { //Given + LocalDate whenWillPay = LocalDate.now().plusDays(5); CaseData caseData = commonData() .respondent1(company("B")) .respondent2(individual("C")) @@ -373,7 +391,11 @@ void shouldGenerateDocumentSuccessfullyForPartAdmit() { .respondToAdmittedClaimOwingAmount(BigDecimal.valueOf(2000)) .detailsOfWhyDoesYouDisputeTheClaim("Reason to dispute the claim") .defenceAdmitPartPaymentTimeRouteRequired(RespondentResponsePartAdmissionPaymentTimeLRspec.IMMEDIATELY) - .build(); + .respondToClaimAdmitPartLRspec( + RespondToClaimAdmitPartLRspec.builder() + .whenWillThisAmountBePaid(whenWillPay) + .build() + ).build(); String fileName = "someName"; DocmosisDocument docmosisDocument = mock(DocmosisDocument.class); byte[] bytes = {}; diff --git a/src/test/java/uk/gov/hmcts/reform/civil/utils/CaseFlagUtilsTest.java b/src/test/java/uk/gov/hmcts/reform/civil/utils/CaseFlagUtilsTest.java index cca5bf3657e..aae666611d3 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/utils/CaseFlagUtilsTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/utils/CaseFlagUtilsTest.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.reform.civil.utils; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -7,6 +8,7 @@ import uk.gov.hmcts.reform.civil.model.PartyFlagStructure; import uk.gov.hmcts.reform.civil.model.LitigationFriend; import uk.gov.hmcts.reform.civil.model.Party; +import uk.gov.hmcts.reform.civil.model.UpdateDetailsForm; import uk.gov.hmcts.reform.civil.model.caseflags.FlagDetail; import uk.gov.hmcts.reform.civil.model.caseflags.Flags; import uk.gov.hmcts.reform.civil.model.common.Element; @@ -18,15 +20,21 @@ import uk.gov.hmcts.reform.civil.model.dq.Respondent2DQ; import uk.gov.hmcts.reform.civil.model.dq.Witness; import uk.gov.hmcts.reform.civil.model.dq.Witnesses; +import uk.gov.hmcts.reform.civil.prd.model.Organisation; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.sampledata.PartyBuilder; +import uk.gov.hmcts.reform.civil.service.OrganisationService; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; 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.utils.CaseFlagUtils.APPLICANT_SOLICITOR_EXPERT; @@ -39,10 +47,35 @@ import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.addRespondentDQPartiesFlagStructure; import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.filter; import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.getAllCaseFlags; +import static uk.gov.hmcts.reform.civil.utils.ElementUtils.unwrapElements; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.wrapElements; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_LEGAL_REP_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_ORG_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_TWO_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_TWO_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_TWO_ORG_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_LEGAL_REP_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_ORG_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_LEGAL_REP_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_ORG_INDIVIDUALS_ID; class CaseFlagUtilsTest { + private OrganisationService organisationService; + + @BeforeEach + void setUp() { + organisationService = mock(OrganisationService.class); + when(organisationService.findOrganisationById(anyString())) + .thenReturn(Optional.of(Organisation.builder().name("Civil - Organisation").build())); + } + @Nested class CreateFlags { @@ -648,4 +681,663 @@ private List hearingRelevantFlagDetails() { return List.of(details1, details2, details3); } } + + @Nested + class CreateAndUpdateFlagNamesAfterManageContactInformationEvent { + + @Nested + class Parties { + + @Test + void shouldUpdateFlagName_whenClaimant1NameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(CLAIMANT_ONE_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant1(caseData.getApplicant1().toBuilder() + .flags(Flags.builder() + .partyName("Mr. John Rambo") + .roleOnCase("applicant") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .individualFirstName("Johnny") + .individualLastName("Rambo new").build()); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + Flags actual = builder.build().getApplicant1().getFlags(); + Flags expected = Flags.builder().partyName("Mr. Johnny Rambo new") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("applicant").build(); + + assertThat(actual).isEqualTo(expected); + } + + @Test + void shouldUpdateFlagName_whenClaimant2NameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .multiPartyClaimTwoApplicants() + .atStateClaimIssued() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(CLAIMANT_TWO_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant2(caseData.getApplicant2().toBuilder() + .flags(Flags.builder() + .partyName("Mr. Jason Rambo") + .roleOnCase("applicant") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .individualFirstName("JJ") + .individualLastName("Rambo edited").build()); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + Flags actual = builder.build().getApplicant2().getFlags(); + Flags expected = Flags.builder().partyName("Mr. JJ Rambo edited") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("applicant").build(); + + assertThat(actual).isEqualTo(expected); + } + + @Test + void shouldUpdateFlagName_whenRespondent1NameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimIssued() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_ONE_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent1(caseData.getRespondent1().toBuilder() + .flags(Flags.builder() + .partyName("Mr. Sole Trader") + .roleOnCase("respondent") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .soleTraderFirstName("Solo") + .soleTraderLastName("New trader").build()); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + Flags actual = builder.build().getRespondent1().getFlags(); + Flags expected = Flags.builder().partyName("Mr. Solo New trader") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("respondent").build(); + + assertThat(actual).isEqualTo(expected); + } + + @Test + void shouldUpdateFlagName_whenRespondent2NameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimIssued() + .multiPartyClaimTwoDefendantSolicitors() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_TWO_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent2(caseData.getRespondent2().toBuilder() + .flags(Flags.builder() + .partyName("Mr. John Rambo") + .roleOnCase("respondent") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .individualTitle("Miss") + .individualFirstName("Jenny") + .individualLastName("Rombo").build()); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + Flags actual = builder.build().getRespondent2().getFlags(); + Flags expected = Flags.builder().partyName("Miss Jenny Rombo") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("respondent").build(); + + assertThat(actual).isEqualTo(expected); + } + } + + @Nested + class LitigationFriend { + + @Test + void shouldUpdateFlagName_whenClaimant1LitigationFriendNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .addApplicant1LitigationFriend() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(CLAIMANT_ONE_LITIGATION_FRIEND_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant1LitigationFriend(caseData.getApplicant1LitigationFriend().toBuilder() + .flags(Flags.builder() + .partyName("Mr. Applicant Litigation Friend") + .roleOnCase("litigation friend") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .fullName(null) + .firstName("Johnny").lastName("Rambo new") + .build()); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + Flags actual = builder.build().getApplicant1LitigationFriend().getFlags(); + Flags expected = Flags.builder().partyName("Johnny Rambo new") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("litigation friend").build(); + + assertThat(actual).isEqualTo(expected); + } + + @Test + void shouldUpdateFlagName_whenClaimant2LitigationFriendNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .addApplicant2LitigationFriend() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(CLAIMANT_TWO_LITIGATION_FRIEND_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant2LitigationFriend(caseData.getApplicant2LitigationFriend().toBuilder() + .flags(Flags.builder() + .partyName("Applicant Two Litigation Friend") + .roleOnCase("litigation friend") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .fullName(null) + .firstName("Johnny").lastName("Rambo new") + .build()); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + Flags actual = builder.build().getApplicant2LitigationFriend().getFlags(); + Flags expected = Flags.builder().partyName("Johnny Rambo new") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("litigation friend").build(); + + assertThat(actual).isEqualTo(expected); + } + + @Test + void shouldUpdateFlagName_whenRespondent1LitigationFriendNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .addRespondent1LitigationFriend() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_ONE_LITIGATION_FRIEND_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent1LitigationFriend(caseData.getRespondent1LitigationFriend().toBuilder() + .flags(Flags.builder() + .partyName("Litigation Friend") + .roleOnCase("litigation friend") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .fullName(null) + .firstName("Johnny").lastName("Rambo new") + .build()); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + Flags actual = builder.build().getRespondent1LitigationFriend().getFlags(); + Flags expected = Flags.builder().partyName("Johnny Rambo new") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("litigation friend").build(); + + assertThat(actual).isEqualTo(expected); + } + + @Test + void shouldUpdateFlagName_whenRespondent2LitigationFriendNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .multiPartyClaimTwoDefendantSolicitors() + .atStateApplicantRespondToDefenceAndProceed() + .addRespondent2LitigationFriend() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_TWO_LITIGATION_FRIEND_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent2LitigationFriend(caseData.getRespondent2LitigationFriend().toBuilder() + .flags(Flags.builder() + .partyName("Litigation Friend") + .roleOnCase("litigation friend") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .fullName(null) + .firstName("Johnny").lastName("Rambo new") + .build()); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + Flags actual = builder.build().getRespondent2LitigationFriend().getFlags(); + Flags expected = Flags.builder().partyName("Johnny Rambo new") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("litigation friend").build(); + + assertThat(actual).isEqualTo(expected); + } + } + + @Nested + class LegalRepIndividuals { + + @Test + void shouldCreateFlag_whenClaimantLRIndividualAdded() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(CLAIMANT_ONE_LEGAL_REP_INDIVIDUALS_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant1LRIndividuals(wrapElements(PartyFlagStructure.builder() + .firstName("Legally").lastName("Rep") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getApplicant1LRIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Legally Rep") + .details(List.of()) + .roleOnCase("Civil - Organisation").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isNotNull(); + } + + @Test + void shouldUpdateFlagName_whenClaimantLRIndividualNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .addApplicantLRIndividual("Legal", "Rep") + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(CLAIMANT_ONE_LEGAL_REP_INDIVIDUALS_ID).build()) + .build(); + + PartyFlagStructure lrIndividual = unwrapElements(caseData.getApplicant1LRIndividuals()).get(0); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant1LRIndividuals(wrapElements(lrIndividual.toBuilder() + .flags(Flags.builder() + .partyName("Legal Rep") + .roleOnCase("Civil - Organisation") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .firstName("Legally").lastName("Rep") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getApplicant1LRIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Legally Rep") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("Civil - Organisation").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isEqualTo("app-lr-ind-party-id"); + } + + @Test + void shouldCreateFlag_whenRespondent1LRIndividualAdded() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_ONE_LEGAL_REP_INDIVIDUALS_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent1LRIndividuals(wrapElements(PartyFlagStructure.builder() + .firstName("Legally").lastName("Rep") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getRespondent1LRIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Legally Rep") + .details(List.of()) + .roleOnCase("Civil - Organisation").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isNotNull(); + } + + @Test + void shouldUpdateFlagName_whenRespondent1LRIndividualNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .addRespondent1LRIndividual("Legal", "Rep") + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_ONE_LEGAL_REP_INDIVIDUALS_ID).build()) + .build(); + + PartyFlagStructure lrIndividual = unwrapElements(caseData.getRespondent1LRIndividuals()).get(0); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent1LRIndividuals(wrapElements(lrIndividual.toBuilder() + .flags(Flags.builder() + .partyName("Legal Rep") + .roleOnCase("Civil - Organisation") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .firstName("Legally").lastName("Rep") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getRespondent1LRIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Legally Rep") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("Civil - Organisation").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isEqualTo("res-1-lr-ind-party-id"); + } + + @Test + void shouldCreateFlag_whenRespondent2LRIndividualAdded() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_TWO_LEGAL_REP_INDIVIDUALS_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent2LRIndividuals(wrapElements(PartyFlagStructure.builder() + .firstName("Legally").lastName("Rep") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getRespondent2LRIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Legally Rep") + .details(List.of()) + .roleOnCase("Civil - Organisation").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isNotNull(); + } + + @Test + void shouldUpdateFlagName_whenRespondent2LRIndividualNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .addRespondent2LRIndividual("Legal", "Rep") + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_TWO_LEGAL_REP_INDIVIDUALS_ID).build()) + .build(); + + PartyFlagStructure lrIndividual = unwrapElements(caseData.getRespondent2LRIndividuals()).get(0); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent2LRIndividuals(wrapElements(lrIndividual.toBuilder() + .flags(Flags.builder() + .partyName("Legal Rep") + .roleOnCase("Civil - Organisation") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .firstName("Legally").lastName("Rep") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getRespondent2LRIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Legally Rep") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("Civil - Organisation").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isEqualTo("res-2-lr-ind-party-id"); + } + } + + @Nested + class OrgIndividuals { + + @Test + void shouldCreateFlag_whenClaimant1OrgIndividualAdded() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(CLAIMANT_ONE_ORG_INDIVIDUALS_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant1OrgIndividuals(wrapElements(PartyFlagStructure.builder() + .firstName("Org").lastName("Ind") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getApplicant1OrgIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Org Ind") + .details(List.of()) + .roleOnCase("Mr. John Rambo").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isNotNull(); + } + + @Test + void shouldUpdateFlagName_whenClaimant1OrgIndividualNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .addApplicant1OrgIndividual("Org", "Person") + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(CLAIMANT_ONE_ORG_INDIVIDUALS_ID).build()) + .build(); + + PartyFlagStructure orgIndividual = unwrapElements(caseData.getApplicant1OrgIndividuals()).get(0); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant1OrgIndividuals(wrapElements(orgIndividual.toBuilder() + .flags(Flags.builder() + .partyName("Org Person") + .roleOnCase("Mr. John Rambo") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .firstName("Org").lastName("Ind") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getApplicant1OrgIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Org Ind") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("Mr. John Rambo").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isEqualTo("app-1-org-ind-party-id"); + } + + @Test + void shouldCreateFlag_whenClaimant2OrgIndividualAdded() { + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimIssued() + .multiPartyClaimTwoApplicants() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(CLAIMANT_TWO_ORG_INDIVIDUALS_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant2OrgIndividuals(wrapElements(PartyFlagStructure.builder() + .firstName("Org").lastName("Ind") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getApplicant2OrgIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Org Ind") + .details(List.of()) + .roleOnCase("Mr. Jason Rambo").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isNotNull(); + } + + @Test + void shouldUpdateFlagName_whenClaimant2OrgIndividualNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimIssued() + .multiPartyClaimTwoApplicants() + .addApplicant2OrgIndividual("Org", "Person") + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(CLAIMANT_TWO_ORG_INDIVIDUALS_ID).build()) + .build(); + + PartyFlagStructure orgIndividual = unwrapElements(caseData.getApplicant2OrgIndividuals()).get(0); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant2OrgIndividuals(wrapElements(orgIndividual.toBuilder() + .flags(Flags.builder() + .partyName("Org Person") + .roleOnCase("Mr. Jason Rambo") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .firstName("Org").lastName("Ind") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getApplicant2OrgIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Org Ind") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("Mr. Jason Rambo").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isEqualTo("app-2-org-ind-party-id"); + } + + @Test + void shouldCreateFlag_whenRespondent1OrgIndividualAdded() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_ONE_ORG_INDIVIDUALS_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent1OrgIndividuals(wrapElements(PartyFlagStructure.builder() + .firstName("Org").lastName("Ind") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getRespondent1OrgIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Org Ind") + .details(List.of()) + .roleOnCase("Mr. Sole Trader").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isNotNull(); + } + + @Test + void shouldUpdateFlagName_whenRespondent1OrgIndividualNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .addRespondent1OrgIndividual("Org", "Person") + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_ONE_ORG_INDIVIDUALS_ID).build()) + .build(); + + PartyFlagStructure orgIndividual = unwrapElements(caseData.getRespondent1OrgIndividuals()).get(0); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent1OrgIndividuals(wrapElements(orgIndividual.toBuilder() + .flags(Flags.builder() + .partyName("Org Person") + .roleOnCase("Mr. Sole Trader") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .firstName("Org").lastName("Ind") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getRespondent1OrgIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Org Ind") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("Mr. Sole Trader").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isEqualTo("res-1-org-ind-party-id"); + } + + @Test + void shouldCreateFlag_whenRespondent2OrgIndividualAdded() { + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimIssued() + .multiPartyClaimTwoDefendantSolicitors() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_TWO_ORG_INDIVIDUALS_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent2OrgIndividuals(wrapElements(PartyFlagStructure.builder() + .firstName("Org").lastName("Ind") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getRespondent2OrgIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Org Ind") + .details(List.of()) + .roleOnCase("Mr. John Rambo").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isNotNull(); + } + + @Test + void shouldUpdateFlagName_whenRespondent2OrgIndividualNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimIssued() + .multiPartyClaimTwoDefendantSolicitors() + .addRespondent2OrgIndividual("Org", "Person") + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_TWO_ORG_INDIVIDUALS_ID).build()) + .build(); + + PartyFlagStructure lrIndividual = unwrapElements(caseData.getRespondent2OrgIndividuals()).get(0); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent2OrgIndividuals(wrapElements(lrIndividual.toBuilder() + .flags(Flags.builder() + .partyName("Org Person") + .roleOnCase("Mr. John Rambo") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .firstName("Org").lastName("Ind") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getRespondent2OrgIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Org Ind") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("Mr. John Rambo").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isEqualTo("res-2-org-ind-party-id"); + } + } + } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/utils/CaseFlagsInitialiserTest.java b/src/test/java/uk/gov/hmcts/reform/civil/utils/CaseFlagsInitialiserTest.java index bb546a4f699..334bb719764 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/utils/CaseFlagsInitialiserTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/utils/CaseFlagsInitialiserTest.java @@ -2,6 +2,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import uk.gov.hmcts.reform.ccd.model.OrganisationPolicy; import uk.gov.hmcts.reform.civil.callback.CaseEvent; import uk.gov.hmcts.reform.civil.model.Party; import uk.gov.hmcts.reform.civil.model.PartyFlagStructure; @@ -14,17 +15,23 @@ import uk.gov.hmcts.reform.civil.model.dq.Respondent2DQ; import uk.gov.hmcts.reform.civil.model.dq.Witness; import uk.gov.hmcts.reform.civil.model.dq.Witnesses; -import uk.gov.hmcts.reform.civil.service.FeatureToggleService; +import uk.gov.hmcts.reform.civil.model.UpdateDetailsForm; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.LitigationFriend; import uk.gov.hmcts.reform.civil.model.caseflags.Flags; +import uk.gov.hmcts.reform.civil.prd.model.Organisation; import uk.gov.hmcts.reform.civil.sampledata.PartyBuilder; +import uk.gov.hmcts.reform.civil.service.FeatureToggleService; +import uk.gov.hmcts.reform.civil.service.OrganisationService; import java.util.List; +import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.APPLICANT_SOLICITOR_EXPERT; @@ -35,6 +42,7 @@ import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.RESPONDENT_SOLICITOR_TWO_WITNESS; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.unwrapElements; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.wrapElements; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_LEGAL_REP_INDIVIDUALS_ID; class CaseFlagsInitialiserTest { @@ -42,11 +50,16 @@ class CaseFlagsInitialiserTest { private FeatureToggleService featureToggleService; + private OrganisationService organisationService; + @BeforeEach void setup() { featureToggleService = mock(FeatureToggleService.class); - caseFlagsInitialiser = new CaseFlagsInitialiser(featureToggleService); + organisationService = mock(OrganisationService.class); + caseFlagsInitialiser = new CaseFlagsInitialiser(featureToggleService, organisationService); when(featureToggleService.isCaseFlagsEnabled()).thenReturn(true); + when(organisationService.findOrganisationById(anyString())) + .thenReturn(Optional.of(Organisation.builder().name("Civil - Organisation 1").build())); } @Test @@ -178,6 +191,24 @@ void shouldNotInitialiseCaseFlagsWhenCaseFlagsToggleIsOff() { assertEquals(expected, actual.build()); } + @Test + void shouldInitialiseCaseFlagsForManageContactInformationEvent() { + CaseData caseData = CaseData.builder() + .applicant1OrganisationPolicy(OrganisationPolicy.builder() + .organisation(uk.gov.hmcts.reform.ccd.model.Organisation.builder() + .organisationID("id") + .build()) + .build()) + .updateDetailsForm(UpdateDetailsForm.builder() + .partyChosenId(CLAIMANT_ONE_LEGAL_REP_INDIVIDUALS_ID) + .build()) + .build(); + + caseFlagsInitialiser.initialiseCaseFlags(CaseEvent.MANAGE_CONTACT_INFORMATION, caseData.toBuilder()); + + verify(organisationService).findOrganisationById("id"); + } + @Test void shouldReinitialiseMissingCaseFlags() { Party applicant1 = PartyBuilder.builder().individual().build();