diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/businessprocess/EndGeneralAppBusinessProcessCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/businessprocess/EndGeneralAppBusinessProcessCallbackHandler.java index 6a714f180..2cc7de6ce 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/businessprocess/EndGeneralAppBusinessProcessCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/businessprocess/EndGeneralAppBusinessProcessCallbackHandler.java @@ -157,9 +157,10 @@ private boolean isLipPaymentViaHelpWithFees(CaseData data) { return data.getCcdState().equals(AWAITING_APPLICATION_PAYMENT) && !Objects.isNull(data.getGeneralAppHelpWithFees()) && data.getGeneralAppHelpWithFees().getHelpWithFee() == YesOrNo.YES - && !Objects.isNull(data.getFeePaymentOutcomeDetails()) + && (Objects.nonNull(data.getGeneralAppPBADetails().getPaymentDetails()) + || (!Objects.isNull(data.getFeePaymentOutcomeDetails()) && (data.getFeePaymentOutcomeDetails().getHwfFullRemissionGrantedForGa() == YesOrNo.YES - || (!Objects.isNull(data.getFeePaymentOutcomeDetails().getHwfOutstandingFeePaymentDoneForGa()) - && data.getFeePaymentOutcomeDetails().getHwfOutstandingFeePaymentDoneForGa().contains("Yes"))); + || (!Objects.isNull(data.getFeePaymentOutcomeDetails().getHwfOutstandingFeePaymentDoneForGa()) + && data.getFeePaymentOutcomeDetails().getHwfOutstandingFeePaymentDoneForGa().contains("Yes"))))); } } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/ApplyForHwFDashboardNotificationHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/ApplyForHwFDashboardNotificationHandler.java index d55b91916..a12510bcc 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/ApplyForHwFDashboardNotificationHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/ApplyForHwFDashboardNotificationHandler.java @@ -10,14 +10,18 @@ import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.callback.CaseEvent; import uk.gov.hmcts.reform.civil.client.DashboardApiClient; +import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.service.DashboardNotificationsParamsMapper; +import uk.gov.hmcts.reform.civil.service.GaForLipService; +import uk.gov.hmcts.reform.civil.service.ParentCaseUpdateHelper; import uk.gov.hmcts.reform.civil.utils.HwFFeeTypeService; import uk.gov.hmcts.reform.dashboard.data.ScenarioRequestParams; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; @@ -30,6 +34,8 @@ public class ApplyForHwFDashboardNotificationHandler extends CallbackHandler { private final ObjectMapper objectMapper; private final DashboardApiClient dashboardApiClient; protected final DashboardNotificationsParamsMapper mapper; + private final GaForLipService gaForLipService; + private final ParentCaseUpdateHelper parentCaseUpdateHelper; @Override protected Map callbacks() { @@ -43,6 +49,13 @@ private CallbackResponse updateHWFDetailsAndSendNotification(CallbackParams call CaseData.CaseDataBuilder caseDataBuilder = HwFFeeTypeService.updateHwfDetails(caseData); String authToken = callbackParams.getParams().get(BEARER_TOKEN).toString(); HashMap paramsMap = mapper.mapCaseDataToParams(caseData); + if ((caseData.getGeneralAppPBADetails().getPaymentDetails() == null + || caseData.getGeneralAppPBADetails().getAdditionalPaymentDetails() == null) + && gaForLipService.isGaForLip(caseData) && Objects.nonNull(caseData.getGeneralAppHelpWithFees()) + && caseData.getGeneralAppHelpWithFees().getHelpWithFee().equals(YesOrNo.YES)) { + parentCaseUpdateHelper.updateMasterCollectionForHwf(caseData); + } + dashboardApiClient.recordScenario(caseData.getCcdCaseReference().toString(), DashboardScenarios.SCENARIO_AAA6_GENERAL_APPS_HWF_REQUESTED_APPLICANT.getScenario(), authToken, diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/businessprocess/EndGeneralAppBusinessProcessCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/businessprocess/EndGeneralAppBusinessProcessCallbackHandlerTest.java index 455a7f981..abe159e1e 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/businessprocess/EndGeneralAppBusinessProcessCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/businessprocess/EndGeneralAppBusinessProcessCallbackHandlerTest.java @@ -245,6 +245,333 @@ void shouldAddGaToJudgeCollectionPaymentThroughServiceRequestAndHwfIsNull() { assertThat(gaDetailsMasterCollection).hasSize(1); } + @Test + void shouldAddGaToJudgeCollectionPaymentThroughServiceRequestAndHwfIsNotNullAndIsRejected() { + CaseData updatedCaseDate = CaseData.builder() + .isGaApplicantLip(NO) + .isGaRespondentTwoLip(NO) + .isGaRespondentOneLip(NO) + .parentClaimantIsApplicant(YES) + .isMultiParty(NO) + .generalAppRespondentAgreement(GARespondentOrderAgreement.builder().hasAgreed(NO).build()) + .generalAppInformOtherParty(GAInformOtherParty.builder().isWithNotice(NO).build()) + .ccdState(AWAITING_APPLICATION_PAYMENT) + .ccdCaseReference(1234L) + .generalAppParentCaseLink(GeneralAppParentCaseLink.builder().caseReference("0000").build()) + .generalAppPBADetails(GAPbaDetails.builder().fee(Fee.builder().code("PAY").build()).paymentDetails( + PaymentDetails.builder().status(PaymentStatus.SUCCESS).build()).build()) + .generalAppHelpWithFees(HelpWithFees.builder().helpWithFee(YES).build()) + .build(); + + GeneralApplicationsDetails judgeCollection = GeneralApplicationsDetails.builder() + .build(); + GeneralApplicationsDetails claimantCollection = GeneralApplicationsDetails.builder() + .caseState("Awaiting Application Payment") + .caseLink(CaseLink.builder() + .caseReference("1234") + .build()) + .build(); + GADetailsRespondentSol respondentOneCollection = GADetailsRespondentSol.builder().build(); + + CaseData parentCaseData = CaseData.builder() + .claimantGaAppDetails(wrapElements(claimantCollection)) + .build(); + + when(coreCaseDataService.caseDataContentFromStartEventResponse(any(), anyMap())).thenCallRealMethod(); + when(gaForLipService.isGaForLip(any())).thenReturn(true); + when(caseDetailsConverter.toCaseData(getCallbackParamsGaForLipCaseData(NO).getRequest().getCaseDetails())) + .thenReturn(updatedCaseDate); + when(coreCaseDataService.startUpdate(any(), any())).thenReturn(getStartEventResponse()); + when(caseDetailsConverter.toCaseData(getStartEventResponse().getCaseDetails())).thenReturn(parentCaseData); + handler.handle(getCallbackParamsGaForLipCaseData(NO)); + verify(coreCaseDataService, times(2)) + .submitUpdate(parentCaseId.capture(), caseDataContent.capture()); + assertThat(caseDataContent.getAllValues()).hasSize(2); + + Map map = objectMapper + .convertValue(caseDataContent.getAllValues().get(0).getData(), + new TypeReference>() {}); + List gaDetailsMasterCollection = objectMapper.convertValue(map + .get("gaDetailsMasterCollection"), + new TypeReference<>(){}); + assertThat(gaDetailsMasterCollection).hasSize(1); + } + + @Test + void shouldAddGaToJudgeCollectionPaymentThroughServiceRequestAndHwfIsNotNullAndFeePaymentOutcome() { + List feePayment = new ArrayList<>(); + feePayment.add("yes"); + CaseData updatedCaseDate = CaseData.builder() + .isGaApplicantLip(YES) + .isGaRespondentTwoLip(NO) + .isGaRespondentOneLip(NO) + .parentClaimantIsApplicant(YES) + .isMultiParty(NO) + .generalAppRespondentAgreement(GARespondentOrderAgreement.builder().hasAgreed(NO).build()) + .generalAppInformOtherParty(GAInformOtherParty.builder().isWithNotice(NO).build()) + .ccdState(AWAITING_APPLICATION_PAYMENT) + .ccdCaseReference(1234L) + .generalAppParentCaseLink(GeneralAppParentCaseLink.builder().caseReference("0000").build()) + .generalAppPBADetails(GAPbaDetails.builder().fee(Fee.builder().code("PAY").build()).build()) + .feePaymentOutcomeDetails(FeePaymentOutcomeDetails.builder().hwfFullRemissionGrantedForGa(YES) + .hwfOutstandingFeePaymentDoneForGa(feePayment).build()) + .generalAppHelpWithFees(HelpWithFees.builder().helpWithFee(YES).build()) + .build(); + + GeneralApplicationsDetails judgeCollection = GeneralApplicationsDetails.builder() + .build(); + GeneralApplicationsDetails claimantCollection = GeneralApplicationsDetails.builder() + .caseState("Awaiting Application Payment") + .caseLink(CaseLink.builder() + .caseReference("1234") + .build()) + .build(); + GADetailsRespondentSol respondentOneCollection = GADetailsRespondentSol.builder().build(); + + CaseData parentCaseData = CaseData.builder() + .claimantGaAppDetails(wrapElements(claimantCollection)) + .build(); + + when(coreCaseDataService.caseDataContentFromStartEventResponse(any(), anyMap())).thenCallRealMethod(); + when(gaForLipService.isGaForLip(any())).thenReturn(true); + when(caseDetailsConverter.toCaseData(getCallbackParamsGaForLipCaseData(NO).getRequest().getCaseDetails())) + .thenReturn(updatedCaseDate); + when(coreCaseDataService.startUpdate(any(), any())).thenReturn(getStartEventResponse()); + when(caseDetailsConverter.toCaseData(getStartEventResponse().getCaseDetails())).thenReturn(parentCaseData); + handler.handle(getCallbackParamsGaForLipCaseData(NO)); + verify(coreCaseDataService, times(3)) + .submitUpdate(parentCaseId.capture(), caseDataContent.capture()); + assertThat(caseDataContent.getAllValues()).hasSize(3); + + Map map = objectMapper + .convertValue(caseDataContent.getAllValues().get(0).getData(), + new TypeReference>() {}); + List gaDetailsMasterCollection = objectMapper.convertValue(map + .get("gaDetailsMasterCollection"), + new TypeReference<>(){}); + assertThat(gaDetailsMasterCollection).hasSize(1); + } + + @Test + void shouldAddGaToJudgeCollectionPaymentThroughServiceRequestAndHwfIsNotNullAndFeePaymentOutcomeIsNullandNo() { + List feePayment = new ArrayList<>(); + feePayment.add("no"); + CaseData updatedCaseDate = CaseData.builder() + .isGaApplicantLip(YES) + .isGaRespondentTwoLip(NO) + .isGaRespondentOneLip(NO) + .parentClaimantIsApplicant(YES) + .isMultiParty(NO) + .generalAppRespondentAgreement(GARespondentOrderAgreement.builder().hasAgreed(NO).build()) + .generalAppInformOtherParty(GAInformOtherParty.builder().isWithNotice(NO).build()) + .ccdState(AWAITING_APPLICATION_PAYMENT) + .ccdCaseReference(1234L) + .generalAppParentCaseLink(GeneralAppParentCaseLink.builder().caseReference("0000").build()) + .generalAppPBADetails(GAPbaDetails.builder().fee(Fee.builder().code("PAY").build()) + .paymentDetails(PaymentDetails.builder().status(PaymentStatus.SUCCESS).build()).build()) + .feePaymentOutcomeDetails(FeePaymentOutcomeDetails.builder().hwfFullRemissionGrantedForGa(YES) + .hwfOutstandingFeePaymentDoneForGa(feePayment).build()) + .generalAppHelpWithFees(HelpWithFees.builder().helpWithFee(NO).build()) + .build(); + + GeneralApplicationsDetails judgeCollection = GeneralApplicationsDetails.builder() + .build(); + GeneralApplicationsDetails claimantCollection = GeneralApplicationsDetails.builder() + .caseState("Awaiting Application Payment") + .caseLink(CaseLink.builder() + .caseReference("1234") + .build()) + .build(); + GADetailsRespondentSol respondentOneCollection = GADetailsRespondentSol.builder().build(); + + CaseData parentCaseData = CaseData.builder() + .claimantGaAppDetails(wrapElements(claimantCollection)) + .build(); + + when(coreCaseDataService.caseDataContentFromStartEventResponse(any(), anyMap())).thenCallRealMethod(); + when(gaForLipService.isGaForLip(any())).thenReturn(true); + when(caseDetailsConverter.toCaseData(getCallbackParamsGaForLipCaseData(NO).getRequest().getCaseDetails())) + .thenReturn(updatedCaseDate); + when(coreCaseDataService.startUpdate(any(), any())).thenReturn(getStartEventResponse()); + when(caseDetailsConverter.toCaseData(getStartEventResponse().getCaseDetails())).thenReturn(parentCaseData); + handler.handle(getCallbackParamsGaForLipCaseData(NO)); + verify(coreCaseDataService, times(2)) + .submitUpdate(parentCaseId.capture(), caseDataContent.capture()); + assertThat(caseDataContent.getAllValues()).hasSize(2); + + Map map = objectMapper + .convertValue(caseDataContent.getAllValues().get(0).getData(), + new TypeReference>() {}); + List gaDetailsMasterCollection = objectMapper.convertValue(map + .get("gaDetailsMasterCollection"), + new TypeReference<>(){}); + assertThat(gaDetailsMasterCollection).hasSize(1); + } + + @Test + void shouldAddGaToJudgeCollectionPaymentThroughServiceRequestAndHwfIsNotNullAndFeePaymentOutcomeIsNullandYes() { + List feePayment = new ArrayList<>(); + feePayment.add("yes"); + CaseData updatedCaseDate = CaseData.builder() + .isGaApplicantLip(YES) + .isGaRespondentTwoLip(NO) + .isGaRespondentOneLip(NO) + .parentClaimantIsApplicant(YES) + .isMultiParty(NO) + .generalAppRespondentAgreement(GARespondentOrderAgreement.builder().hasAgreed(NO).build()) + .generalAppInformOtherParty(GAInformOtherParty.builder().isWithNotice(NO).build()) + .ccdState(AWAITING_APPLICATION_PAYMENT) + .ccdCaseReference(1234L) + .generalAppParentCaseLink(GeneralAppParentCaseLink.builder().caseReference("0000").build()) + .generalAppPBADetails(GAPbaDetails.builder().fee(Fee.builder().code("PAY").build()) + .build()) + .generalAppHelpWithFees(HelpWithFees.builder().helpWithFee(NO).build()) + .build(); + + GeneralApplicationsDetails judgeCollection = GeneralApplicationsDetails.builder() + .build(); + GeneralApplicationsDetails claimantCollection = GeneralApplicationsDetails.builder() + .caseState("Awaiting Application Payment") + .caseLink(CaseLink.builder() + .caseReference("1234") + .build()) + .build(); + GADetailsRespondentSol respondentOneCollection = GADetailsRespondentSol.builder().build(); + + CaseData parentCaseData = CaseData.builder() + .claimantGaAppDetails(wrapElements(claimantCollection)) + .build(); + + when(coreCaseDataService.caseDataContentFromStartEventResponse(any(), anyMap())).thenCallRealMethod(); + when(gaForLipService.isGaForLip(any())).thenReturn(true); + when(caseDetailsConverter.toCaseData(getCallbackParamsGaForLipCaseData(NO).getRequest().getCaseDetails())) + .thenReturn(updatedCaseDate); + when(coreCaseDataService.startUpdate(any(), any())).thenReturn(getStartEventResponse()); + when(caseDetailsConverter.toCaseData(getStartEventResponse().getCaseDetails())).thenReturn(parentCaseData); + handler.handle(getCallbackParamsGaForLipCaseData(NO)); + verify(coreCaseDataService, times(2)) + .submitUpdate(parentCaseId.capture(), caseDataContent.capture()); + assertThat(caseDataContent.getAllValues()).hasSize(2); + + Map map = objectMapper + .convertValue(caseDataContent.getAllValues().get(0).getData(), + new TypeReference>() {}); + List gaDetailsMasterCollection = objectMapper.convertValue(map + .get("gaDetailsMasterCollection"), + new TypeReference<>(){}); + assertThat(gaDetailsMasterCollection).hasSize(1); + } + + @Test + void shouldAddGaToJudgeCollectionPaymentThroughServiceRequestAndHwfIsNotNullAndFeePaymentOutcomeIsNull() { + List feePayment = new ArrayList<>(); + feePayment.add("yes"); + CaseData updatedCaseDate = CaseData.builder() + .isGaApplicantLip(YES) + .isGaRespondentTwoLip(NO) + .isGaRespondentOneLip(NO) + .parentClaimantIsApplicant(YES) + .isMultiParty(NO) + .generalAppRespondentAgreement(GARespondentOrderAgreement.builder().hasAgreed(NO).build()) + .generalAppInformOtherParty(GAInformOtherParty.builder().isWithNotice(NO).build()) + .ccdState(AWAITING_APPLICATION_PAYMENT) + .ccdCaseReference(1234L) + .generalAppParentCaseLink(GeneralAppParentCaseLink.builder().caseReference("0000").build()) + .generalAppPBADetails(GAPbaDetails.builder().fee(Fee.builder().code("PAY").build()).build()) + .feePaymentOutcomeDetails(FeePaymentOutcomeDetails.builder().hwfFullRemissionGrantedForGa(NO) + .hwfOutstandingFeePaymentDoneForGa(feePayment).build()) + .generalAppHelpWithFees(HelpWithFees.builder().helpWithFee(YES).build()) + .build(); + + GeneralApplicationsDetails judgeCollection = GeneralApplicationsDetails.builder() + .build(); + GeneralApplicationsDetails claimantCollection = GeneralApplicationsDetails.builder() + .caseState("Awaiting Application Payment") + .caseLink(CaseLink.builder() + .caseReference("1234") + .build()) + .build(); + GADetailsRespondentSol respondentOneCollection = GADetailsRespondentSol.builder().build(); + + CaseData parentCaseData = CaseData.builder() + .claimantGaAppDetails(wrapElements(claimantCollection)) + .build(); + + when(coreCaseDataService.caseDataContentFromStartEventResponse(any(), anyMap())).thenCallRealMethod(); + when(gaForLipService.isGaForLip(any())).thenReturn(true); + when(caseDetailsConverter.toCaseData(getCallbackParamsGaForLipCaseData(NO).getRequest().getCaseDetails())) + .thenReturn(updatedCaseDate); + when(coreCaseDataService.startUpdate(any(), any())).thenReturn(getStartEventResponse()); + when(caseDetailsConverter.toCaseData(getStartEventResponse().getCaseDetails())).thenReturn(parentCaseData); + handler.handle(getCallbackParamsGaForLipCaseData(NO)); + verify(coreCaseDataService, times(2)) + .submitUpdate(parentCaseId.capture(), caseDataContent.capture()); + assertThat(caseDataContent.getAllValues()).hasSize(2); + + Map map = objectMapper + .convertValue(caseDataContent.getAllValues().get(0).getData(), + new TypeReference>() {}); + List gaDetailsMasterCollection = objectMapper.convertValue(map + .get("gaDetailsMasterCollection"), + new TypeReference<>(){}); + assertThat(gaDetailsMasterCollection).hasSize(1); + } + + @Test + void shouldAddGaToJudgeCollectionPaymentThroughServiceRequestAndHwfIsNotNullAndFeePaymentOutcomeIsGranted() { + List feePayment = new ArrayList<>(); + feePayment.add("no"); + CaseData updatedCaseDate = CaseData.builder() + .isGaApplicantLip(YES) + .isGaRespondentTwoLip(NO) + .isGaRespondentOneLip(NO) + .parentClaimantIsApplicant(YES) + .isMultiParty(NO) + .generalAppRespondentAgreement(GARespondentOrderAgreement.builder().hasAgreed(NO).build()) + .generalAppInformOtherParty(GAInformOtherParty.builder().isWithNotice(NO).build()) + .ccdState(AWAITING_APPLICATION_PAYMENT) + .ccdCaseReference(1234L) + .generalAppParentCaseLink(GeneralAppParentCaseLink.builder().caseReference("0000").build()) + .generalAppPBADetails(GAPbaDetails.builder().fee(Fee.builder().code("PAY").build()).build()) + .feePaymentOutcomeDetails(FeePaymentOutcomeDetails.builder().hwfFullRemissionGrantedForGa(NO) + .hwfOutstandingFeePaymentDoneForGa(feePayment).build()) + .generalAppHelpWithFees(HelpWithFees.builder().helpWithFee(YES).build()) + .build(); + + GeneralApplicationsDetails judgeCollection = GeneralApplicationsDetails.builder() + .build(); + GeneralApplicationsDetails claimantCollection = GeneralApplicationsDetails.builder() + .caseState("Awaiting Application Payment") + .caseLink(CaseLink.builder() + .caseReference("1234") + .build()) + .build(); + GADetailsRespondentSol respondentOneCollection = GADetailsRespondentSol.builder().build(); + + CaseData parentCaseData = CaseData.builder() + .claimantGaAppDetails(wrapElements(claimantCollection)) + .build(); + + when(coreCaseDataService.caseDataContentFromStartEventResponse(any(), anyMap())).thenCallRealMethod(); + when(gaForLipService.isGaForLip(any())).thenReturn(true); + when(caseDetailsConverter.toCaseData(getCallbackParamsGaForLipCaseData(NO).getRequest().getCaseDetails())) + .thenReturn(updatedCaseDate); + when(coreCaseDataService.startUpdate(any(), any())).thenReturn(getStartEventResponse()); + when(caseDetailsConverter.toCaseData(getStartEventResponse().getCaseDetails())).thenReturn(parentCaseData); + handler.handle(getCallbackParamsGaForLipCaseData(NO)); + verify(coreCaseDataService, times(2)) + .submitUpdate(parentCaseId.capture(), caseDataContent.capture()); + assertThat(caseDataContent.getAllValues()).hasSize(2); + + Map map = objectMapper + .convertValue(caseDataContent.getAllValues().get(0).getData(), + new TypeReference>() {}); + List gaDetailsMasterCollection = objectMapper.convertValue(map + .get("gaDetailsMasterCollection"), + new TypeReference<>(){}); + assertThat(gaDetailsMasterCollection).hasSize(1); + } + @Test void shouldAddGaToJudgeCollectionPaymentThroughServiceRequest() { CaseData updatedCaseDate = CaseData.builder() diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/ApplyForHwFDashboardNotificationHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/ApplyForHwFDashboardNotificationHandlerTest.java index 182c74a64..6efd64c60 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/ApplyForHwFDashboardNotificationHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/dashboardnotifications/ApplyForHwFDashboardNotificationHandlerTest.java @@ -14,15 +14,20 @@ import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.client.DashboardApiClient; import uk.gov.hmcts.reform.civil.enums.CaseState; +import uk.gov.hmcts.reform.civil.enums.PaymentStatus; import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.enums.dq.GeneralApplicationTypes; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.PaymentDetails; import uk.gov.hmcts.reform.civil.model.citizenui.HelpWithFees; import uk.gov.hmcts.reform.civil.model.genapplication.GAApplicationType; +import uk.gov.hmcts.reform.civil.model.genapplication.GAPbaDetails; import uk.gov.hmcts.reform.civil.sampledata.CallbackParamsBuilder; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.service.DashboardNotificationsParamsMapper; +import uk.gov.hmcts.reform.civil.service.GaForLipService; +import uk.gov.hmcts.reform.civil.service.ParentCaseUpdateHelper; import uk.gov.hmcts.reform.dashboard.data.ScenarioRequestParams; import java.util.HashMap; @@ -37,12 +42,17 @@ import static uk.gov.hmcts.reform.civil.handler.callback.camunda.dashboardnotifications.DashboardScenarios.SCENARIO_AAA6_GENERAL_APPS_HWF_REQUESTED_APPLICANT; @ExtendWith(MockitoExtension.class) -public class ApplyForHwFDashboardNotificationHandlerTest extends BaseCallbackHandlerTest { +class ApplyForHwFDashboardNotificationHandlerTest extends BaseCallbackHandlerTest { @Mock private DashboardApiClient dashboardApiClient; @Mock private DashboardNotificationsParamsMapper mapper; + @Mock + private GaForLipService gaForLipService; + @Mock + private ParentCaseUpdateHelper parentCaseUpdateHelper; + @InjectMocks private ApplyForHwFDashboardNotificationHandler handler; @MockBean @@ -66,16 +76,21 @@ class AboutToSubmitCallback { void setup() { objectMapper = new ObjectMapper(); objectMapper.findAndRegisterModules(); - handler = new ApplyForHwFDashboardNotificationHandler(objectMapper, dashboardApiClient, mapper); + handler = new ApplyForHwFDashboardNotificationHandler(objectMapper, dashboardApiClient, mapper, gaForLipService, parentCaseUpdateHelper); } @Test void shouldRecordApplicantScenario_ApplyForHwF_whenInvoked() { + + when(gaForLipService.isGaForLip(any())).thenReturn(true); + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().withNoticeCaseData(); caseData = caseData.toBuilder() .generalAppType(GAApplicationType.builder().types(List.of(GeneralApplicationTypes.VARY_ORDER)) .build()) - .generalAppHelpWithFees(HelpWithFees.builder().helpWithFeesReferenceNumber("HWF-234-456").build()) + .generalAppPBADetails(GAPbaDetails.builder().build()) + .generalAppHelpWithFees(HelpWithFees.builder().helpWithFee(YesOrNo.YES) + .helpWithFeesReferenceNumber("HWF-234-456").build()) .ccdState(CaseState.AWAITING_APPLICATION_PAYMENT) .isGaApplicantLip(YesOrNo.YES) .build(); @@ -102,6 +117,108 @@ void shouldRecordApplicantScenario_ApplyForHwF_whenInvoked() { ); } + @Test + void shouldRecordApplicantScenario_ApplyForHwF_whenInvoked_gaLipIsFalse() { + + when(gaForLipService.isGaForLip(any())).thenReturn(false); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().withNoticeCaseData(); + caseData = caseData.toBuilder() + .generalAppType(GAApplicationType.builder().types(List.of(GeneralApplicationTypes.VARY_ORDER)) + .build()) + .generalAppPBADetails(GAPbaDetails.builder().build()) + .generalAppHelpWithFees(HelpWithFees.builder().helpWithFee(YesOrNo.YES).build()) + .ccdState(CaseState.AWAITING_APPLICATION_PAYMENT) + .isGaApplicantLip(YesOrNo.YES) + .build(); + + HashMap scenarioParams = new HashMap<>(); + + when(mapper.mapCaseDataToParams(any())).thenReturn(scenarioParams); + + CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( + CallbackRequest.builder().eventId(NOTIFY_HELP_WITH_FEE.name()) + .build() + ).build(); + + handler.handle(params); + verify(dashboardApiClient).recordScenario( + caseData.getCcdCaseReference().toString(), + SCENARIO_AAA6_GENERAL_APPS_HWF_REQUESTED_APPLICANT.getScenario(), + "BEARER_TOKEN", + ScenarioRequestParams.builder().params(scenarioParams).build() + ); + } + + @Test + void shouldRecordApplicantScenario_ApplyForHwF_whenInvoked_gaLipIsTrueAnndWithAdditionalDetails() { + + when(gaForLipService.isGaForLip(any())).thenReturn(true); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().withNoticeCaseData(); + caseData = caseData.toBuilder() + .generalAppType(GAApplicationType.builder().types(List.of(GeneralApplicationTypes.VARY_ORDER)) + .build()) + .generalAppPBADetails(GAPbaDetails.builder().additionalPaymentDetails(PaymentDetails.builder() + .status(PaymentStatus.SUCCESS) + .build()).build()) + .generalAppHelpWithFees(HelpWithFees.builder().helpWithFee(YesOrNo.NO).build()) + .ccdState(CaseState.APPLICATION_ADD_PAYMENT) + .isGaApplicantLip(YesOrNo.YES) + .build(); + + HashMap scenarioParams = new HashMap<>(); + + when(mapper.mapCaseDataToParams(any())).thenReturn(scenarioParams); + + CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( + CallbackRequest.builder().eventId(NOTIFY_HELP_WITH_FEE.name()) + .build() + ).build(); + + handler.handle(params); + verify(dashboardApiClient).recordScenario( + caseData.getCcdCaseReference().toString(), + SCENARIO_AAA6_GENERAL_APPS_HWF_REQUESTED_APPLICANT.getScenario(), + "BEARER_TOKEN", + ScenarioRequestParams.builder().params(scenarioParams).build() + ); + } + + @Test + void shouldRecordApplicantScenario_ApplyForHwF_whenInvoked_for_additional() { + + when(gaForLipService.isGaForLip(any())).thenReturn(true); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().withNoticeCaseData(); + caseData = caseData.toBuilder() + .generalAppType(GAApplicationType.builder().types(List.of(GeneralApplicationTypes.VARY_ORDER)) + .build()) + .generalAppPBADetails(GAPbaDetails.builder().paymentDetails(PaymentDetails.builder().status( + PaymentStatus.SUCCESS).build()).build()) + .generalAppHelpWithFees(HelpWithFees.builder().helpWithFee(YesOrNo.YES).build()) + .ccdState(CaseState.APPLICATION_ADD_PAYMENT) + .isGaApplicantLip(YesOrNo.YES) + .build(); + + HashMap scenarioParams = new HashMap<>(); + + when(mapper.mapCaseDataToParams(any())).thenReturn(scenarioParams); + + CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( + CallbackRequest.builder().eventId(NOTIFY_HELP_WITH_FEE.name()) + .build() + ).build(); + + handler.handle(params); + verify(dashboardApiClient).recordScenario( + caseData.getCcdCaseReference().toString(), + SCENARIO_AAA6_GENERAL_APPS_HWF_REQUESTED_APPLICANT.getScenario(), + "BEARER_TOKEN", + ScenarioRequestParams.builder().params(scenarioParams).build() + ); + } + @Test void shouldRecordApplicantScenario_ApplyForHwFAdditionalApplicationFee_whenInvoked() { CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().withNoticeCaseData();