diff --git a/src/main/java/uk/gov/hmcts/reform/civil/callback/CaseEvent.java b/src/main/java/uk/gov/hmcts/reform/civil/callback/CaseEvent.java index fc50b0b8ebc..fda21730b51 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/callback/CaseEvent.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/callback/CaseEvent.java @@ -642,7 +642,8 @@ public enum CaseEvent { UPLOAD_TRANSLATED_DOCUMENT_HEARING_SCHEDULED(CAMUNDA), ADD_APPLICATION_TO_TRANSLATION_COLLECTION(CAMUNDA), UPLOAD_TRANSLATED_DOCUMENT_FOR_FREE_FEE_APPLICATION(CAMUNDA), - UPLOAD_TRANSLATED_DOCUMENT_FINAL_ORDER(CAMUNDA); + UPLOAD_TRANSLATED_DOCUMENT_FINAL_ORDER(CAMUNDA), + UPDATE_COSC_VARIABLE(CAMUNDA); private final UserType userType; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/DashboardScenarios.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/DashboardScenarios.java index efc1c90f216..72563b59bcf 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/DashboardScenarios.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/DashboardScenarios.java @@ -258,6 +258,9 @@ public enum DashboardScenarios { SCENARIO_AAA6_CLAIMANT_CONFIRMATION_JUDGMENT_PAID_IN_FULL_DEFENDANT("Scenario.AAA6.ProofOfDebtPayment.Confirmation.Defendant"), SCENARIO_AAA6_DEFENDANT_NOTICE_OF_CHANGE_JBA_CLAIM_MOVES_OFFLINE_CLAIMANT("Scenario.AAA6.DefendantNoticeOfChange.JudgmentByAdmissionClaimMovesOffline.Claimant"), + SCENARIO_AAA6_MARK_PAID_IN_FULL_CLAIMANT("Scenario.AAA6.MarkPaidInFull.Confirmation.Claimant"), + SCENARIO_AAA6_MARK_PAID_IN_FULL_DEFENDANT("Scenario.AAA6.MarkPaidInFull.Confirmation.Defendant"), + //General Application SCENARIO_AAA6_GENERAL_APPLICATION_SUBMITTED_NONURGENT_RESPONDENT("Scenario.AAA6.GeneralApps.NonUrgentApplicationMade.Respondent"), SCENARIO_AAA6_GENERAL_APPLICATION_SUBMITTED_URGENT_RESPONDENT("Scenario.AAA6.GeneralApps.UrgentApplicationMade.Respondent"), diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/claimant/JudgmentPaidClaimantNotificationHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/claimant/JudgmentPaidClaimantNotificationHandler.java index 3baa3cdf649..9835e0e1844 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/claimant/JudgmentPaidClaimantNotificationHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/claimant/JudgmentPaidClaimantNotificationHandler.java @@ -14,6 +14,8 @@ import static uk.gov.hmcts.reform.civil.callback.CaseEvent.UPDATE_DASHBOARD_NOTIFICATIONS_JUDGMENT_PAID_CLAIMANT; import static uk.gov.hmcts.reform.civil.handler.callback.camunda.dashboardnotifications.DashboardScenarios.SCENARIO_AAA6_CLAIMANT_CONFIRMATION_JUDGMENT_PAID_IN_FULL_CLAIMANT; +import static uk.gov.hmcts.reform.civil.handler.callback.camunda.dashboardnotifications.DashboardScenarios.SCENARIO_AAA6_MARK_PAID_IN_FULL_CLAIMANT; +import static uk.gov.hmcts.reform.civil.utils.MarkPaidInFullUtil.checkMarkPaidInFull; @Service public class JudgmentPaidClaimantNotificationHandler extends DashboardCallbackHandler { @@ -39,6 +41,9 @@ public List handledEvents() { @Override public String getScenario(CaseData caseData) { + if (checkMarkPaidInFull(caseData)) { + return SCENARIO_AAA6_MARK_PAID_IN_FULL_CLAIMANT.getScenario(); + } return SCENARIO_AAA6_CLAIMANT_CONFIRMATION_JUDGMENT_PAID_IN_FULL_CLAIMANT.getScenario(); } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/defendant/JudgmentPaidDefendantNotificationHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/defendant/JudgmentPaidDefendantNotificationHandler.java index 8731bd85c47..280d7434a1c 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/defendant/JudgmentPaidDefendantNotificationHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/defendant/JudgmentPaidDefendantNotificationHandler.java @@ -14,6 +14,8 @@ import static uk.gov.hmcts.reform.civil.callback.CaseEvent.UPDATE_DASHBOARD_NOTIFICATIONS_JUDGMENT_PAID_DEFENDANT; import static uk.gov.hmcts.reform.civil.handler.callback.camunda.dashboardnotifications.DashboardScenarios.SCENARIO_AAA6_CLAIMANT_CONFIRMATION_JUDGMENT_PAID_IN_FULL_DEFENDANT; +import static uk.gov.hmcts.reform.civil.handler.callback.camunda.dashboardnotifications.DashboardScenarios.SCENARIO_AAA6_MARK_PAID_IN_FULL_DEFENDANT; +import static uk.gov.hmcts.reform.civil.utils.MarkPaidInFullUtil.checkMarkPaidInFull; @Service public class JudgmentPaidDefendantNotificationHandler extends DashboardCallbackHandler { @@ -39,6 +41,9 @@ public List handledEvents() { @Override public String getScenario(CaseData caseData) { + if (checkMarkPaidInFull(caseData)) { + return SCENARIO_AAA6_MARK_PAID_IN_FULL_DEFENDANT.getScenario(); + } return SCENARIO_AAA6_CLAIMANT_CONFIRMATION_JUDGMENT_PAID_IN_FULL_DEFENDANT.getScenario(); } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/tasks/CaseEventTaskHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/tasks/CaseEventTaskHandler.java index 7690880d75e..8553d6290c8 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/tasks/CaseEventTaskHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/tasks/CaseEventTaskHandler.java @@ -1,8 +1,5 @@ package uk.gov.hmcts.reform.civil.handler.tasks; -import java.util.Map; -import java.util.Objects; - import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; @@ -17,9 +14,9 @@ import uk.gov.hmcts.reform.civil.callback.CaseEvent; import uk.gov.hmcts.reform.civil.exceptions.InvalidCaseDataException; import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; -import uk.gov.hmcts.reform.civil.model.ExternalTaskData; import uk.gov.hmcts.reform.civil.model.BusinessProcess; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.ExternalTaskData; import uk.gov.hmcts.reform.civil.service.CoreCaseDataService; import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.service.data.ExternalTaskInput; @@ -27,6 +24,9 @@ import uk.gov.hmcts.reform.civil.service.flowstate.IStateFlowEngine; import uk.gov.hmcts.reform.civil.service.robotics.support.RoboticsEventTextFormatter; +import java.util.Map; +import java.util.Objects; + import static java.lang.String.format; import static java.util.Optional.ofNullable; import static uk.gov.hmcts.reform.civil.enums.CaseCategory.SPEC_CLAIM; @@ -40,6 +40,7 @@ import static uk.gov.hmcts.reform.civil.enums.UnrepresentedOrUnregisteredScenario.UNREPRESENTED; import static uk.gov.hmcts.reform.civil.enums.UnrepresentedOrUnregisteredScenario.getDefendantNames; import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; +import static uk.gov.hmcts.reform.civil.utils.MarkPaidInFullUtil.checkMarkPaidInFull; @RequiredArgsConstructor @Component @@ -91,6 +92,7 @@ public VariableMap getVariableMap(ExternalTaskData externalTaskData) { var stateFlow = stateFlowEngine.getStateFlow(data); variables.putValue(FLOW_STATE, stateFlow.getState().getName()); variables.putValue(FLOW_FLAGS, stateFlow.getFlags()); + variables.putValue("isJudgmentMarkedPaidInFull", checkMarkPaidInFull(data)); return variables; } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/helpers/judgmentsonline/JudgmentPaidInFullOnlineMapper.java b/src/main/java/uk/gov/hmcts/reform/civil/helpers/judgmentsonline/JudgmentPaidInFullOnlineMapper.java index 1c40d1eb273..5cd78848dd5 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/helpers/judgmentsonline/JudgmentPaidInFullOnlineMapper.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/helpers/judgmentsonline/JudgmentPaidInFullOnlineMapper.java @@ -48,11 +48,13 @@ public JudgmentDetails addUpdateActiveJudgment(CaseData caseData) { } protected JudgmentState getJudgmentState(CaseData caseData, LocalDate paymentDate) { - boolean paidAfter31Days = JudgmentsOnlineHelper.checkIfDateDifferenceIsGreaterThan31Days( - caseData.getActiveJudgment().getIssueDate(), + LocalDate issueDate = caseData.getActiveJudgment().getIssueDate(); + log.info("Getting Judgment State based on issueDate date: {}, eligible days: {}", issueDate, issueDate.lengthOfMonth()); + boolean paidAfterEligibleDays = JudgmentsOnlineHelper.checkIfDateDifferenceIsGreaterThanDaysInMonth( + issueDate, nonNull(paymentDate) ? paymentDate : caseData.getJoJudgmentPaidInFull().getDateOfFullPaymentMade() ); - return paidAfter31Days ? JudgmentState.SATISFIED : JudgmentState.CANCELLED; + return paidAfterEligibleDays ? JudgmentState.SATISFIED : JudgmentState.CANCELLED; } protected JudgmentState getJudgmentState(CaseData caseData) { diff --git a/src/main/java/uk/gov/hmcts/reform/civil/helpers/judgmentsonline/JudgmentsOnlineHelper.java b/src/main/java/uk/gov/hmcts/reform/civil/helpers/judgmentsonline/JudgmentsOnlineHelper.java index 3996a55da53..9e8408123c2 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/helpers/judgmentsonline/JudgmentsOnlineHelper.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/helpers/judgmentsonline/JudgmentsOnlineHelper.java @@ -29,7 +29,7 @@ public class JudgmentsOnlineHelper { private static final String ERROR_MESSAGE_DATE_FIRST_INSTALMENT_MUST_BE_IN_FUTURE = "Date of first instalment must be in the future"; private static final String ERROR_MESSAGE_DATE_ORDER_MUST_BE_IN_PAST = "Date judge made the order must be in the past"; - private static final String regex = "[ˆ`´¨]"; + private static final String REGEX = "[ˆ`´¨]"; private JudgmentsOnlineHelper() { } @@ -39,8 +39,8 @@ public static boolean validateIfFutureDate(LocalDate date) { return date.isAfter(today); } - public static boolean checkIfDateDifferenceIsGreaterThan31Days(LocalDate firstDate, LocalDate secondDate) { - return ChronoUnit.DAYS.between(firstDate, secondDate) > 31; + public static boolean checkIfDateDifferenceIsGreaterThanDaysInMonth(LocalDate firstDate, LocalDate secondDate) { + return ChronoUnit.DAYS.between(firstDate, secondDate) > firstDate.lengthOfMonth(); } public static List validateMidCallbackData(CaseData caseData) { @@ -295,7 +295,7 @@ public static JudgmentAddress getJudgmentAddress(Address address, RoboticsAddres } public static String removeWelshCharacters(String input) { - return input != null ? input.replaceAll(regex, "") : input; + return input != null ? input.replaceAll(REGEX, "") : input; } private static String trimDownTo35(String input) { diff --git a/src/main/java/uk/gov/hmcts/reform/civil/utils/MarkPaidInFullUtil.java b/src/main/java/uk/gov/hmcts/reform/civil/utils/MarkPaidInFullUtil.java new file mode 100644 index 00000000000..c0dff5d64ab --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/utils/MarkPaidInFullUtil.java @@ -0,0 +1,19 @@ +package uk.gov.hmcts.reform.civil.utils; + +import uk.gov.hmcts.reform.civil.model.CaseData; + +import java.util.Objects; + +public class MarkPaidInFullUtil { + + private MarkPaidInFullUtil() { + //no op + } + + public static boolean checkMarkPaidInFull(CaseData data) { + return (Objects.nonNull(data.getActiveJudgment()) + && data.getActiveJudgment().getFullyPaymentMadeDate() != null + && Objects.nonNull(data.getCertOfSC()) + && data.getCertOfSC().getDefendantFinalPaymentDate() != null); + } +} diff --git a/src/main/resources/db/migration/V2026_03_26_0921__create_new_clamant_and_defendant_mark_paid_in_full_notifications.sql b/src/main/resources/db/migration/V2026_03_26_0921__create_new_clamant_and_defendant_mark_paid_in_full_notifications.sql new file mode 100644 index 00000000000..ce9369c253a --- /dev/null +++ b/src/main/resources/db/migration/V2026_03_26_0921__create_new_clamant_and_defendant_mark_paid_in_full_notifications.sql @@ -0,0 +1,26 @@ +/** + * Add scenario to delete claimant notification + */ +INSERT INTO dbs.scenario (name, notifications_to_delete, notifications_to_create) +VALUES ('Scenario.AAA6.MarkPaidInFull.Confirmation.Claimant', + '{ + "Notice.AAA6.ProofofDebtPayment.Application.Claimant", + "Notice.AAA6.JudgmentsOnline.DefaultJudgmentIssued.Claimant", + "Notice.AAA6.JudgmentsOnline.IssuedCCJ.Claimant" + }', + '{"Notice.AAA6.JudgmentsOnline.PaidInFull.Claimant": []}'); + +/** + * Add scenario to delete defendant notification + */ + +INSERT INTO dbs.scenario (name, notifications_to_delete, notifications_to_create) +VALUES ('Scenario.AAA6.MarkPaidInFull.Confirmation.Defendant', + '{ + "Notice.AAA6.ProofofDebtPayment.Application.Defendant", + "Notice.AAA6.JudgmentsOnline.IssuedCCJ.Defendant", + "Notice.AAA6.JudgmentsOnline.DefaultJudgmentIssued.Defendant" + }', + '{"Notice.AAA6.ProofofDebtPayment.ApplicationProcessed.Defendant": []}'); + + diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/claimant/JudgmentPaidClaimantNotificationHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/claimant/JudgmentPaidClaimantNotificationHandlerTest.java index af9f5b13b74..b1d81f7a8a9 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/claimant/JudgmentPaidClaimantNotificationHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/claimant/JudgmentPaidClaimantNotificationHandlerTest.java @@ -12,6 +12,8 @@ import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.citizenui.CaseDataLiP; +import uk.gov.hmcts.reform.civil.model.citizenui.CertOfSC; +import uk.gov.hmcts.reform.civil.model.judgmentonline.JudgmentDetails; import uk.gov.hmcts.reform.civil.sampledata.CallbackParamsBuilder; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.service.FeatureToggleService; @@ -31,6 +33,7 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.UPDATE_DASHBOARD_NOTIFICATIONS_JUDGMENT_PAID_CLAIMANT; import static uk.gov.hmcts.reform.civil.handler.callback.camunda.dashboardnotifications.DashboardScenarios.SCENARIO_AAA6_CLAIMANT_CONFIRMATION_JUDGMENT_PAID_IN_FULL_CLAIMANT; +import static uk.gov.hmcts.reform.civil.handler.callback.camunda.dashboardnotifications.DashboardScenarios.SCENARIO_AAA6_MARK_PAID_IN_FULL_CLAIMANT; @ExtendWith(MockitoExtension.class) public class JudgmentPaidClaimantNotificationHandlerTest extends BaseCallbackHandlerTest { @@ -114,5 +117,37 @@ void shouldRecordScenario_whenInvoked_whenClaimantRepresented() { new ScenarioRequestParams(scenarioParams) ); } + + @Test + void shouldRecordScenario_whenInvoked_whenClaimantRepresented_And_MarkedPaid_And_Def_Mark_Paid_In_Full() { + CaseDataLiP caseDataLiP = new CaseDataLiP(); + caseDataLiP.setApplicant1SettleClaim(YesOrNo.YES); + caseDataLiP.setApplicant1ClaimSettledDate(LocalDate.now()); + CaseData caseData = CaseDataBuilder.builder().atStateClaimSubmittedSmallClaim() + .caseDataLip(caseDataLiP) + .applicant1Represented(YesOrNo.NO).build(); + caseData.setCaseDocumentUploadDate(LocalDateTime.now()); + + CaseData.CaseDataBuilder caseData2 = caseData.toBuilder(); + caseData2.activeJudgment(new JudgmentDetails().setFullyPaymentMadeDate(LocalDate.now())); + caseData2.certOfSC(new CertOfSC().setDefendantFinalPaymentDate(LocalDate.now())); + + HashMap scenarioParams = new HashMap<>(); + when(mapper.mapCaseDataToParams(any())).thenReturn(scenarioParams); + + CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData2.build()).request( + CallbackRequest.builder().eventId(UPDATE_DASHBOARD_NOTIFICATIONS_JUDGMENT_PAID_CLAIMANT.name()).build() + ).build(); + + when(featureToggleService.isLipVLipEnabled()).thenReturn(true); + + handler.handle(params); + verify(dashboardScenariosService).recordScenarios( + "BEARER_TOKEN", + SCENARIO_AAA6_MARK_PAID_IN_FULL_CLAIMANT.getScenario(), + caseData.getCcdCaseReference().toString(), + new ScenarioRequestParams(scenarioParams) + ); + } } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/defendant/JudgmentPaidDefendantNotificationHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/defendant/JudgmentPaidDefendantNotificationHandlerTest.java index 19db27ca8b6..45c38b6bdb4 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/defendant/JudgmentPaidDefendantNotificationHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/defendant/JudgmentPaidDefendantNotificationHandlerTest.java @@ -12,6 +12,8 @@ import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.citizenui.CaseDataLiP; +import uk.gov.hmcts.reform.civil.model.citizenui.CertOfSC; +import uk.gov.hmcts.reform.civil.model.judgmentonline.JudgmentDetails; import uk.gov.hmcts.reform.civil.sampledata.CallbackParamsBuilder; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.service.FeatureToggleService; @@ -31,6 +33,7 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.UPDATE_DASHBOARD_NOTIFICATIONS_JUDGMENT_PAID_DEFENDANT; import static uk.gov.hmcts.reform.civil.handler.callback.camunda.dashboardnotifications.DashboardScenarios.SCENARIO_AAA6_CLAIMANT_CONFIRMATION_JUDGMENT_PAID_IN_FULL_DEFENDANT; +import static uk.gov.hmcts.reform.civil.handler.callback.camunda.dashboardnotifications.DashboardScenarios.SCENARIO_AAA6_MARK_PAID_IN_FULL_DEFENDANT; @ExtendWith(MockitoExtension.class) public class JudgmentPaidDefendantNotificationHandlerTest extends BaseCallbackHandlerTest { @@ -116,5 +119,38 @@ void shouldRecordScenario_whenInvoked_whenDefendantRepresented() { new ScenarioRequestParams(scenarioParams) ); } + + @Test + void shouldRecordScenario_whenInvoked_whenDefendantRepresented_And_MarkedPaid_And_Def_Mark_Paid_In_Full() { + CaseDataLiP caseDataLiP = new CaseDataLiP(); + caseDataLiP.setApplicant1SettleClaim(YesOrNo.YES); + caseDataLiP.setApplicant1ClaimSettledDate(LocalDate.now()); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimSubmittedSmallClaim() + .caseDataLip(caseDataLiP) + .respondent1Represented(YesOrNo.NO).build(); + caseData.setCaseDocumentUploadDate(LocalDateTime.now()); + + CaseData.CaseDataBuilder caseData2 = caseData.toBuilder(); + caseData2.activeJudgment(new JudgmentDetails().setFullyPaymentMadeDate(LocalDate.now())); + caseData2.certOfSC(new CertOfSC().setDefendantFinalPaymentDate(LocalDate.now())); + + HashMap scenarioParams = new HashMap<>(); + when(mapper.mapCaseDataToParams(any())).thenReturn(scenarioParams); + + CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData2.build()).request( + CallbackRequest.builder().eventId(UPDATE_DASHBOARD_NOTIFICATIONS_JUDGMENT_PAID_DEFENDANT.name()).build() + ).build(); + + when(featureToggleService.isLipVLipEnabled()).thenReturn(true); + + handler.handle(params); + verify(dashboardScenariosService).recordScenarios( + "BEARER_TOKEN", + SCENARIO_AAA6_MARK_PAID_IN_FULL_DEFENDANT.getScenario(), + caseData.getCcdCaseReference().toString(), + new ScenarioRequestParams(scenarioParams) + ); + } } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/tasks/CaseEventTaskHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/tasks/CaseEventTaskHandlerTest.java index c3179f11ff1..78a3f6b78df 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/tasks/CaseEventTaskHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/tasks/CaseEventTaskHandlerTest.java @@ -35,6 +35,8 @@ import uk.gov.hmcts.reform.civil.model.BusinessProcess; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.StateFlowDTO; +import uk.gov.hmcts.reform.civil.model.citizenui.CertOfSC; +import uk.gov.hmcts.reform.civil.model.judgmentonline.JudgmentDetails; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.sampledata.CaseDetailsBuilder; import uk.gov.hmcts.reform.civil.service.CoreCaseDataService; @@ -49,6 +51,7 @@ import java.time.LocalDateTime; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -106,6 +109,7 @@ class CaseEventTaskHandlerTest { ArgumentCaptor caseDataContentArgumentCaptor; @InjectMocks private CaseEventTaskHandler caseEventTaskHandler; + private static final String IS_JUDGMENT_MARKED_PAID_IN_FULL = "isJudgmentMarkedPaidInFull"; @Nested class NotifyRespondent { @@ -134,6 +138,7 @@ void shouldTriggerCCDEvent_whenHandlerIsExecuted() { VariableMap variables = Variables.createVariables(); variables.putValue(FLOW_STATE, "MAIN.DRAFT"); variables.putValue(FLOW_FLAGS, Map.of()); + variables.putValue(IS_JUDGMENT_MARKED_PAID_IN_FULL, checkMarkPaidInFull(caseData)); CaseDetails caseDetails = new CaseDetailsBuilder().data(caseData).build(); @@ -151,6 +156,80 @@ void shouldTriggerCCDEvent_whenHandlerIsExecuted() { verify(coreCaseDataService).submitUpdate(eq(CASE_ID), any(CaseDataContent.class)); verify(externalTaskService).complete(mockTask, variables); } + + @Test + void shouldTriggerCCDEvent_whenHandlerIsExecutedV1() { + CaseData caseData1 = new CaseDataBuilder().atStateClaimDraft() + .businessProcess(new BusinessProcess() + .setStatus(BusinessProcessStatus.READY) + .setProcessInstanceId("processInstanceId")) + .build(); + CaseData.CaseDataBuilder caseData2 = caseData1.toBuilder(); + caseData2.activeJudgment(new JudgmentDetails().setFullyPaymentMadeDate(LocalDate.now())); + caseData2.certOfSC(new CertOfSC().setDefendantFinalPaymentDate(LocalDate.now())); + CaseData caseData = caseData2.build(); + + VariableMap variables = Variables.createVariables(); + variables.putValue(FLOW_STATE, "MAIN.DRAFT"); + variables.putValue(FLOW_FLAGS, Map.of()); + variables.putValue(IS_JUDGMENT_MARKED_PAID_IN_FULL, checkMarkPaidInFull(caseData)); + + CaseDetails caseDetails = new CaseDetailsBuilder().data(caseData).build(); + + when(coreCaseDataService.startUpdate(CASE_ID, NOTIFY_EVENT)) + .thenReturn(StartEventResponse.builder().caseDetails(caseDetails).build()); + + when(coreCaseDataService.submitUpdate(eq(CASE_ID), any(CaseDataContent.class))).thenReturn(caseData); + + when(stateFlowEngine.getStateFlow(any(CaseData.class))) + .thenReturn(new StateFlowDTO().setState(State.from("MAIN.DRAFT")).setFlags(Map.of())); + + caseEventTaskHandler.execute(mockTask, externalTaskService); + + verify(coreCaseDataService).startUpdate(CASE_ID, NOTIFY_EVENT); + verify(coreCaseDataService).submitUpdate(eq(CASE_ID), any(CaseDataContent.class)); + verify(externalTaskService).complete(mockTask, variables); + } + + @Test + void shouldTriggerCCDEvent_whenHandlerIsExecutedV3() { + CaseData caseData1 = new CaseDataBuilder().atStateClaimDraft() + .businessProcess(new BusinessProcess() + .setStatus(BusinessProcessStatus.READY) + .setProcessInstanceId("processInstanceId")) + .build(); + CaseData.CaseDataBuilder caseData2 = caseData1.toBuilder(); + caseData2.activeJudgment(new JudgmentDetails().setFullyPaymentMadeDate(LocalDate.now())); + CaseData caseData = caseData2.build(); + + VariableMap variables = Variables.createVariables(); + variables.putValue(FLOW_STATE, "MAIN.DRAFT"); + variables.putValue(FLOW_FLAGS, Map.of()); + variables.putValue(IS_JUDGMENT_MARKED_PAID_IN_FULL, checkMarkPaidInFull(caseData)); + + CaseDetails caseDetails = new CaseDetailsBuilder().data(caseData).build(); + + when(coreCaseDataService.startUpdate(CASE_ID, NOTIFY_EVENT)) + .thenReturn(StartEventResponse.builder().caseDetails(caseDetails).build()); + + when(coreCaseDataService.submitUpdate(eq(CASE_ID), any(CaseDataContent.class))).thenReturn(caseData); + + when(stateFlowEngine.getStateFlow(any(CaseData.class))) + .thenReturn(new StateFlowDTO().setState(State.from("MAIN.DRAFT")).setFlags(Map.of())); + + caseEventTaskHandler.execute(mockTask, externalTaskService); + + verify(coreCaseDataService).startUpdate(CASE_ID, NOTIFY_EVENT); + verify(coreCaseDataService).submitUpdate(eq(CASE_ID), any(CaseDataContent.class)); + verify(externalTaskService).complete(mockTask, variables); + } + + private boolean checkMarkPaidInFull(CaseData data) { + return (Objects.nonNull(data.getActiveJudgment()) + && data.getActiveJudgment().getFullyPaymentMadeDate() != null + && Objects.nonNull(data.getCertOfSC()) + && data.getCertOfSC().getDefendantFinalPaymentDate() != null); + } } @Nested @@ -253,7 +332,10 @@ void shouldTriggerCCDEvent_whenClaimIsPendingUnRepresented(FlowState.Main state) FLOW_FLAGS, flags ); - + variables.putValue( + IS_JUDGMENT_MARKED_PAID_IN_FULL, + false + ); when(mockTask.getVariable(FLOW_STATE)).thenReturn(state.fullName()); when(mockTask.getTopicName()).thenReturn("test"); when(mockTask.getActivityId()).thenReturn("activityId"); @@ -276,7 +358,7 @@ void shouldTriggerCCDEvent_whenClaimIsPendingUnRepresented(FlowState.Main state) verify(coreCaseDataService).startUpdate(CASE_ID, PROCEEDS_IN_HERITAGE_SYSTEM); verify(coreCaseDataService).submitUpdate(eq(CASE_ID), any(CaseDataContent.class)); - verify(externalTaskService).complete(mockTask, Map.of( + verify(externalTaskService).complete(mockTask, Map.of(IS_JUDGMENT_MARKED_PAID_IN_FULL, false, FLOW_FLAGS, flags, FLOW_STATE, state.fullName() )); @@ -312,6 +394,10 @@ void shouldTriggerCCDEventWithDescription_whenClaimIsHandedOffline(ReasonForProc FLOW_FLAGS, getFlowFlags(TAKEN_OFFLINE_BY_STAFF) ); + variables.putValue( + IS_JUDGMENT_MARKED_PAID_IN_FULL, + false + ); when(mockTask.getVariable(FLOW_STATE)).thenReturn(TAKEN_OFFLINE_BY_STAFF.fullName()); when(mockTask.getTopicName()).thenReturn("test"); @@ -337,7 +423,7 @@ void shouldTriggerCCDEventWithDescription_whenClaimIsHandedOffline(ReasonForProc verify(coreCaseDataService).startUpdate(CASE_ID, PROCEEDS_IN_HERITAGE_SYSTEM); verify(coreCaseDataService).submitUpdate(eq(CASE_ID), any(CaseDataContent.class)); - verify(externalTaskService).complete(mockTask, Map.of( + verify(externalTaskService).complete(mockTask, Map.of(IS_JUDGMENT_MARKED_PAID_IN_FULL, false, FLOW_FLAGS, getFlowFlags(TAKEN_OFFLINE_BY_STAFF), FLOW_STATE, TAKEN_OFFLINE_BY_STAFF.fullName() )); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/helpers/judgmentsonline/JudgmentsOnlineHelperTest.java b/src/test/java/uk/gov/hmcts/reform/civil/helpers/judgmentsonline/JudgmentsOnlineHelperTest.java index 4dd67b26360..f57254145cc 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/helpers/judgmentsonline/JudgmentsOnlineHelperTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/helpers/judgmentsonline/JudgmentsOnlineHelperTest.java @@ -7,6 +7,9 @@ import uk.gov.hmcts.reform.civil.model.common.DynamicList; import uk.gov.hmcts.reform.civil.model.common.DynamicListElement; import uk.gov.hmcts.reform.civil.model.judgmentonline.JudgmentAddress; +import uk.gov.hmcts.reform.civil.model.judgmentonline.JudgmentDetails; +import uk.gov.hmcts.reform.civil.model.judgmentonline.JudgmentPaymentPlan; +import uk.gov.hmcts.reform.civil.model.judgmentonline.PaymentPlanSelection; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.sampledata.PartyBuilder; import uk.gov.hmcts.reform.civil.service.robotics.mapper.AddressLinesMapper; @@ -17,17 +20,14 @@ import static org.assertj.core.api.Assertions.assertThat; import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; -import uk.gov.hmcts.reform.civil.model.judgmentonline.PaymentPlanSelection; -import uk.gov.hmcts.reform.civil.model.judgmentonline.JudgmentDetails; -import uk.gov.hmcts.reform.civil.model.judgmentonline.JudgmentPaymentPlan; -import static uk.gov.hmcts.reform.civil.helpers.judgmentsonline.JudgmentsOnlineHelper.checkIfDateDifferenceIsGreaterThan31Days; -import static uk.gov.hmcts.reform.civil.helpers.judgmentsonline.JudgmentsOnlineHelper.getFixedCostsOfJudgmentForDJ; +import static uk.gov.hmcts.reform.civil.helpers.judgmentsonline.JudgmentsOnlineHelper.calculateRepaymentBreakdownSummary; +import static uk.gov.hmcts.reform.civil.helpers.judgmentsonline.JudgmentsOnlineHelper.calculateRepaymentBreakdownSummaryWithoutClaimInterest; +import static uk.gov.hmcts.reform.civil.helpers.judgmentsonline.JudgmentsOnlineHelper.checkIfDateDifferenceIsGreaterThanDaysInMonth; import static uk.gov.hmcts.reform.civil.helpers.judgmentsonline.JudgmentsOnlineHelper.getClaimFeeOfJudgmentForDJ; +import static uk.gov.hmcts.reform.civil.helpers.judgmentsonline.JudgmentsOnlineHelper.getFixedCostsOfJudgmentForDJ; import static uk.gov.hmcts.reform.civil.helpers.judgmentsonline.JudgmentsOnlineHelper.getMoneyValue; import static uk.gov.hmcts.reform.civil.helpers.judgmentsonline.JudgmentsOnlineHelper.getPartialPayment; import static uk.gov.hmcts.reform.civil.helpers.judgmentsonline.JudgmentsOnlineHelper.isNonDivergentForDJ; -import static uk.gov.hmcts.reform.civil.helpers.judgmentsonline.JudgmentsOnlineHelper.calculateRepaymentBreakdownSummary; -import static uk.gov.hmcts.reform.civil.helpers.judgmentsonline.JudgmentsOnlineHelper.calculateRepaymentBreakdownSummaryWithoutClaimInterest; public class JudgmentsOnlineHelperTest { @@ -48,8 +48,8 @@ void test_validateIfFutureDate() { @Test void shouldCheckIfDateDifferenceIsGreaterThan31Days() { - assertThat(checkIfDateDifferenceIsGreaterThan31Days(LocalDate.now(), LocalDate.now().plusDays(31))).isFalse(); - assertThat(checkIfDateDifferenceIsGreaterThan31Days(LocalDate.now(), LocalDate.now().plusDays(32))).isTrue(); + assertThat(checkIfDateDifferenceIsGreaterThanDaysInMonth(LocalDate.now(), LocalDate.now().plusDays(31))).isFalse(); + assertThat(checkIfDateDifferenceIsGreaterThanDaysInMonth(LocalDate.now(), LocalDate.now().plusDays(32))).isTrue(); } @Test diff --git a/src/test/java/uk/gov/hmcts/reform/civil/utils/MarkPaidInFullUtilTest.java b/src/test/java/uk/gov/hmcts/reform/civil/utils/MarkPaidInFullUtilTest.java new file mode 100644 index 00000000000..5b0d2c69f16 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/civil/utils/MarkPaidInFullUtilTest.java @@ -0,0 +1,62 @@ +package uk.gov.hmcts.reform.civil.utils; + +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.citizenui.CertOfSC; +import uk.gov.hmcts.reform.civil.model.judgmentonline.JudgmentDetails; + +import java.time.LocalDate; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class MarkPaidInFullUtilTest { + + @Test + void shouldReturnTrue_whenAllConditionsAreMet() { + CaseData caseData = CaseData.builder() + .activeJudgment(new JudgmentDetails().setFullyPaymentMadeDate(LocalDate.now())) + .certOfSC(new CertOfSC().setDefendantFinalPaymentDate(LocalDate.now())) + .build(); + + assertTrue(MarkPaidInFullUtil.checkMarkPaidInFull(caseData)); + } + + @Test + void shouldReturnFalse_whenActiveJudgmentIsNull() { + CaseData caseData = CaseData.builder() + .certOfSC(new CertOfSC().setDefendantFinalPaymentDate(LocalDate.now())) + .build(); + + assertFalse(MarkPaidInFullUtil.checkMarkPaidInFull(caseData)); + } + + @Test + void shouldReturnFalse_whenFullyPaymentMadeDateIsNull() { + CaseData caseData = CaseData.builder() + .activeJudgment(new JudgmentDetails()) + .certOfSC(new CertOfSC().setDefendantFinalPaymentDate(LocalDate.now())) + .build(); + + assertFalse(MarkPaidInFullUtil.checkMarkPaidInFull(caseData)); + } + + @Test + void shouldReturnFalse_whenCertOfSCIsNull() { + CaseData caseData = CaseData.builder() + .activeJudgment(new JudgmentDetails().setFullyPaymentMadeDate(LocalDate.now())) + .build(); + + assertFalse(MarkPaidInFullUtil.checkMarkPaidInFull(caseData)); + } + + @Test + void shouldReturnFalse_whenDefendantFinalPaymentDateIsNull() { + CaseData caseData = CaseData.builder() + .activeJudgment(new JudgmentDetails().setFullyPaymentMadeDate(LocalDate.now())) + .certOfSC(new CertOfSC()) + .build(); + + assertFalse(MarkPaidInFullUtil.checkMarkPaidInFull(caseData)); + } +}