Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSCSCI-1616 #4349

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"DisplayOrder": 361,
"PreConditionState(s)": "*",
"CallBackURLAboutToStartEvent": "${CCD_DEF_TRIBUNALS_API_URL}/ccdAboutToStart",
"CallBackURLMidEvent": "${CCD_DEF_TRIBUNALS_API_URL}/ccdMidEvent",
"CallBackURLAboutToSubmitEvent": "${CCD_DEF_TRIBUNALS_API_URL}/ccdAboutToSubmit",
"PostConditionState": "*",
"SecurityClassification": "Public"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"CaseFieldID": "hearingOutcomes",
"CaseTypeID": "Benefit",
"DisplayContext": "COMPLEX",
"CallBackURLMidEvent": "${CCD_DEF_TRIBUNALS_API_URL}/ccdMidEvent",
"PageDisplayOrder": 1,
"PageFieldDisplayOrder": 1,
"PageID": "1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ public PreSubmitCallbackResponse<SscsCaseData> handle(CallbackType callbackType,
}

SscsCaseData sscsCaseData = callback.getCaseDetails().getCaseData();
PreSubmitCallbackResponse<SscsCaseData> preSubmitCallbackResponse = new PreSubmitCallbackResponse<>(sscsCaseData);

if (sscsCaseData.getHearingOutcomes().isEmpty()) {
sscsCaseData.setHearingOutcomes(null);
}

return new PreSubmitCallbackResponse<>(sscsCaseData);
return preSubmitCallbackResponse;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package uk.gov.hmcts.reform.sscs.ccd.presubmit.amendhearingoutcome;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
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.SscsCaseData;
import uk.gov.hmcts.reform.sscs.ccd.presubmit.PreSubmitCallbackHandler;

@Slf4j
@Component
public class AmendHearingOutcomeMidEventHandler implements PreSubmitCallbackHandler<SscsCaseData> {
@Override
public boolean canHandle(CallbackType callbackType, Callback<SscsCaseData> callback) {
return callbackType.equals(CallbackType.MID_EVENT)
&& callback.getEvent().equals(EventType.AMEND_HEARING_OUTCOME);

}

@Override
public PreSubmitCallbackResponse<SscsCaseData> handle(CallbackType callbackType, Callback<SscsCaseData> callback, String userAuthorisation) {
if (!canHandle(callbackType, callback)) {
throw new IllegalStateException("Cannot handle callback");
}
SscsCaseData sscsCaseData = callback.getCaseDetails().getCaseData();
PreSubmitCallbackResponse<SscsCaseData> preSubmitCallbackResponse = new PreSubmitCallbackResponse<>(sscsCaseData);
boolean hasNewOutcomeBeenAdded = sscsCaseData.getHearingOutcomes().stream()
.anyMatch(hearingOutcome -> hearingOutcome.getValue().getCompletedHearingId() == null);
if (hasNewOutcomeBeenAdded) {
preSubmitCallbackResponse.addError("You cannot create a new hearing outcome in Amend Hearing Outcome, select ‘Add New hearing outcome’ event to add another outcome.");
}

return preSubmitCallbackResponse;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package uk.gov.hmcts.reform.sscs.ccd.presubmit.amendhearingoutcome;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.openMocks;

import java.time.LocalDateTime;
import java.util.List;
import junitparams.JUnitParamsRunner;
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.CallbackType;
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.EventType;
import uk.gov.hmcts.reform.sscs.ccd.domain.HearingOutcome;
import uk.gov.hmcts.reform.sscs.ccd.domain.HearingOutcomeDetails;
import uk.gov.hmcts.reform.sscs.ccd.domain.SscsCaseData;
import uk.gov.hmcts.reform.sscs.reference.data.model.HearingChannel;


@RunWith(JUnitParamsRunner.class)
public class AmendHearingOutcomeMidEventHandlerTest {

private AmendHearingOutcomeMidEventHandler handler;

@Mock
private Callback<SscsCaseData> callback;

@Mock
private CaseDetails<SscsCaseData> caseDetails;

private SscsCaseData sscsCaseData;

@Before
public void setUp() {
openMocks(this);
handler = new AmendHearingOutcomeMidEventHandler();

when(callback.getEvent()).thenReturn(EventType.AMEND_HEARING_OUTCOME);
when(callback.getCaseDetails()).thenReturn(caseDetails);
sscsCaseData = SscsCaseData.builder().ccdCaseId("ccdDd").appeal(Appeal.builder().build()).build();
when(caseDetails.getCaseData()).thenReturn(sscsCaseData);
}

@Test
public void givenAValidAboutToSubmitEvent_thenReturnTrue() {
assertThat(handler.canHandle(CallbackType.MID_EVENT, callback)).isTrue();
}

@Test
public void givenAnInvalidAboutToSubmitEvent_thenReturnTrue() {
when(callback.getEvent()).thenReturn(EventType.APPEAL_RECEIVED);
assertThat(handler.canHandle(CallbackType.MID_EVENT, callback)).isFalse();
}

@Test
public void givenAHearingWasAdded_ThenReturnError() {
sscsCaseData.setHearingOutcomes(List.of(
HearingOutcome.builder().value(HearingOutcomeDetails.builder().completedHearingId(null).build()).build(),
HearingOutcome.builder().value(
HearingOutcomeDetails.builder()
.hearingOutcomeId("17")
.hearingChannelId(HearingChannel.FACE_TO_FACE)
.hearingStartDateTime(LocalDateTime.now().minusHours(1))
.hearingEndDateTime(LocalDateTime.now())
.completedHearingId("123").build()).build()
));
var response = handler.handle(CallbackType.MID_EVENT, callback, "userAuthorisation");
assertThat(response.getErrors()).contains("You cannot create a new hearing outcome in Amend Hearing Outcome, select ‘Add New hearing outcome’ event to add another outcome.");
}

@Test
public void givenNoHearingAdded_ThenReturnResponse() {
sscsCaseData.setHearingOutcomes(List.of(
HearingOutcome.builder().value(
HearingOutcomeDetails.builder()
.hearingOutcomeId("17")
.hearingChannelId(HearingChannel.FACE_TO_FACE)
.hearingStartDateTime(LocalDateTime.now().minusHours(1))
.hearingEndDateTime(LocalDateTime.now())
.completedHearingId("123").build()).build()
));
var response = handler.handle(CallbackType.MID_EVENT, callback, "userAuthorisation");
assertThat(response.getErrors()).isEmpty();
}

}
Loading