Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/DIAC-556-Remove-jcenter' into DI…
Browse files Browse the repository at this point in the history
…AC-556-Remove-jcenter
  • Loading branch information
AmandaRichards committed Aug 13, 2024
2 parents fbfc060 + 846f323 commit cb3f985
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 133 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ dependencies {

functionalTestImplementation group: 'com.github.hmcts', name: 'core-case-data-store-client', version: '4.9.2'


//pact contract testing
contractTestImplementation group: 'au.com.dius.pact.consumer', name: 'junit5', version: '4.2.14'
contractTestImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: versions.junit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package uk.gov.hmcts.reform.iacaseapi.domain.handlers.presubmit;

import static java.util.Objects.requireNonNull;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.JOURNEY_TYPE;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.PREV_JOURNEY_TYPE;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.PRE_CLARIFYING_STATE;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.REMISSION_DECISION;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.REMISSION_TYPE;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.YesOrNo.YES;

import java.util.List;
import java.util.Optional;
Expand All @@ -16,8 +12,6 @@
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.ContactPreference;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionDecision;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionType;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.Subscriber;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.State;
Expand All @@ -26,7 +20,7 @@
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackStage;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.IdValue;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.JourneyType;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.PaymentStatus;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.YesOrNo;
import uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils;
import uk.gov.hmcts.reform.iacaseapi.domain.handlers.PreSubmitCallbackStateHandler;

Expand Down Expand Up @@ -69,40 +63,9 @@ public PreSubmitCallbackResponse<AsylumCase> handle(PreSubmitCallbackStage callb
currentState = State.CASE_UNDER_REVIEW;
}

updatePaymentServiceRequestDetails(asylumCase);

return new PreSubmitCallbackResponse<>(asylumCase, currentState);
}

private void updatePaymentServiceRequestDetails(AsylumCase asylumCase) {
Optional<PaymentStatus> paymentStatusOptional = asylumCase.read(
AsylumCaseFieldDefinition.PAYMENT_STATUS, PaymentStatus.class);

if (paymentStatusOptional.isPresent()
&& !PaymentStatus.PAID.equals(paymentStatusOptional.get())
&& hasNoRemission(asylumCase)) {

asylumCase.write(AsylumCaseFieldDefinition.IS_SERVICE_REQUEST_TAB_VISIBLE_CONSIDERING_REMISSIONS, YES);

Optional<String> paymentReferenceOpt = asylumCase.read(AsylumCaseFieldDefinition.PAYMENT_REFERENCE);

if (paymentReferenceOpt.isPresent() && isNotEmpty(paymentReferenceOpt.get())) {
asylumCase.write(AsylumCaseFieldDefinition.HAS_SERVICE_REQUEST_ALREADY, YES);
}
}
}

private boolean hasNoRemission(AsylumCase asylumCase) {
Optional<RemissionType> optRemissionType = asylumCase.read(REMISSION_TYPE, RemissionType.class);
Optional<RemissionDecision> optionalRemissionDecision =
asylumCase.read(REMISSION_DECISION, RemissionDecision.class);

return optRemissionType.isEmpty()
|| optRemissionType.get() == RemissionType.NO_REMISSION
|| (optionalRemissionDecision.isPresent()
&& optionalRemissionDecision.get() != RemissionDecision.APPROVED);
}

