Skip to content

Commit

Permalink
SSCSCI-1409 make lapse appeal mid event for validations (#4160)
Browse files Browse the repository at this point in the history
* make lapse appeal mid event for validations

* checkstyle fixes

* setting interloc state to review by judge for ibc lapse

* checkstyle fix

* adding mid event url to lapse appeal

* changing nested if

* mid event fix
  • Loading branch information
nilay913 authored Dec 9, 2024
1 parent a75f55d commit 5223ad7
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 4 deletions.
2 changes: 2 additions & 0 deletions definitions/benefit/sheets/CaseEvent/CaseEvent.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -40,10 +42,10 @@ public boolean canHandle(CallbackType callbackType, Callback<SscsCaseData> callb
@Override
public PreSubmitCallbackResponse<SscsCaseData> handle(CallbackType callbackType, Callback<SscsCaseData> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<SscsCaseData> {

@Override
public boolean canHandle(CallbackType callbackType, Callback<SscsCaseData> 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<SscsCaseData> handle(CallbackType callbackType, Callback<SscsCaseData> callback,
String userAuthorisation) {
if (!canHandle(callbackType, callback)) {
throw new IllegalStateException("Cannot handle callback");
}
SscsCaseData caseData = callback.getCaseDetails().getCaseData();

PreSubmitCallbackResponse<SscsCaseData> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<SscsCaseData> 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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<SscsCaseData> callback;

@Mock
private CaseDetails<SscsCaseData> 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<SscsCaseData> 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<SscsCaseData> 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<SscsCaseData> 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<SscsCaseData> 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"));
}
}

0 comments on commit 5223ad7

Please sign in to comment.