From 8e30e09c5c372e6c3ab99fc5a8c23da70bc786d8 Mon Sep 17 00:00:00 2001 From: taleb <20416858+benouaer@users.noreply.github.com> Date: Tue, 21 Jan 2025 20:18:15 +0000 Subject: [PATCH] SSCSCI-1549: filter out cancelled hearings (#4293) --- .../postpone/PostponeHearingHandlerTest.java | 1 + .../postpone/PostponeHearingHandler.java | 2 + .../ReadyToListAboutToSubmitHandler.java | 18 +++---- .../hmcts/reform/sscs/helper/SscsHelper.java | 10 ++-- .../postpone/PostponeHearingHandlerTest.java | 7 +-- .../ReadyToListAboutToSubmitHandlerTest.java | 22 ++++++-- .../reform/sscs/helper/SscsHelperTest.java | 52 ++++++++++++++++--- 7 files changed, 85 insertions(+), 27 deletions(-) diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/sscs/functional/handlers/postpone/PostponeHearingHandlerTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/sscs/functional/handlers/postpone/PostponeHearingHandlerTest.java index a6bd240ff6f..72339c15e77 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/sscs/functional/handlers/postpone/PostponeHearingHandlerTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/sscs/functional/handlers/postpone/PostponeHearingHandlerTest.java @@ -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); } } diff --git a/src/main/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/postpone/PostponeHearingHandler.java b/src/main/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/postpone/PostponeHearingHandler.java index d99bfbfe0bf..6dff01f4e72 100644 --- a/src/main/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/postpone/PostponeHearingHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/postpone/PostponeHearingHandler.java @@ -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; @@ -99,6 +100,7 @@ public PreSubmitCallbackResponse handle(CallbackType callbackType, sscsCaseDetails -> { SscsCaseData sscsCaseData = sscsCaseDetails.getData(); sscsCaseData.setDwpState(DwpState.HEARING_POSTPONED); + sscsCaseData.setIgnoreCallbackWarnings(YES); sscsCaseData.setPostponement(Postponement.builder() .unprocessedPostponement(NO) .build()); diff --git a/src/main/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/readytolist/ReadyToListAboutToSubmitHandler.java b/src/main/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/readytolist/ReadyToListAboutToSubmitHandler.java index c664c59ae8c..0cd409d4d9e 100644 --- a/src/main/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/readytolist/ReadyToListAboutToSubmitHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/readytolist/ReadyToListAboutToSubmitHandler.java @@ -20,6 +20,10 @@ @Slf4j public class ReadyToListAboutToSubmitHandler implements PreSubmitCallbackHandler { + 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; @@ -56,10 +60,8 @@ public PreSubmitCallbackResponse handle(CallbackType callbackType, if (!callback.isIgnoreWarnings() && !YesNo.YES.equals(sscsCaseData.getIgnoreCallbackWarnings())) { PreSubmitCallbackResponse 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; } @@ -68,12 +70,10 @@ public PreSubmitCallbackResponse handle(CallbackType callbackType, } if (SscsHelper.hasHearingScheduledInTheFuture(sscsCaseData) - && !callback.isIgnoreWarnings()) { + && !callback.isIgnoreWarnings() && !YesNo.YES.equals(sscsCaseData.getIgnoreCallbackWarnings())) { PreSubmitCallbackResponse 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; } diff --git a/src/main/java/uk/gov/hmcts/reform/sscs/helper/SscsHelper.java b/src/main/java/uk/gov/hmcts/reform/sscs/helper/SscsHelper.java index 6b7496649f6..e5271ba99c5 100644 --- a/src/main/java/uk/gov/hmcts/reform/sscs/helper/SscsHelper.java +++ b/src/main/java/uk/gov/hmcts/reform/sscs/helper/SscsHelper.java @@ -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; @@ -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()); @@ -116,7 +117,10 @@ private static boolean getValidHearing(Hearing hearing) { public static boolean hasHearingScheduledInTheFuture(SscsCaseData caseData) { Optional 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(); } -} \ No newline at end of file +} diff --git a/src/test/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/postpone/PostponeHearingHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/postpone/PostponeHearingHandlerTest.java index 44beea54a7d..ea78a24483a 100644 --- a/src/test/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/postpone/PostponeHearingHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/postpone/PostponeHearingHandlerTest.java @@ -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() { @@ -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() { diff --git a/src/test/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/readytolist/ReadyToListAboutToSubmitHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/readytolist/ReadyToListAboutToSubmitHandlerTest.java index 65c4e19e1eb..a3e96870a46 100644 --- a/src/test/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/readytolist/ReadyToListAboutToSubmitHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/sscs/ccd/presubmit/readytolist/ReadyToListAboutToSubmitHandlerTest.java @@ -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; @@ -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 @@ -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, @@ -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)) @@ -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 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 diff --git a/src/test/java/uk/gov/hmcts/reform/sscs/helper/SscsHelperTest.java b/src/test/java/uk/gov/hmcts/reform/sscs/helper/SscsHelperTest.java index e9b959edcc2..b29b74ee6c8 100644 --- a/src/test/java/uk/gov/hmcts/reform/sscs/helper/SscsHelperTest.java +++ b/src/test/java/uk/gov/hmcts/reform/sscs/helper/SscsHelperTest.java @@ -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") @@ -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 = buildOtherParty();