Skip to content

Commit

Permalink
SSCSCI-1549: filter out cancelled hearings (#4293)
Browse files Browse the repository at this point in the history
  • Loading branch information
benouaer authored Jan 21, 2025
1 parent acedb99 commit 8e30e09
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@ public void hitCallback() throws JsonProcessingException {
assertThat(result.getPostponement().getUnprocessedPostponement()).isEqualTo(NO);
assertThat(result.getPostponement().getPostponementEvent()).isEqualTo(READY_TO_LIST);
assertThat(result.getDwpState()).isEqualTo(DwpState.HEARING_POSTPONED);
assertThat(result.getIgnoreCallbackWarnings()).isEqualTo(YES);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static uk.gov.hmcts.reform.sscs.ccd.domain.EventType.NOT_LISTABLE;
import static uk.gov.hmcts.reform.sscs.ccd.domain.EventType.READY_TO_LIST;
import static uk.gov.hmcts.reform.sscs.ccd.domain.YesNo.NO;
import static uk.gov.hmcts.reform.sscs.ccd.domain.YesNo.YES;
import static uk.gov.hmcts.reform.sscs.ccd.domain.YesNo.isNoOrNull;

import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -99,6 +100,7 @@ public PreSubmitCallbackResponse<SscsCaseData> handle(CallbackType callbackType,
sscsCaseDetails -> {
SscsCaseData sscsCaseData = sscsCaseDetails.getData();
sscsCaseData.setDwpState(DwpState.HEARING_POSTPONED);
sscsCaseData.setIgnoreCallbackWarnings(YES);
sscsCaseData.setPostponement(Postponement.builder()
.unprocessedPostponement(NO)
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
@Slf4j
public class ReadyToListAboutToSubmitHandler implements PreSubmitCallbackHandler<SscsCaseData> {

static final String EXISTING_HEARING_WARNING = "There is already a hearing request in List assist, "
+ "are you sure you want to send another request? If you do proceed, then please cancel the existing hearing request first";
static final String GAPS_CASE_WARNING = "This is a GAPS case, If you do want to proceed, "
+ "then please change the hearing route to List Assist";
private final boolean gapsSwitchOverFeature;

private final RegionalProcessingCenterService regionalProcessingCenterService;
Expand Down Expand Up @@ -56,10 +60,8 @@ public PreSubmitCallbackResponse<SscsCaseData> handle(CallbackType callbackType,

if (!callback.isIgnoreWarnings() && !YesNo.YES.equals(sscsCaseData.getIgnoreCallbackWarnings())) {
PreSubmitCallbackResponse<SscsCaseData> response = new PreSubmitCallbackResponse<>(callback.getCaseDetails().getCaseData());
String gapsProceedWarning = "This is a GAPS case, If you do want to proceed, "
+ "then please change the hearing route to List Assist";
response.addWarning(gapsProceedWarning);
log.warn("Warning: {}", gapsProceedWarning);
response.addWarning(GAPS_CASE_WARNING);
log.warn("Warning: {}", GAPS_CASE_WARNING);
return response;
}

Expand All @@ -68,12 +70,10 @@ public PreSubmitCallbackResponse<SscsCaseData> handle(CallbackType callbackType,
}

if (SscsHelper.hasHearingScheduledInTheFuture(sscsCaseData)
&& !callback.isIgnoreWarnings()) {
&& !callback.isIgnoreWarnings() && !YesNo.YES.equals(sscsCaseData.getIgnoreCallbackWarnings())) {
PreSubmitCallbackResponse<SscsCaseData> response = new PreSubmitCallbackResponse<>(callback.getCaseDetails().getCaseData());
String listAssistExistsWarning = "There is already a hearing request in List assist, "
+ "are you sure you want to send another request? If you do proceed, then please cancel the existing hearing request first";
response.addWarning(listAssistExistsWarning);
log.warn("Warning: {}", listAssistExistsWarning);
response.addWarning(EXISTING_HEARING_WARNING);
log.warn("Warning: {}", EXISTING_HEARING_WARNING);
return response;
}

Expand Down
10 changes: 7 additions & 3 deletions src/main/java/uk/gov/hmcts/reform/sscs/helper/SscsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.util.Arrays.asList;
import static java.util.Objects.isNull;
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static uk.gov.hmcts.reform.sscs.ccd.domain.HearingStatus.CANCELLED;
import static uk.gov.hmcts.reform.sscs.ccd.domain.State.INCOMPLETE_APPLICATION;
import static uk.gov.hmcts.reform.sscs.ccd.domain.State.INCOMPLETE_APPLICATION_INFORMATION_REQUESTED;
import static uk.gov.hmcts.reform.sscs.ccd.domain.State.INTERLOCUTORY_REVIEW_STATE;
Expand Down Expand Up @@ -104,7 +105,7 @@ private static boolean isValidHearing(HearingDetails hearingDetails) {
&& StringUtils.isNotBlank(hearingDetails.getVenue().getName());
}

private static boolean getValidHearing(Hearing hearing) {
private static boolean isFutureHearing(Hearing hearing) {
HearingDetails hearingDetails = hearing.getValue();
if (isValidHearing(hearingDetails)) {
LocalDateTime hearingDateTime = getLocalDateTime(hearingDetails.getHearingDate(), hearingDetails.getTime());
Expand All @@ -116,7 +117,10 @@ private static boolean getValidHearing(Hearing hearing) {
public static boolean hasHearingScheduledInTheFuture(SscsCaseData caseData) {
Optional<Hearing> futureHearing = Optional.ofNullable(caseData.getHearings())
.orElse(Collections.emptyList())
.stream().filter(SscsHelper::getValidHearing).findFirst();
.stream()
.filter(SscsHelper::isFutureHearing)
.filter(hearing -> !CANCELLED.equals(hearing.getValue().getHearingStatus()))
.findFirst();
return futureHearing.isPresent();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ public void canHandleInvalidEvents(EventType eventType) {
assertThat(handler.canHandle(SUBMITTED, callback)).isFalse();
}

@DisplayName("When given an valid event canHandle returns false")
@DisplayName("When given a valid event canHandle returns false")
@Test
public void canHandleScheduleListingDisabled() {
ReflectionTestUtils.setField(handler, "isScheduleListingEnabled", false);
assertThat(handler.canHandle(SUBMITTED, callback)).isFalse();
}

@DisplayName("When given Ready To List event is given and postponement hearing has not been already handled "
@DisplayName("When Ready To List event is chosen and postponement hearing has not been already handled "
+ "handle sets the fields correctly and sends the correct ccd update event")
@Test
public void handleReadyToListPostponementRelistEventType() {
Expand Down Expand Up @@ -162,9 +162,10 @@ public void handleReadyToListPostponementRelistEventType() {
assertThat(sscsCaseData.getPostponement().getPostponementEvent()).isNull();
assertThat(sscsCaseData.getPostponement().getUnprocessedPostponement()).isEqualTo(NO);
assertThat(sscsCaseData.getDwpState()).isEqualTo(DwpState.HEARING_POSTPONED);
assertThat(sscsCaseData.getIgnoreCallbackWarnings()).isEqualTo(YES);
}

@DisplayName("When given Not Listable event is given and postponement hearing has not been already handled "
@DisplayName("When Not Listable event is chosen and postponement hearing has not been already handled "
+ "handle sets the fields correctly and sends the correct ccd update event")
@Test
public void handleNotListablePostponementRelistEventType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
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.domain.YesNo.NO;
import static uk.gov.hmcts.reform.sscs.ccd.domain.YesNo.YES;
import static uk.gov.hmcts.reform.sscs.ccd.presubmit.readytolist.ReadyToListAboutToSubmitHandler.EXISTING_HEARING_WARNING;
import static uk.gov.hmcts.reform.sscs.ccd.presubmit.readytolist.ReadyToListAboutToSubmitHandler.GAPS_CASE_WARNING;

import java.time.LocalDate;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -234,7 +239,7 @@ public void givenAGapsCaseOnSubmitReturnWarning() {

MatcherAssert.assertThat(response.getErrors().size(), is(0));
MatcherAssert.assertThat(response.getWarnings().size(), is(1));
MatcherAssert.assertThat(response.getWarnings().iterator().next(), is("This is a GAPS case, If you do want to proceed, then please change the hearing route to List Assist"));
MatcherAssert.assertThat(response.getWarnings().iterator().next(), is(GAPS_CASE_WARNING));
}

@Test
Expand All @@ -246,7 +251,7 @@ public void givenAGapsCaseOnSubmitIgnoreWarningIIgnoreWarningsFieldIsYes() {
.schedulingAndListingFields(schedulingAndListingFields)
.region("TEST")
.build();
sscsCaseData.setIgnoreCallbackWarnings(YesNo.YES);
sscsCaseData.setIgnoreCallbackWarnings(YES);
when(caseDetails.getCaseData()).thenReturn(sscsCaseData);

handler = new ReadyToListAboutToSubmitHandler(false, regionalProcessingCenterService,
Expand All @@ -259,7 +264,8 @@ public void givenAGapsCaseOnSubmitIgnoreWarningIIgnoreWarningsFieldIsYes() {
}

@Test
public void givenAListAssistCaseIfAHearingExistsInTheFutureThenReturnWarning() {
@Parameters({"YES", "NO"})
public void givenAListAssistCaseIfAHearingExistsInTheFutureThenReturnWarning(YesNo ignoreCallbackWarnings) {
HearingDetails hearingDetails1 = HearingDetails.builder()
.hearingDate(LocalDate.now().minusDays(10).toString())
.start(LocalDateTime.now().minusDays(10))
Expand All @@ -281,14 +287,20 @@ public void givenAListAssistCaseIfAHearingExistsInTheFutureThenReturnWarning() {
sscsCaseData = sscsCaseData.toBuilder()
.hearings(List.of(hearing1, hearing2))
.region("TEST")
.ignoreCallbackWarnings(ignoreCallbackWarnings)
.build();
when(caseDetails.getCaseData()).thenReturn(sscsCaseData);
handler = new ReadyToListAboutToSubmitHandler(false, regionalProcessingCenterService, hearingMessagingServiceFactory);

PreSubmitCallbackResponse<SscsCaseData> response = handler.handle(ABOUT_TO_SUBMIT, callback, USER_AUTHORISATION);

MatcherAssert.assertThat(response.getErrors().size(), is(0));
MatcherAssert.assertThat(response.getWarnings().size(), is(1));
MatcherAssert.assertThat(response.getWarnings().iterator().next(), is("There is already a hearing request in List assist, are you sure you want to send another request? If you do proceed, then please cancel the existing hearing request first"));
if (ignoreCallbackWarnings == NO) {
MatcherAssert.assertThat(response.getWarnings().size(), is(1));
assertTrue(response.getWarnings().contains(EXISTING_HEARING_WARNING));
} else {
MatcherAssert.assertThat(response.getWarnings().size(), is(0));
}
}

@Test
Expand Down
52 changes: 45 additions & 7 deletions src/test/java/uk/gov/hmcts/reform/sscs/helper/SscsHelperTest.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
package uk.gov.hmcts.reform.sscs.helper;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static uk.gov.hmcts.reform.sscs.ccd.domain.YesNo.NO;
import static uk.gov.hmcts.reform.sscs.ccd.domain.YesNo.YES;
import static uk.gov.hmcts.reform.sscs.helper.SscsHelper.*;
import static uk.gov.hmcts.reform.sscs.helper.SscsHelper.getUpdatedDirectionDueDate;
import static uk.gov.hmcts.reform.sscs.helper.SscsHelper.hasHearingScheduledInTheFuture;
import static uk.gov.hmcts.reform.sscs.helper.SscsHelper.validateHearingOptionsAndExcludeDates;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import uk.gov.hmcts.reform.sscs.ccd.domain.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import uk.gov.hmcts.reform.sscs.ccd.domain.Appeal;
import uk.gov.hmcts.reform.sscs.ccd.domain.Benefit;
import uk.gov.hmcts.reform.sscs.ccd.domain.BenefitType;
import uk.gov.hmcts.reform.sscs.ccd.domain.CcdValue;
import uk.gov.hmcts.reform.sscs.ccd.domain.DateRange;
import uk.gov.hmcts.reform.sscs.ccd.domain.ExcludeDate;
import uk.gov.hmcts.reform.sscs.ccd.domain.Hearing;
import uk.gov.hmcts.reform.sscs.ccd.domain.HearingDetails;
import uk.gov.hmcts.reform.sscs.ccd.domain.HearingOptions;
import uk.gov.hmcts.reform.sscs.ccd.domain.HearingStatus;
import uk.gov.hmcts.reform.sscs.ccd.domain.OtherParty;
import uk.gov.hmcts.reform.sscs.ccd.domain.SscsCaseData;
import uk.gov.hmcts.reform.sscs.ccd.domain.Venue;

public class SscsHelperTest {

public static final LocalDate NOW = LocalDate.now();
private SscsCaseData sscsCaseData;

@Before
@BeforeEach
public void setUp() {
sscsCaseData = SscsCaseData.builder()
.ccdCaseId("ccdId")
Expand Down Expand Up @@ -120,6 +136,28 @@ public void givenThereAreSomeHearingsInTheFuture_WhenTheHearingDataIsInvalid_The
assertFalse(hasHearingScheduledInTheFuture(sscsCaseData));
}

@ParameterizedTest
@CsvSource({
"AWAITING_LISTING, true",
"CANCELLED, false"
})
public void givenANonCancelledHearingsInTheFuture_ThenReturnTrue(HearingStatus hearingStatus,
boolean expectedResult) {
HearingDetails hearingDetails = HearingDetails.builder()
.hearingDate(LocalDate.now().plusDays(5).toString())
.start(LocalDateTime.now().plusDays(5))
.hearingId(String.valueOf(1))
.time("12:00")
.venue(Venue.builder().name("Venue 1").build())
.hearingStatus(hearingStatus)
.build();
Hearing hearing = Hearing.builder().value(hearingDetails).build();

sscsCaseData.setHearings(List.of(hearing));

assertThat(hasHearingScheduledInTheFuture(sscsCaseData)).isEqualTo(expectedResult);
}

@Test
public void givenAnyCaseWhenExcludeDatesAreNotProvided_thenThrowError() {
CcdValue<OtherParty> otherParty = buildOtherParty();
Expand Down

0 comments on commit 8e30e09

Please sign in to comment.