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 c67428ba2d..3cadb2a81f 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 @@ -29,6 +29,7 @@ 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.RemissionType; import uk.gov.hmcts.reform.iacaseapi.domain.entities.StrategicCaseFlag; import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.CaseDetails; import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.Callback; @@ -327,4 +328,9 @@ private static boolean hearingDateUnchanged(AsylumCase asylumCase, AsylumCase as return prevHearingDate.equalsIgnoreCase(currentHearingDate); } + + public static boolean isRemissionExists(Optional remissionType) { + return remissionType.isPresent() + && remissionType.get() != RemissionType.NO_REMISSION; + } } 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 6eea43ca8a..0f26b1f525 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 @@ -10,6 +10,7 @@ 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.isRemissionExists; import java.math.BigDecimal; import java.util.Arrays; @@ -219,12 +220,6 @@ private boolean isRemissionApprovedOrPartiallyApproved(Optional remissionType) { - - return remissionType.isPresent() - && remissionType.get() != RemissionType.NO_REMISSION; - } - private boolean completedStagesHasFeeUpdateStatus( Optional> completedStages, String preRequisiteFeeUpdateStatus) { AtomicBoolean preRequisiteFeeUpdateStatusExists = new AtomicBoolean(false); 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 22a16f9e15..9fa036f6c6 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 @@ -5,6 +5,7 @@ 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 java.util.Arrays; import java.util.Optional; @@ -112,11 +113,6 @@ public PreSubmitCallbackResponse handle( return callbackResponse; } - private boolean isRemissionExists(Optional remissionType) { - - return remissionType.isPresent() && remissionType.get() != RemissionType.NO_REMISSION; - } - private boolean isRemissionExistsAip(Optional remissionOption, Optional helpWithFeesOption) { boolean isDlrmFeeRemission = featureToggler.getValue("dlrm-fee-remission-feature-flag", false); 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 b61c7be32a..d218792e21 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 @@ -6,6 +6,7 @@ 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 java.util.List; import java.util.Optional; @@ -137,12 +138,14 @@ private void checkPaymentConditions(AppealType appealType, AsylumCase asylumCase Optional eaHuPaymentType = asylumCase.read(EA_HU_APPEAL_TYPE_PAYMENT_OPTION, String.class); boolean isEaHuEuAg = List.of(EA, HU, EU, AG).contains(appealType); // old cases - if ((appealType == PA && remissionType.isEmpty() && paPaymentType.isEmpty()) - || (isEaHuEuAg && remissionType.isEmpty() - && eaHuPaymentType.isEmpty())) { + if (!isRemissionExists(remissionType) && !isRemissionExists(lateRemissionType) + && ((appealType == PA && paPaymentType.isEmpty()) || (isEaHuEuAg && eaHuPaymentType.isEmpty())) + ) { callbackResponse.addError(NOT_AVAILABLE_LABEL); } - if (isEaHuEuAg && (remissionType.isEmpty() || remissionType.get() == NO_REMISSION) + if (!isRemissionExists(remissionType) + && !isRemissionExists(lateRemissionType) + && isEaHuEuAg && eaHuPaymentType.isPresent() && eaHuPaymentType.get().equals("payNow") && paymentStatus.isPresent() && paymentStatus.get() == PaymentStatus.PAID) { callbackResponse.addError(NOT_AVAILABLE_LABEL); diff --git a/src/test/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/payment/MarkPaymentPaidPreparerTest.java b/src/test/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/payment/MarkPaymentPaidPreparerTest.java index c0921f7207..2bd55d4543 100644 --- a/src/test/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/payment/MarkPaymentPaidPreparerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/iacaseapi/domain/handlers/presubmit/payment/MarkPaymentPaidPreparerTest.java @@ -2,14 +2,33 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.reset; import static org.powermock.api.mockito.PowerMockito.when; -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.AppealType.AG; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AppealType.EA; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AppealType.EU; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AppealType.HU; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AppealType.PA; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.APPEAL_TYPE; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.APPELLANT_IN_DETENTION; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.EA_HU_APPEAL_TYPE_PAYMENT_OPTION; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.HELP_WITH_FEES_OPTION; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.IS_ACCELERATED_DETAINED_APPEAL; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.IS_ADMIN; +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.PAYMENT_STATUS; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.PA_APPEAL_TYPE_PAYMENT_OPTION; +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.HelpWithFeesOption.WILL_PAY_FOR_APPEAL; import static uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionOption.NO_REMISSION; -import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackStage.*; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionType.HO_WAIVER_REMISSION; +import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackStage.ABOUT_TO_START; import java.util.Optional; import java.util.stream.Stream; @@ -26,7 +45,13 @@ 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.*; +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.AsylumCaseFieldDefinition; +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.CaseDetails; import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event; import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.Callback; @@ -419,4 +444,49 @@ void should_not_allow_null_arguments() { .isExactlyInstanceOf(NullPointerException.class); } + @ParameterizedTest + @MethodSource("appealTypesWithRemissionOptions") + void should_pass_checkRemissionConditions_if_remission_or_late_remission_present( + AppealType appealType, + Optional remissionType, + Optional lateRemission) { + + when(callback.getCaseDetails()).thenReturn(caseDetails); + when(callback.getEvent()).thenReturn(Event.MARK_APPEAL_PAID); + when(callback.getCaseDetails().getCaseData()).thenReturn(asylumCase); + when(asylumCase.read(APPEAL_TYPE, AppealType.class)).thenReturn(Optional.of(appealType)); + when(asylumCase.read(REMISSION_TYPE, RemissionType.class)).thenReturn(remissionType); + when(asylumCase.read(LATE_REMISSION_TYPE, RemissionType.class)).thenReturn(lateRemission); + when(asylumCase.read(PA_APPEAL_TYPE_PAYMENT_OPTION, String.class)).thenReturn(Optional.empty()); + when(asylumCase.read(EA_HU_APPEAL_TYPE_PAYMENT_OPTION, String.class)).thenReturn(Optional.empty()); + when(asylumCase.read(REMISSION_DECISION, RemissionDecision.class)).thenReturn(Optional.of(RemissionDecision.REJECTED)); + + + PreSubmitCallbackResponse returnedCallbackResponse = + markPaymentPaidPreparer.handle(ABOUT_TO_START, callback); + + assertNotNull(returnedCallbackResponse); + assertThat(returnedCallbackResponse.getErrors()).isEmpty(); + } + + private static Stream appealTypesWithRemissionOptions() { + return Stream.of( + Arguments.of(EA, Optional.of(HO_WAIVER_REMISSION), Optional.empty()), + Arguments.of(EA, Optional.empty(), Optional.of(HO_WAIVER_REMISSION)), + Arguments.of(EA, Optional.of(NO_REMISSION), Optional.of(HO_WAIVER_REMISSION)), + Arguments.of(HU, Optional.of(HO_WAIVER_REMISSION), Optional.empty()), + Arguments.of(HU, Optional.empty(), Optional.of(HO_WAIVER_REMISSION)), + Arguments.of(HU, Optional.of(NO_REMISSION), Optional.of(HO_WAIVER_REMISSION)), + Arguments.of(EU, Optional.of(HO_WAIVER_REMISSION), Optional.empty()), + Arguments.of(EU, Optional.empty(), Optional.of(HO_WAIVER_REMISSION)), + Arguments.of(EU, Optional.of(NO_REMISSION), Optional.of(HO_WAIVER_REMISSION)), + Arguments.of(PA, Optional.of(HO_WAIVER_REMISSION), Optional.empty()), + Arguments.of(PA, Optional.empty(), Optional.of(HO_WAIVER_REMISSION)), + Arguments.of(PA, Optional.of(NO_REMISSION), Optional.of(HO_WAIVER_REMISSION)), + Arguments.of(AG, Optional.of(HO_WAIVER_REMISSION), Optional.empty()), + Arguments.of(AG, Optional.empty(), Optional.of(HO_WAIVER_REMISSION)), + Arguments.of(AG, Optional.of(NO_REMISSION), Optional.of(HO_WAIVER_REMISSION)) + ); + } + }