private void updateAppellantContactDetails(AsylumCase asylumCase) {
Optional<List<IdValue<Subscriber>>> subscriptionsOptional = asylumCase.read(AsylumCaseFieldDefinition.SUBSCRIPTIONS);

Expand All @@ -111,7 +74,7 @@ private void updateAppellantContactDetails(AsylumCase asylumCase) {
Subscriber subscriber = subscriptionsOptional.get().stream().findFirst().map(IdValue::getValue).orElse(null);

if (subscriber != null) {
ContactPreference contactPreference = subscriber.getWantsEmail() == YES
ContactPreference contactPreference = subscriber.getWantsEmail() == YesOrNo.YES
? ContactPreference.WANTS_EMAIL
: ContactPreference.WANTS_SMS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public PreSubmitCallbackResponse<AsylumCase> handle(
Optional<RemissionType> optRemissionType = asylumCase.read(REMISSION_TYPE, RemissionType.class);
Optional<RemissionDecision> optRemissionDecision = asylumCase.read(REMISSION_DECISION, RemissionDecision.class);

if (optRemissionType.isEmpty() || optRemissionType.get().equals(RemissionType.NO_REMISSION)) {
if (optRemissionType.isPresent() && optRemissionType.get().equals(RemissionType.NO_REMISSION)) {
asylumCase.write(IS_SERVICE_REQUEST_TAB_VISIBLE_CONSIDERING_REMISSIONS, YesOrNo.YES);
} else {
asylumCase.write(IS_SERVICE_REQUEST_TAB_VISIBLE_CONSIDERING_REMISSIONS, YesOrNo.NO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand All @@ -22,24 +21,15 @@
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.BeforeEach;
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.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.AsylumCase;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ContactPreference;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionDecision;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionType;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.Subscriber;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.SubscriberType;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.CaseDetails;
Expand All @@ -50,7 +40,6 @@
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackStage;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.IdValue;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.JourneyType;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.PaymentStatus;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.YesOrNo;

@MockitoSettings(strictness = Strictness.LENIENT)
Expand Down Expand Up @@ -203,65 +192,6 @@ void should_update_appellant_contact_details_with_email_preference() {
verify(asylumCase, times(1)).clear(SUBSCRIPTIONS);
}

@ParameterizedTest
@MethodSource("providePaymentUpdateScenarios")
void should_update_payment_details_when_payment_is_pending_and_remission_rejected(
PaymentStatus paymentStatus,
String paymentReference,
RemissionType remissionType,
RemissionDecision remissionDecision,
boolean updateServiceRequestData) {

when(asylumCase.read(AsylumCaseFieldDefinition.PAYMENT_STATUS, PaymentStatus.class))
.thenReturn(Optional.of(paymentStatus));
when(asylumCase.read(AsylumCaseFieldDefinition.PAYMENT_REFERENCE))
.thenReturn(Optional.ofNullable(paymentReference));
when(asylumCase.read(AsylumCaseFieldDefinition.REMISSION_TYPE, RemissionType.class))
.thenReturn(Optional.ofNullable(remissionType));
when(asylumCase.read(AsylumCaseFieldDefinition.REMISSION_DECISION, RemissionDecision.class))
.thenReturn(Optional.ofNullable(remissionDecision));

PreSubmitCallbackResponse<AsylumCase> response = aipToLegalRepJourneyHandler.handle(
PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback, callbackResponse);

assertNotNull(response);
assertEquals(asylumCase, response.getData());

if (updateServiceRequestData) {
verify(asylumCase, times(1)).write(
AsylumCaseFieldDefinition.IS_SERVICE_REQUEST_TAB_VISIBLE_CONSIDERING_REMISSIONS, YesOrNo.YES);

if (StringUtils.isNotEmpty(paymentReference)) {
verify(asylumCase, times(1))
.write(AsylumCaseFieldDefinition.HAS_SERVICE_REQUEST_ALREADY, YesOrNo.YES);
}
} else {
verify(asylumCase, never())
.write(AsylumCaseFieldDefinition.HAS_SERVICE_REQUEST_ALREADY, YesOrNo.YES);
verify(asylumCase, never()).write(
AsylumCaseFieldDefinition.IS_SERVICE_REQUEST_TAB_VISIBLE_CONSIDERING_REMISSIONS, YesOrNo.YES);
}
}

static Stream<Arguments> providePaymentUpdateScenarios() {
final String reference = "1111-1111-1111-1111";
return Stream.of(
Arguments.of(PaymentStatus.PAYMENT_PENDING, reference, RemissionType.NO_REMISSION, null, true),
Arguments.of(PaymentStatus.PAYMENT_PENDING, reference, null, null, true),
Arguments.of(PaymentStatus.PAYMENT_PENDING, reference, RemissionType.HO_WAIVER_REMISSION, RemissionDecision.PARTIALLY_APPROVED, true),
Arguments.of(PaymentStatus.PAYMENT_PENDING, reference, null, null, true),
Arguments.of(PaymentStatus.PAYMENT_PENDING, reference, RemissionType.HO_WAIVER_REMISSION, RemissionDecision.REJECTED, true),
Arguments.of(PaymentStatus.PAYMENT_PENDING, null, RemissionType.NO_REMISSION, null, true),
Arguments.of(PaymentStatus.PAYMENT_PENDING, null, null, null, true),
Arguments.of(PaymentStatus.PAYMENT_PENDING, "", RemissionType.HO_WAIVER_REMISSION, RemissionDecision.PARTIALLY_APPROVED, true),
Arguments.of(PaymentStatus.PAYMENT_PENDING, "", null, null, true),
Arguments.of(PaymentStatus.PAYMENT_PENDING, reference, RemissionType.HO_WAIVER_REMISSION, RemissionDecision.REJECTED, true),
Arguments.of(PaymentStatus.PAID, reference, RemissionType.EXCEPTIONAL_CIRCUMSTANCES_REMISSION, RemissionDecision.APPROVED, false),
Arguments.of(PaymentStatus.PAYMENT_PENDING, reference, RemissionType.HELP_WITH_FEES, null, false),
Arguments.of(PaymentStatus.PAID, reference, RemissionType.NO_REMISSION, null, false)
);
}

@Test
void should_update_appellant_contact_details_with_sms_preference() {
Subscriber subscriber = new Subscriber(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,6 @@ void should_make_service_request_tab_visible_if_no_remission() {
assertEquals(YesOrNo.YES, yesOrNoCaptor.getValue());
}

@Test
void should_make_service_request_tab_visible_when_remission_type_does_not_exist() {

when(callback.getEvent()).thenReturn(SUBMIT_APPEAL);
when(callback.getCaseDetails()).thenReturn(caseDetails);
when(caseDetails.getCaseData()).thenReturn(asylumCase);
when(asylumCase.read(PA_APPEAL_TYPE_PAYMENT_OPTION, String.class)).thenReturn(Optional.empty());
when(asylumCase.read(JOURNEY_TYPE, JourneyType.class)).thenReturn(Optional.empty());
when(asylumCase.read(APPEAL_OUT_OF_COUNTRY, YesOrNo.class)).thenReturn(Optional.of(YesOrNo.NO));
when(asylumCase.read(REMISSION_TYPE, RemissionType.class)).thenReturn(Optional.empty());

appealSubmitHandler.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback);

ArgumentCaptor<AsylumCaseFieldDefinition> tabVisibleFieldCaptor = ArgumentCaptor.forClass(AsylumCaseFieldDefinition.class);
ArgumentCaptor<Object> yesOrNoCaptor = ArgumentCaptor.forClass(YesOrNo.class);
verify(asylumCase, times(1))
.write(tabVisibleFieldCaptor.capture(), yesOrNoCaptor.capture());

assertEquals(IS_SERVICE_REQUEST_TAB_VISIBLE_CONSIDERING_REMISSIONS, tabVisibleFieldCaptor.getValue());
assertEquals(YesOrNo.YES, yesOrNoCaptor.getValue());
}

@ParameterizedTest
@EnumSource(value = RemissionDecision.class, names = {"PARTIALLY_APPROVED", "APPROVED"})
void should_make_service_request_tab_hidden_if_remission_not_rejected(RemissionDecision remissionDecision) {
Expand Down

0 comments on commit cb3f985

Please sign in to comment.