diff --git a/definitions/benefit/sheets/CaseEvent/CaseEvent.json b/definitions/benefit/sheets/CaseEvent/CaseEvent.json index cba48f02a33..4dd4971ea98 100644 --- a/definitions/benefit/sheets/CaseEvent/CaseEvent.json +++ b/definitions/benefit/sheets/CaseEvent/CaseEvent.json @@ -720,6 +720,7 @@ "DisplayOrder": 550, "PreConditionState(s)": "hearing;incompleteApplication;incompleteApplicationInformationReqsted;interlocutoryReviewState;notListable;readyToList;responseReceived;validAppeal;withDwp;handlingError", "PostConditionState": "dormantAppealState", + "EventEnablingCondition": "appeal.benefitType.code!=\"infectedBloodCompensation\"", "CallBackURLAboutToSubmitEvent": "${CCD_DEF_TRIBUNALS_API_URL}/ccdAboutToSubmit", "CallBackURLSubmittedEvent": "${CCD_DEF_TRIBUNALS_API_URL}/send", "ShowEventNotes": "Y", @@ -1435,6 +1436,7 @@ "DisplayOrder": 1010, "PreConditionState(s)": "hearing;incompleteApplication;incompleteApplicationInformationReqsted;interlocutoryReviewState;notListable;readyToList;responseReceived;validAppeal;withDwp;handlingError", "PostConditionState": "*", + "CallBackURLMidEvent": "${CCD_DEF_TRIBUNALS_API_URL}/ccdMidEvent", "CallBackURLAboutToSubmitEvent": "${CCD_DEF_TRIBUNALS_API_URL}/ccdAboutToSubmit", "SecurityClassification": "Public", "ShowSummary": "Y", diff --git a/definitions/benefit/sheets/CaseEventToFields/CaseEventToFields.json b/definitions/benefit/sheets/CaseEventToFields/CaseEventToFields.json index 983447409c9..c304668785b 100644 --- a/definitions/benefit/sheets/CaseEventToFields/CaseEventToFields.json +++ b/definitions/benefit/sheets/CaseEventToFields/CaseEventToFields.json @@ -647,10 +647,11 @@ "ShowSummaryChangeOption": "Y" }, { + "CallBackURLMidEvent": "${CCD_DEF_TRIBUNALS_API_URL}/ccdMidEvent", "CaseEventID": "dwpLapseCase", "CaseFieldID": "dwpLT203", "CaseTypeID": "Benefit", - "DisplayContext": "MANDATORY", + "DisplayContext": "OPTIONAL", "LiveFrom": "01/01/2018", "PageDisplayOrder": 1, "PageFieldDisplayOrder": 1, diff --git a/src/main/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/dwplapse/DwpLapseCaseHandler.java b/src/main/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/dwplapse/DwpLapseCaseHandler.java index cac31c0f54b..26b038ca006 100644 --- a/src/main/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/dwplapse/DwpLapseCaseHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/dwplapse/DwpLapseCaseHandler.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; import static uk.gov.hmcts.reform.sscs.ccd.domain.InterlocReviewState.AWAITING_ADMIN_ACTION; +import static uk.gov.hmcts.reform.sscs.ccd.domain.InterlocReviewState.REVIEW_BY_JUDGE; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -12,6 +13,7 @@ import uk.gov.hmcts.reform.sscs.ccd.callback.PreSubmitCallbackResponse; import uk.gov.hmcts.reform.sscs.ccd.domain.DwpState; import uk.gov.hmcts.reform.sscs.ccd.domain.EventType; +import uk.gov.hmcts.reform.sscs.ccd.domain.InterlocReviewState; import uk.gov.hmcts.reform.sscs.ccd.domain.SscsCaseData; import uk.gov.hmcts.reform.sscs.ccd.presubmit.PreSubmitCallbackHandler; import uk.gov.hmcts.reform.sscs.service.DwpDocumentService; @@ -40,10 +42,10 @@ public boolean canHandle(CallbackType callbackType, Callback callb @Override public PreSubmitCallbackResponse handle(CallbackType callbackType, Callback callback, String userAuthorisation) { SscsCaseData caseData = callback.getCaseDetails().getCaseData(); + InterlocReviewState interlocReviewState = caseData.isIbcCase() ? REVIEW_BY_JUDGE : AWAITING_ADMIN_ACTION; + log.info("Setting interloc review field to " + interlocReviewState + " for case id " + caseData.getCcdCaseId()); - log.info("Setting interloc review field to " + AWAITING_ADMIN_ACTION + " for case id " + caseData.getCcdCaseId()); - - caseData.setInterlocReviewState(AWAITING_ADMIN_ACTION); + caseData.setInterlocReviewState(interlocReviewState); caseData.setDwpState(DwpState.LAPSED); if (caseData.getDwpLapseLetter() != null) { diff --git a/src/main/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/dwplapse/DwpLapseCaseMidEventHandler.java b/src/main/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/dwplapse/DwpLapseCaseMidEventHandler.java new file mode 100644 index 00000000000..921cfeb2e91 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/dwplapse/DwpLapseCaseMidEventHandler.java @@ -0,0 +1,45 @@ +package uk.gov.hmcts.reform.sscs.ccd.presubmit.dwplapse; + +import static java.util.Objects.requireNonNull; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.reform.sscs.ccd.callback.Callback; +import uk.gov.hmcts.reform.sscs.ccd.callback.CallbackType; +import uk.gov.hmcts.reform.sscs.ccd.callback.PreSubmitCallbackResponse; +import uk.gov.hmcts.reform.sscs.ccd.domain.EventType; +import uk.gov.hmcts.reform.sscs.ccd.domain.InterlocReviewState; +import uk.gov.hmcts.reform.sscs.ccd.domain.SscsCaseData; +import uk.gov.hmcts.reform.sscs.ccd.presubmit.PreSubmitCallbackHandler; + +@Service +@Slf4j +public class DwpLapseCaseMidEventHandler implements PreSubmitCallbackHandler { + + @Override + public boolean canHandle(CallbackType callbackType, Callback callback) { + requireNonNull(callback, "callback must not be null"); + requireNonNull(callbackType, "callbacktype must not be null"); + + return callbackType.equals(CallbackType.MID_EVENT) + && callback.getEvent() == EventType.DWP_LAPSE_CASE; + } + + @Override + public PreSubmitCallbackResponse handle(CallbackType callbackType, Callback callback, + String userAuthorisation) { + if (!canHandle(callbackType, callback)) { + throw new IllegalStateException("Cannot handle callback"); + } + SscsCaseData caseData = callback.getCaseDetails().getCaseData(); + + PreSubmitCallbackResponse sscsCaseDataPreSubmitCallbackResponse = new PreSubmitCallbackResponse<>(caseData); + if (caseData.isIbcCase() && caseData.getInterlocReviewState() != InterlocReviewState.REVIEW_BY_JUDGE) { + sscsCaseDataPreSubmitCallbackResponse.addError("Interlocutory review state must be set to 'Review by Judge'"); + } else if (!caseData.isIbcCase() && caseData.getDwpLT203() == null) { + sscsCaseDataPreSubmitCallbackResponse.addError("Select or fill the required Select document for upload field"); + } + + return sscsCaseDataPreSubmitCallbackResponse; + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/dwplapse/DwpLapseCaseHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/dwplapse/DwpLapseCaseHandlerTest.java index 941f9cde23b..ce6cbf33f7a 100644 --- a/src/test/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/dwplapse/DwpLapseCaseHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/dwplapse/DwpLapseCaseHandlerTest.java @@ -11,6 +11,7 @@ import static uk.gov.hmcts.reform.sscs.ccd.callback.CallbackType.ABOUT_TO_SUBMIT; import static uk.gov.hmcts.reform.sscs.ccd.domain.DwpState.LAPSED; import static uk.gov.hmcts.reform.sscs.ccd.domain.InterlocReviewState.AWAITING_ADMIN_ACTION; +import static uk.gov.hmcts.reform.sscs.ccd.domain.InterlocReviewState.REVIEW_BY_JUDGE; import java.time.LocalDate; import java.util.ArrayList; @@ -75,6 +76,43 @@ public void givenAHandleDwpLapseEvent_thenReturnTrue() { assertTrue(handler.canHandle(ABOUT_TO_SUBMIT, callback)); } + @Test + public void givenIbcLapseCaseEvent_thenSetInterlocReviewByJudge() { + sscsCaseData = sscsCaseData.toBuilder().state(State.WITH_DWP) + .benefitCode("093") + .dwpLT203(DwpResponseDocument.builder().documentLink(DocumentLink.builder().documentUrl("lt203Link").build()).build()) + .dwpLapseLetter(DwpResponseDocument.builder().documentLink(DocumentLink.builder().documentUrl("lapseLink").build()).build()).build(); + + when(caseDetails.getCaseData()).thenReturn(sscsCaseData); + PreSubmitCallbackResponse response = handler.handle(ABOUT_TO_SUBMIT, callback, USER_AUTHORISATION); + + assertNull(response.getData().getDwpLT203()); + assertNull(response.getData().getDwpLapseLetter()); + + assertEquals(2, response.getData().getDwpDocuments().size()); + + assertThat(response.getData().getDwpDocuments(), hasItem( + hasProperty("value", allOf( + hasProperty("documentLink", allOf( + hasProperty("documentUrl", is("lt203Link")) + )), + hasProperty("documentType", is(DwpDocumentType.DWP_LT_203.getValue())) + )) + )); + + assertThat(response.getData().getDwpDocuments(), hasItem( + hasProperty("value", allOf( + hasProperty("documentLink", allOf( + hasProperty("documentUrl", is("lapseLink")) + )), + hasProperty("documentType", is(DwpDocumentType.DWP_LAPSE_LETTER.getValue())) + )) + )); + + assertEquals(REVIEW_BY_JUDGE, response.getData().getInterlocReviewState()); + assertEquals(LAPSED, response.getData().getDwpState()); + } + @Test public void givenDwpLapseCaseEventWithEmptyDwpDocuments_thenSetInterlocReviewToAdminAndMoveLt203DocToDwpDocuments() { sscsCaseData = sscsCaseData.toBuilder().state(State.WITH_DWP) diff --git a/src/test/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/dwplapse/DwpLapseCaseMidEventHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/dwplapse/DwpLapseCaseMidEventHandlerTest.java new file mode 100644 index 00000000000..8b0b3bb55b7 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/dwplapse/DwpLapseCaseMidEventHandlerTest.java @@ -0,0 +1,136 @@ +package uk.gov.hmcts.reform.sscs.ccd.presubmit.dwplapse; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.openMocks; +import static uk.gov.hmcts.reform.sscs.ccd.callback.CallbackType.ABOUT_TO_SUBMIT; +import static uk.gov.hmcts.reform.sscs.ccd.callback.CallbackType.MID_EVENT; + +import junitparams.JUnitParamsRunner; +import junitparams.Parameters; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import uk.gov.hmcts.reform.sscs.ccd.callback.Callback; +import uk.gov.hmcts.reform.sscs.ccd.callback.PreSubmitCallbackResponse; +import uk.gov.hmcts.reform.sscs.ccd.domain.Appeal; +import uk.gov.hmcts.reform.sscs.ccd.domain.CaseDetails; +import uk.gov.hmcts.reform.sscs.ccd.domain.DocumentLink; +import uk.gov.hmcts.reform.sscs.ccd.domain.DwpResponseDocument; +import uk.gov.hmcts.reform.sscs.ccd.domain.EventType; +import uk.gov.hmcts.reform.sscs.ccd.domain.InterlocReviewState; +import uk.gov.hmcts.reform.sscs.ccd.domain.SscsCaseData; +import uk.gov.hmcts.reform.sscs.ccd.domain.State; + +@RunWith(JUnitParamsRunner.class) +public class DwpLapseCaseMidEventHandlerTest { + + private static final String USER_AUTHORISATION = "Bearer token"; + private DwpLapseCaseMidEventHandler handler; + private SscsCaseData sscsCaseData; + + @Mock + private Callback callback; + + @Mock + private CaseDetails caseDetails; + + @Before + public void setUp() { + openMocks(this); + handler = new DwpLapseCaseMidEventHandler(); + + when(callback.getEvent()).thenReturn(EventType.DWP_LAPSE_CASE); + + sscsCaseData = SscsCaseData.builder() + .ccdCaseId("1234") + .createdInGapsFrom(State.READY_TO_LIST.getId()) + .appeal(Appeal.builder().build()) + .build(); + + when(callback.getCaseDetails()).thenReturn(caseDetails); + when(caseDetails.getCaseData()).thenReturn(sscsCaseData); + } + + @Test + @Parameters({"APPEAL_RECEIVED", "ACTION_FURTHER_EVIDENCE"}) + public void givenANonHandleDwpLapseEvent_thenReturnFalse(EventType eventType) { + when(callback.getEvent()).thenReturn(eventType); + assertFalse(handler.canHandle(MID_EVENT, callback)); + } + + @Test + public void givenAHandleDwpLapseAboutToSubmitEvent_thenReturnFalse() { + when(callback.getEvent()).thenReturn(EventType.DWP_LAPSE_CASE); + assertFalse(handler.canHandle(ABOUT_TO_SUBMIT, callback)); + } + + @Test + public void givenAHandleDwpLapseEvent_thenReturnTrue() { + when(callback.getEvent()).thenReturn(EventType.DWP_LAPSE_CASE); + assertTrue(handler.canHandle(MID_EVENT, callback)); + } + + @Test + public void givenNullCallback_thenThrowError() { + when(callback.getEvent()).thenReturn(EventType.DWP_LAPSE_CASE); + assertThrows(NullPointerException.class, () -> handler.canHandle(ABOUT_TO_SUBMIT, null)); + assertThrows(NullPointerException.class, () -> handler.canHandle(null, callback)); + } + + @Test + @Parameters({"APPEAL_RECEIVED", "ACTION_FURTHER_EVIDENCE"}) + public void givenANonHandleDwpLapseEvent_thenThrowError(EventType eventType) { + when(callback.getEvent()).thenReturn(eventType); + assertThrows(IllegalStateException.class, () -> handler.handle(MID_EVENT, callback, USER_AUTHORISATION)); + } + + @Test + public void givenAHandleDwpLapseEvent_thenThrowError() { + when(callback.getEvent()).thenReturn(EventType.DWP_LAPSE_CASE); + assertThrows(IllegalStateException.class, () -> handler.handle(ABOUT_TO_SUBMIT, callback, USER_AUTHORISATION)); + } + + @Test + public void passIbaCaseIfInterlocReviewByJudge() { + when(callback.getEvent()).thenReturn(EventType.DWP_LAPSE_CASE); + sscsCaseData.setBenefitCode("093"); + sscsCaseData.setInterlocReviewState(InterlocReviewState.REVIEW_BY_JUDGE); + PreSubmitCallbackResponse response = handler.handle(MID_EVENT, callback, USER_AUTHORISATION); + assertTrue(response.getErrors().isEmpty()); + } + + @Test + @Parameters({"AWAITING_ADMIN_ACTION", "AWAITING_INFORMATION", "NONE", "REVIEW_BY_TCW", "WELSH_TRANSLATION"}) + public void failIbaCaseIfNotInterlocReviewByJudge(InterlocReviewState interlocReviewState) { + when(callback.getEvent()).thenReturn(EventType.DWP_LAPSE_CASE); + sscsCaseData.setBenefitCode("093"); + sscsCaseData.setInterlocReviewState(interlocReviewState); + PreSubmitCallbackResponse response = handler.handle(MID_EVENT, callback, USER_AUTHORISATION); + assertEquals(1, response.getErrors().size()); + assertTrue(response.getErrors().contains("Interlocutory review state must be set to 'Review by Judge'")); + } + + @Test + public void passNonIbaCaseIfNonNullLt203() { + when(callback.getEvent()).thenReturn(EventType.DWP_LAPSE_CASE); + sscsCaseData.setBenefitCode("001"); + sscsCaseData.setDwpLT203(DwpResponseDocument.builder().documentLink(DocumentLink.builder().documentUrl("lt203Link").build()).build()); + PreSubmitCallbackResponse response = handler.handle(MID_EVENT, callback, USER_AUTHORISATION); + assertTrue(response.getErrors().isEmpty()); + } + + @Test + public void failNonIbaCaseIfNullLt203() { + when(callback.getEvent()).thenReturn(EventType.DWP_LAPSE_CASE); + sscsCaseData.setBenefitCode("001"); + sscsCaseData.setDwpLT203(null); + PreSubmitCallbackResponse response = handler.handle(MID_EVENT, callback, USER_AUTHORISATION); + assertEquals(1, response.getErrors().size()); + assertTrue(response.getErrors().contains("Select or fill the required Select document for upload field")); + } +}