Skip to content

Commit

Permalink
RIA-9552 Removed AIP check for generate service request (#2346)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasKKC authored Sep 6, 2024
1 parent 47dcc6f commit af406c5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package uk.gov.hmcts.reform.iacaseapi.domain.handlers.presubmit;

import static java.util.Objects.requireNonNull;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.JOURNEY_TYPE;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
Expand All @@ -10,7 +9,6 @@
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.handlers.PreSubmitCallbackHandler;
import uk.gov.hmcts.reform.iacaseapi.domain.service.FeePayment;

Expand Down Expand Up @@ -47,20 +45,8 @@ public PreSubmitCallbackResponse<AsylumCase> handle(
throw new IllegalStateException("Cannot handle callback");
}


AsylumCase asylumCase = callback.getCaseDetails().getCaseData();

if (!isAipJourney(asylumCase)) {
asylumCase = feePayment.aboutToSubmit(callback);

}
AsylumCase asylumCase = feePayment.aboutToSubmit(callback);

return new PreSubmitCallbackResponse<>(asylumCase);
}

private boolean isAipJourney(AsylumCase asylumCase) {
return asylumCase.read(JOURNEY_TYPE, JourneyType.class)
.map(journeyType -> journeyType == JourneyType.AIP)
.orElse(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
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.JOURNEY_TYPE;

import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -24,7 +21,6 @@
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.FeePayment;

@ExtendWith(MockitoExtension.class)
Expand All @@ -51,59 +47,21 @@ public void setUp() {
}

@Test
void no_journey_type_should_make_feePayment_submit_callback() {
void should_make_feePayment_submit_callback() {

when(callback.getEvent()).thenReturn(Event.GENERATE_SERVICE_REQUEST);
when(callback.getCaseDetails()).thenReturn(caseDetails);
when(caseDetails.getCaseData()).thenReturn(asylumCase);
when(asylumCase.read(JOURNEY_TYPE, JourneyType.class)).thenReturn(Optional.empty()); // empty = not AIP

AsylumCase responseAsylumCase = mock(AsylumCase.class);
when(feePayment.aboutToSubmit(callback)).thenReturn(responseAsylumCase); // empty = not AIP

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

assertNotNull(callbackResponse);

verify(feePayment, times(1)).aboutToSubmit(callback);
}

@Test
void lr_should_make_feePayment_submit_callback() {

when(callback.getEvent()).thenReturn(Event.GENERATE_SERVICE_REQUEST);
when(callback.getCaseDetails()).thenReturn(caseDetails);
when(caseDetails.getCaseData()).thenReturn(asylumCase);
when(asylumCase.read(JOURNEY_TYPE, JourneyType.class)).thenReturn(Optional.of(JourneyType.REP));

AsylumCase responseAsylumCase = mock(AsylumCase.class);
when(feePayment.aboutToSubmit(callback)).thenReturn(responseAsylumCase);

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

assertNotNull(callbackResponse);

verify(feePayment, times(1)).aboutToSubmit(callback);
}

@Test
void aip_should_not_make_feePayment_submit_callback() {

when(callback.getEvent()).thenReturn(Event.GENERATE_SERVICE_REQUEST);
when(callback.getCaseDetails()).thenReturn(caseDetails);
when(caseDetails.getCaseData()).thenReturn(asylumCase);
when(asylumCase.read(JOURNEY_TYPE, JourneyType.class)).thenReturn(Optional.of(JourneyType.AIP));
// JourneyType optional empty = not AIP

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

assertNotNull(callbackResponse);

verify(feePayment, never()).aboutToSubmit(callback);
}

@Test
void handling_should_throw_if_cannot_actually_handle() {
Expand Down

0 comments on commit af406c5

Please sign in to comment.