diff --git a/src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/HandlerUtils.java b/src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/HandlerUtils.java index 3cadb2a81f..baa23e88fa 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/HandlerUtils.java +++ b/src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/HandlerUtils.java @@ -4,6 +4,7 @@ import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.*; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.HearingAdjournmentDay.BEFORE_HEARING_DATE; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.HearingAdjournmentDay.ON_HEARING_DATE; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.HelpWithFeesOption.WILL_PAY_FOR_APPEAL; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.StrategicCaseFlagType.AUDIO_VIDEO_EVIDENCE; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.StrategicCaseFlagType.FOREIGN_NATIONAL_OFFENDER; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.StrategicCaseFlagType.LACKING_CAPACITY; @@ -29,6 +30,8 @@ import uk.gov.hmcts.reform.iacaseapi.domain.entities.DynamicList; import uk.gov.hmcts.reform.iacaseapi.domain.entities.HearingAdjournmentDay; import uk.gov.hmcts.reform.iacaseapi.domain.entities.HearingCentre; +import uk.gov.hmcts.reform.iacaseapi.domain.entities.HelpWithFeesOption; +import uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionOption; import uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionType; import uk.gov.hmcts.reform.iacaseapi.domain.entities.StrategicCaseFlag; import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.CaseDetails; @@ -333,4 +336,10 @@ public static boolean isRemissionExists(Optional remissionType) { return remissionType.isPresent() && remissionType.get() != RemissionType.NO_REMISSION; } + + public static boolean isRemissionExistsAip(Optional remissionOption, Optional helpWithFeesOption, boolean isDlrmFeeRemissionFlag) { + return isDlrmFeeRemissionFlag + && ((remissionOption.isPresent() && remissionOption.get() != RemissionOption.NO_REMISSION) + || (helpWithFeesOption.isPresent() && helpWithFeesOption.get() != WILL_PAY_FOR_APPEAL)); + } } diff --git a/src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/ManageFeeUpdateMidEvent.java b/src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/ManageFeeUpdateMidEvent.java index 0f26b1f525..7db0d05169 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/ManageFeeUpdateMidEvent.java +++ b/src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/ManageFeeUpdateMidEvent.java @@ -4,13 +4,17 @@ import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.FEE_UPDATE_COMPLETED_STAGES; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.FEE_UPDATE_REASON; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.FEE_UPDATE_STATUS; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.HELP_WITH_FEES_OPTION; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.LATE_REMISSION_TYPE; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.NEW_FEE_AMOUNT; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.REMISSION_DECISION; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.REMISSION_OPTION; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.REMISSION_TYPE; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionDecision.APPROVED; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionDecision.PARTIALLY_APPROVED; +import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isAipJourney; import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isRemissionExists; +import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isRemissionExistsAip; import java.math.BigDecimal; import java.util.Arrays; @@ -20,7 +24,9 @@ import org.springframework.stereotype.Component; import uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCase; import uk.gov.hmcts.reform.iacaseapi.domain.entities.FeeUpdateReason; +import uk.gov.hmcts.reform.iacaseapi.domain.entities.HelpWithFeesOption; import uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionDecision; +import uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionOption; import uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionType; import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.CheckValues; import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event; @@ -91,7 +97,12 @@ public PreSubmitCallbackResponse handle( Optional remissionType = asylumCase.read(REMISSION_TYPE, RemissionType.class); Optional lateRemissionType = asylumCase.read(LATE_REMISSION_TYPE, RemissionType.class); - if (!isRemissionExists(remissionType) && !isRemissionExists(lateRemissionType)) { + final boolean isDlrmFeeRemissionFlag = featureToggler.getValue("dlrm-fee-remission-feature-flag", false); + Optional remissionOption = asylumCase.read(REMISSION_OPTION, RemissionOption.class); + Optional helpWithFeesOption = asylumCase.read(HELP_WITH_FEES_OPTION, HelpWithFeesOption.class); + + if ((!isAipJourney(asylumCase) && !isRemissionExists(remissionType) && !isRemissionExists(lateRemissionType)) + || (isAipJourney(asylumCase) && !isRemissionExistsAip(remissionOption, helpWithFeesOption, isDlrmFeeRemissionFlag))) { callbackResponse.addError( "You cannot choose this option because there is no remission request associated with this appeal"); diff --git a/src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/RecordRemissionDecisionPreparer.java b/src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/RecordRemissionDecisionPreparer.java index 9fa036f6c6..b120eae115 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/RecordRemissionDecisionPreparer.java +++ b/src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/RecordRemissionDecisionPreparer.java @@ -2,10 +2,9 @@ import static java.util.Objects.requireNonNull; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.*; -import static uk.gov.hmcts.reform.iacaseapi.domain.entities.HelpWithFeesOption.WILL_PAY_FOR_APPEAL; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionDecision.*; -import static uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionOption.NO_REMISSION; import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isRemissionExists; +import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isRemissionExistsAip; import java.util.Arrays; import java.util.Optional; @@ -42,8 +41,8 @@ public boolean canHandle( requireNonNull(callback, "callback must not be null"); return callbackStage == PreSubmitCallbackStage.ABOUT_TO_START - && callback.getEvent() == Event.RECORD_REMISSION_DECISION - && featureToggler.getValue("remissions-feature", false); + && callback.getEvent() == Event.RECORD_REMISSION_DECISION + && featureToggler.getValue("remissions-feature", false); } public PreSubmitCallbackResponse handle( @@ -70,6 +69,8 @@ public PreSubmitCallbackResponse handle( case EU: case PA: case AG: + final boolean isDlrmFeeRemissionFlag = featureToggler.getValue("dlrm-fee-remission-feature-flag", false); + Optional paymentStatus = asylumCase.read(PAYMENT_STATUS, PaymentStatus.class); Optional remissionType = asylumCase.read(REMISSION_TYPE, RemissionType.class); @@ -81,7 +82,7 @@ public PreSubmitCallbackResponse handle( Optional remissionDecision = asylumCase.read(REMISSION_DECISION, RemissionDecision.class); - if (!isRemissionExists(remissionType) && !isRemissionExists(lateRemissionType) && !isRemissionExistsAip(remissionOptionAip, helpWithFeesOptionAip)) { + if (!isRemissionExists(remissionType) && !isRemissionExists(lateRemissionType) && !isRemissionExistsAip(remissionOptionAip, helpWithFeesOptionAip, isDlrmFeeRemissionFlag)) { callbackResponse.addError("You cannot record a remission decision because a remission has not been requested for this appeal"); @@ -90,7 +91,7 @@ public PreSubmitCallbackResponse handle( callbackResponse.addError("The fee for this appeal has already been paid."); } else if (remissionDecision.isPresent() - && Arrays.asList(APPROVED, PARTIALLY_APPROVED, REJECTED).contains(remissionDecision.get())) { + && Arrays.asList(APPROVED, PARTIALLY_APPROVED, REJECTED).contains(remissionDecision.get())) { callbackResponse.addError("The remission decision for this appeal has already been recorded."); @@ -113,21 +114,13 @@ public PreSubmitCallbackResponse handle( return callbackResponse; } - private boolean isRemissionExistsAip(Optional remissionOption, Optional helpWithFeesOption) { - boolean isDlrmFeeRemission = featureToggler.getValue("dlrm-fee-remission-feature-flag", false); - - return (remissionOption.isPresent() && remissionOption.get() != NO_REMISSION) - || (helpWithFeesOption.isPresent() && helpWithFeesOption.get() != WILL_PAY_FOR_APPEAL) - && isDlrmFeeRemission; - } - private boolean isRemissionAmountLeftPaid( Optional remissionDecision, Optional paymentStatus ) { return remissionDecision.isPresent() - && Arrays.asList(PARTIALLY_APPROVED, REJECTED).contains(remissionDecision.get()) - && paymentStatus.isPresent() - && Arrays.asList(PaymentStatus.PAID).contains(paymentStatus.get()); + && Arrays.asList(PARTIALLY_APPROVED, REJECTED).contains(remissionDecision.get()) + && paymentStatus.isPresent() + && Arrays.asList(PaymentStatus.PAID).contains(paymentStatus.get()); } } diff --git a/src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/payment/MarkPaymentPaidPreparer.java b/src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/payment/MarkPaymentPaidPreparer.java index d218792e21..55246fe349 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/payment/MarkPaymentPaidPreparer.java +++ b/src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/payment/MarkPaymentPaidPreparer.java @@ -3,10 +3,10 @@ import static java.util.Objects.requireNonNull; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AppealType.*; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.*; -import static uk.gov.hmcts.reform.iacaseapi.domain.entities.HelpWithFeesOption.WILL_PAY_FOR_APPEAL; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionDecision.*; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionType.*; import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isRemissionExists; +import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isRemissionExistsAip; import java.util.List; import java.util.Optional; @@ -101,7 +101,8 @@ private void checkRemissionConditions(AppealType appealType, AsylumCase asylumCa if (isAipJourney) { Optional remissionOption = asylumCase.read(REMISSION_OPTION, RemissionOption.class); Optional helpWithFeesOption = asylumCase.read(HELP_WITH_FEES_OPTION, HelpWithFeesOption.class); - if (!isRemissionExistsAip(remissionOption, helpWithFeesOption)) { + final boolean isDlrmFeeRemissionFlag = featureToggler.getValue("dlrm-fee-remission-feature-flag", false); + if (!isRemissionExistsAip(remissionOption, helpWithFeesOption, isDlrmFeeRemissionFlag)) { callbackResponse.addError(NOT_AVAILABLE_LABEL); } } else { @@ -166,14 +167,6 @@ private void checkPaymentConditions(AppealType appealType, AsylumCase asylumCase } } - private boolean isRemissionExistsAip(Optional remissionOption, Optional helpWithFeesOption) { - boolean isDlrmFeeRemission = featureToggler.getValue("dlrm-fee-remission-feature-flag", false); - - return (remissionOption.isPresent() && remissionOption.get() != RemissionOption.NO_REMISSION) - || (helpWithFeesOption.isPresent() && helpWithFeesOption.get() != WILL_PAY_FOR_APPEAL) - && isDlrmFeeRemission; - } - private boolean awaitingRemissionDecision(AsylumCase asylumCase) { Optional lateRemissionType = asylumCase.read(LATE_REMISSION_TYPE, RemissionType.class); Optional remissionType = asylumCase.read(REMISSION_TYPE, RemissionType.class); diff --git a/src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/payment/PaymentStateHandler.java b/src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/payment/PaymentStateHandler.java index 654539782d..983a932429 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/payment/PaymentStateHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/payment/PaymentStateHandler.java @@ -2,9 +2,6 @@ import static java.util.Objects.requireNonNull; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.*; -import static uk.gov.hmcts.reform.iacaseapi.domain.entities.HelpWithFeesOption.WILL_PAY_FOR_APPEAL; -import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.State.*; -import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.PaymentStatus.*; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.State.APPEAL_STARTED; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.State.APPEAL_STARTED_BY_ADMIN; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.State.APPEAL_SUBMITTED; @@ -12,6 +9,7 @@ import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.PaymentStatus.FAILED; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.PaymentStatus.PAID; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.PaymentStatus.PAYMENT_PENDING; +import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isRemissionExistsAip; import java.util.List; import java.util.Optional; @@ -125,19 +123,12 @@ private static PreSubmitCallbackResponse decideAppealState(AppealTyp } } - private boolean isRemissionExistsAip(Optional remissionOption, Optional helpWithFeesOption) { - boolean isDlrmFeeRemission = featureToggler.getValue("dlrm-fee-remission-feature-flag", false); - - return (remissionOption.isPresent() && remissionOption.get() != RemissionOption.NO_REMISSION) - || (helpWithFeesOption.isPresent() && helpWithFeesOption.get() != WILL_PAY_FOR_APPEAL) - && isDlrmFeeRemission; - } - private PreSubmitCallbackResponse handleDlrmFeeRemission(Callback callback, State currentState, boolean isPayLaterAppeal, boolean isPaymentStatusPaid) { + final boolean isDlrmFeeRemissionFlag = featureToggler.getValue("dlrm-fee-remission-feature-flag", false); AsylumCase asylumCase = callback.getCaseDetails().getCaseData(); Optional remissionOption = asylumCase.read(REMISSION_OPTION, RemissionOption.class); Optional helpWithFeesOption = asylumCase.read(HELP_WITH_FEES_OPTION, HelpWithFeesOption.class); - State state = isRemissionExistsAip(remissionOption, helpWithFeesOption) + State state = isRemissionExistsAip(remissionOption, helpWithFeesOption, isDlrmFeeRemissionFlag) && !isPayLaterAppeal && !isPaymentStatusPaid ? PENDING_PAYMENT : APPEAL_SUBMITTED; if (isValidPayLaterPaymentEvent(callback, currentState, isPayLaterAppeal)) { state = currentState; diff --git a/src/test/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/HandlerUtilsTest.java b/src/test/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/HandlerUtilsTest.java index e94f38851e..555193d83b 100644 --- a/src/test/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/HandlerUtilsTest.java +++ b/src/test/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/HandlerUtilsTest.java @@ -1,42 +1,78 @@ package uk.gov.hmcts.reform.iacaseapi.domain.handlers; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.*; +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.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.*; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.APPEAL_TYPE; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.APPELLANT_FAMILY_NAME; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.APPELLANT_GIVEN_NAMES; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.APPELLANT_LEVEL_FLAGS; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.APPELLANT_NAME_FOR_DISPLAY; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.AUTO_HEARING_REQUEST_ENABLED; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.AUTO_LIST_HEARING; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.CASE_LEVEL_FLAGS; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.HEARING_ADJOURNMENT_WHEN; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.HEARING_CHANNEL; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.IS_ADMIN; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.IS_CASE_USING_LOCATION_REF_DATA; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.IS_EJP; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.IS_INTEGRATED; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.IS_LEGALLY_REPRESENTED_EJP; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.IS_NOTIFICATION_TURNED_OFF; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.IS_PANEL_REQUIRED; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.IS_REMOTE_HEARING; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.JOURNEY_TYPE; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.LEGAL_REP_NAME; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.LIST_CASE_HEARING_CENTRE; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.LIST_CASE_HEARING_DATE; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.RELIST_CASE_IMMEDIATELY; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.SELECTED_HEARING_CENTRE_REF_DATA; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.SOURCE_OF_APPEAL; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.HearingAdjournmentDay.BEFORE_HEARING_DATE; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.HearingAdjournmentDay.ON_HEARING_DATE; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.HearingCentre.GLASGOW; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionType.NO_REMISSION; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.YesOrNo.YES; import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.adjournedBeforeHearingDay; import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.adjournedOnHearingDay; import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isCaseUsingLocationRefData; import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isIntegrated; -import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isPanelRequired; import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isOnlyRemoteToRemoteHearingChannelUpdate; +import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isPanelRequired; import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.relistCaseImmediately; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.stream.Stream; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.EnumSource; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.quality.Strictness; +import uk.gov.hmcts.reform.iacaseapi.domain.entities.AppealType; import uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCase; import uk.gov.hmcts.reform.iacaseapi.domain.entities.CaseFlagDetail; import uk.gov.hmcts.reform.iacaseapi.domain.entities.CaseFlagValue; import uk.gov.hmcts.reform.iacaseapi.domain.entities.DynamicList; import uk.gov.hmcts.reform.iacaseapi.domain.entities.HearingAdjournmentDay; import uk.gov.hmcts.reform.iacaseapi.domain.entities.HearingCentre; +import uk.gov.hmcts.reform.iacaseapi.domain.entities.HelpWithFeesOption; +import uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionOption; +import uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionType; +import uk.gov.hmcts.reform.iacaseapi.domain.entities.SourceOfAppeal; import uk.gov.hmcts.reform.iacaseapi.domain.entities.StrategicCaseFlag; import uk.gov.hmcts.reform.iacaseapi.domain.entities.Value; import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.CaseDetails; @@ -44,8 +80,6 @@ import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.JourneyType; import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.YesOrNo; import uk.gov.hmcts.reform.iacaseapi.domain.service.LocationBasedFeatureToggler; -import uk.gov.hmcts.reform.iacaseapi.domain.entities.AppealType; -import uk.gov.hmcts.reform.iacaseapi.domain.entities.SourceOfAppeal; @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) @@ -282,7 +316,7 @@ void setDefaultAutoListHearingValue_ActiveFlagPresent(boolean hasAppellantFlags, } @ParameterizedTest - @EnumSource(value = YesOrNo.class, names = {"YES","NO"}) + @EnumSource(value = YesOrNo.class, names = {"YES", "NO"}) void should_return_whether_panel_is_required(YesOrNo yesOrNo) { when(asylumCase.read(IS_PANEL_REQUIRED, YesOrNo.class)).thenReturn(Optional.of(yesOrNo)); @@ -290,7 +324,7 @@ void should_return_whether_panel_is_required(YesOrNo yesOrNo) { } @ParameterizedTest - @EnumSource(value = YesOrNo.class, names = {"YES","NO"}) + @EnumSource(value = YesOrNo.class, names = {"YES", "NO"}) void isIntegrated_should_work_as_expected(YesOrNo integrated) { when(asylumCase.read(IS_INTEGRATED, YesOrNo.class)).thenReturn(Optional.of(integrated)); @@ -298,7 +332,7 @@ void isIntegrated_should_work_as_expected(YesOrNo integrated) { } @ParameterizedTest - @EnumSource(value = YesOrNo.class, names = {"YES","NO"}) + @EnumSource(value = YesOrNo.class, names = {"YES", "NO"}) void relistCaseImmediately_should_work_as_expected(YesOrNo relist) { when(asylumCase.read(RELIST_CASE_IMMEDIATELY, YesOrNo.class)) .thenReturn(Optional.of(relist)); @@ -315,7 +349,7 @@ void relistCaseImmediately_should_throw_exception() { } @ParameterizedTest - @EnumSource(value = HearingAdjournmentDay.class, names = {"ON_HEARING_DATE","BEFORE_HEARING_DATE"}) + @EnumSource(value = HearingAdjournmentDay.class, names = {"ON_HEARING_DATE", "BEFORE_HEARING_DATE"}) void adjournBeforeHearingDay_should_work_as_expected(HearingAdjournmentDay adjournmentDay) { when(asylumCase.read(HEARING_ADJOURNMENT_WHEN, HearingAdjournmentDay.class)) .thenReturn(Optional.of(adjournmentDay)); @@ -324,7 +358,7 @@ void adjournBeforeHearingDay_should_work_as_expected(HearingAdjournmentDay adjou } @ParameterizedTest - @EnumSource(value = HearingAdjournmentDay.class, names = {"ON_HEARING_DATE","BEFORE_HEARING_DATE"}) + @EnumSource(value = HearingAdjournmentDay.class, names = {"ON_HEARING_DATE", "BEFORE_HEARING_DATE"}) void adjournOnHearingDay_should_work_as_expected(HearingAdjournmentDay adjournmentDay) { when(asylumCase.read(HEARING_ADJOURNMENT_WHEN, HearingAdjournmentDay.class)) .thenReturn(Optional.of(adjournmentDay)); @@ -363,7 +397,7 @@ public void read_json_file_list_non_array_json_returns_empty() throws IOExceptio } @ParameterizedTest - @EnumSource(value = YesOrNo.class, names = {"YES","NO"}) + @EnumSource(value = YesOrNo.class, names = {"YES", "NO"}) void should_return_whether_case_uses_location_ref_data(YesOrNo yesOrNo) { when(asylumCase.read(IS_CASE_USING_LOCATION_REF_DATA, YesOrNo.class)).thenReturn(Optional.of(yesOrNo)); @@ -430,4 +464,51 @@ void isOnlyRemoteToRemoteHearingChannelUpdate_should_return_false_when_no_previo assertFalse(isOnlyRemoteToRemoteHearingChannelUpdate(callback)); } + + @ParameterizedTest + @EnumSource(value = RemissionType.class, names = {"NO_REMISSION", "HO_WAIVER_REMISSION", "HELP_WITH_FEES", "EXCEPTIONAL_CIRCUMSTANCES_REMISSION"}) + void should_return_is_non_aip_remission_exists_proper_value(RemissionType remissionType) { + + if (NO_REMISSION.equals(remissionType)) { + assertFalse(HandlerUtils.isRemissionExists(Optional.of(remissionType))); + } else { + assertTrue(HandlerUtils.isRemissionExists(Optional.of(remissionType))); + } + } + + @ParameterizedTest + @MethodSource("provideAipRemissionParameters") + void should_return_aip_remission_exists_proper_value(RemissionOption remissionOption, HelpWithFeesOption helpWithFeesOption, boolean isDlrmFeeRemissionFlag, boolean expectedResult) { + boolean actualResult = HandlerUtils.isRemissionExistsAip(Optional.of(remissionOption), Optional.of(helpWithFeesOption), isDlrmFeeRemissionFlag); + assertEquals(expectedResult, actualResult); + } + + private static Stream provideAipRemissionParameters() { + return Stream.of( + Arguments.of(RemissionOption.ASYLUM_SUPPORT_FROM_HOME_OFFICE, HelpWithFeesOption.WANT_TO_APPLY, true, true), + Arguments.of(RemissionOption.ASYLUM_SUPPORT_FROM_HOME_OFFICE, HelpWithFeesOption.WANT_TO_APPLY, false, false), + Arguments.of(RemissionOption.ASYLUM_SUPPORT_FROM_HOME_OFFICE, HelpWithFeesOption.ALREADY_APPLIED, true, true), + Arguments.of(RemissionOption.ASYLUM_SUPPORT_FROM_HOME_OFFICE, HelpWithFeesOption.WILL_PAY_FOR_APPEAL, true, true), + + Arguments.of(RemissionOption.FEE_WAIVER_FROM_HOME_OFFICE, HelpWithFeesOption.WANT_TO_APPLY, true, true), + Arguments.of(RemissionOption.FEE_WAIVER_FROM_HOME_OFFICE, HelpWithFeesOption.ALREADY_APPLIED, true, true), + Arguments.of(RemissionOption.FEE_WAIVER_FROM_HOME_OFFICE, HelpWithFeesOption.WILL_PAY_FOR_APPEAL, true, true), + + Arguments.of(RemissionOption.UNDER_18_GET_SUPPORT, HelpWithFeesOption.WANT_TO_APPLY, true, true), + Arguments.of(RemissionOption.UNDER_18_GET_SUPPORT, HelpWithFeesOption.ALREADY_APPLIED, true, true), + Arguments.of(RemissionOption.UNDER_18_GET_SUPPORT, HelpWithFeesOption.WILL_PAY_FOR_APPEAL, true, true), + + Arguments.of(RemissionOption.PARENT_GET_SUPPORT, HelpWithFeesOption.WANT_TO_APPLY, true, true), + Arguments.of(RemissionOption.PARENT_GET_SUPPORT, HelpWithFeesOption.ALREADY_APPLIED, true, true), + Arguments.of(RemissionOption.PARENT_GET_SUPPORT, HelpWithFeesOption.WILL_PAY_FOR_APPEAL, true, true), + + Arguments.of(RemissionOption.NO_REMISSION, HelpWithFeesOption.WANT_TO_APPLY, true, true), + Arguments.of(RemissionOption.NO_REMISSION, HelpWithFeesOption.ALREADY_APPLIED, true, true), + Arguments.of(RemissionOption.NO_REMISSION, HelpWithFeesOption.WILL_PAY_FOR_APPEAL, true, false), + + Arguments.of(RemissionOption.I_WANT_TO_GET_HELP_WITH_FEES, HelpWithFeesOption.WANT_TO_APPLY, true, true), + Arguments.of(RemissionOption.I_WANT_TO_GET_HELP_WITH_FEES, HelpWithFeesOption.ALREADY_APPLIED, true, true), + Arguments.of(RemissionOption.I_WANT_TO_GET_HELP_WITH_FEES, HelpWithFeesOption.WILL_PAY_FOR_APPEAL, true, true) + ); + } } diff --git a/src/test/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/ManageFeeUpdateMidEventTest.java b/src/test/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/ManageFeeUpdateMidEventTest.java index 5db70b710a..f19bb8ec64 100644 --- a/src/test/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/ManageFeeUpdateMidEventTest.java +++ b/src/test/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/ManageFeeUpdateMidEventTest.java @@ -10,9 +10,11 @@ import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.FEE_UPDATE_REASON; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.FEE_UPDATE_RECORDED; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.FEE_UPDATE_STATUS; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.JOURNEY_TYPE; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.LATE_REMISSION_TYPE; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.NEW_FEE_AMOUNT; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.REMISSION_DECISION; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.REMISSION_OPTION; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.REMISSION_TYPE; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackStage.MID_EVENT; @@ -31,6 +33,7 @@ import uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCase; import uk.gov.hmcts.reform.iacaseapi.domain.entities.FeeUpdateReason; import uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionDecision; +import uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionOption; import uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionType; import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.CaseDetails; import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.CheckValues; @@ -38,6 +41,7 @@ import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.Callback; import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackResponse; import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackStage; +import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.JourneyType; import uk.gov.hmcts.reform.iacaseapi.domain.service.FeatureToggler; @MockitoSettings(strictness = Strictness.LENIENT) @@ -132,6 +136,28 @@ void handle_should_return_error_if_remission_does_not_exists() { "You cannot choose this option because there is no remission request associated with this appeal"); } + @Test + void handle_should_return_error_if_aip_journey_and_remission_does_not_exists() { + + when(featureToggler.getValue("manage-fee-update-feature", false)).thenReturn(true); + when(featureToggler.getValue("dlrm-fee-remission-feature-flag", false)).thenReturn(true); + + when(callback.getCaseDetails()).thenReturn(caseDetails); + when(caseDetails.getCaseData()).thenReturn(asylumCase); + when(callback.getEvent()).thenReturn(Event.MANAGE_FEE_UPDATE); + when(asylumCase.read(FEE_UPDATE_REASON, FeeUpdateReason.class)).thenReturn(Optional.of(FeeUpdateReason.FEE_REMISSION_CHANGED)); + when(asylumCase.read(REMISSION_OPTION, RemissionOption.class)).thenReturn(Optional.of(RemissionOption.NO_REMISSION)); + when(asylumCase.read(JOURNEY_TYPE, JourneyType.class)).thenReturn(Optional.of(JourneyType.AIP)); + + PreSubmitCallbackResponse callbackResponse = manageFeeUpdateMidEvent.handle(MID_EVENT, callback); + + assertNotNull(callbackResponse); + assertThat(callbackResponse.getErrors()).isNotEmpty(); + assertThat(callbackResponse.getErrors()) + .contains( + "You cannot choose this option because there is no remission request associated with this appeal"); + } + @Test void handle_should_return_error_on_one_or_no_completed_stages() {