diff --git a/src/main/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerHwfApplicationAccepted.java b/src/main/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerHwfApplicationAccepted.java index 585e67467bd..ac8069cfe33 100644 --- a/src/main/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerHwfApplicationAccepted.java +++ b/src/main/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerHwfApplicationAccepted.java @@ -7,10 +7,13 @@ import uk.gov.hmcts.ccd.sdk.api.CaseDetails; import uk.gov.hmcts.ccd.sdk.api.ConfigBuilder; import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse; +import uk.gov.hmcts.ccd.sdk.type.YesOrNo; +import uk.gov.hmcts.divorce.caseworker.service.CaseFlagsService; import uk.gov.hmcts.divorce.common.ccd.PageBuilder; import uk.gov.hmcts.divorce.divorcecase.model.CaseData; import uk.gov.hmcts.divorce.divorcecase.model.State; import uk.gov.hmcts.divorce.divorcecase.model.UserRole; +import uk.gov.hmcts.reform.ccd.client.model.SubmittedCallbackResponse; import static uk.gov.hmcts.divorce.divorcecase.model.State.AwaitingDocuments; import static uk.gov.hmcts.divorce.divorcecase.model.State.AwaitingHWFDecision; @@ -34,6 +37,7 @@ public class CaseworkerHwfApplicationAccepted implements CCDConfig configBuilder) { @@ -52,6 +56,7 @@ public void configure(final ConfigBuilder configBuild .name("HWF application accepted") .description("HWF application accepted") .aboutToSubmitCallback(this::aboutToSubmit) + .submittedCallback(this::submitted) .showEventNotes() .grant(CREATE_READ_UPDATE, CASE_WORKER) .grantHistoryOnly(SOLICITOR, SUPER_USER, LEGAL_ADVISOR, JUDGE)); @@ -62,13 +67,22 @@ public AboutToStartOrSubmitResponse aboutToSubmit( log.info("{} about to submit callback invoked for Case Id: {}", CASEWORKER_HWF_APPLICATION_ACCEPTED, details.getId()); CaseData caseData = details.getData(); + caseData.setCaseFlagsSetupComplete(YesOrNo.YES); + details.setState(caseworkerHwfApplicationAndPaymentHelper.getState(caseData)); details.setData(caseworkerHwfApplicationAndPaymentHelper.setDateSubmittedAndDueDate(caseData)); caseworkerHwfApplicationAndPaymentHelper.setRequiredCaseFieldsForPostSubmissionCase(details); - + return AboutToStartOrSubmitResponse.builder() .data(details.getData()) .state(details.getState()) .build(); } + + public SubmittedCallbackResponse submitted(final CaseDetails details, + final CaseDetails beforeDetails) { + log.info("{} submitted callback invoked CaseID: {}", CASEWORKER_HWF_APPLICATION_ACCEPTED, details.getId()); + caseFlagsService.setSupplementaryDataForCaseFlags(details.getId()); + return SubmittedCallbackResponse.builder().build(); + } } diff --git a/src/main/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerProgressPaperCase.java b/src/main/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerProgressPaperCase.java index 631a42fe018..107ebcfd64f 100644 --- a/src/main/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerProgressPaperCase.java +++ b/src/main/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerProgressPaperCase.java @@ -7,12 +7,15 @@ import uk.gov.hmcts.ccd.sdk.api.CaseDetails; import uk.gov.hmcts.ccd.sdk.api.ConfigBuilder; import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse; +import uk.gov.hmcts.ccd.sdk.type.YesOrNo; +import uk.gov.hmcts.divorce.caseworker.service.CaseFlagsService; import uk.gov.hmcts.divorce.common.ccd.PageBuilder; import uk.gov.hmcts.divorce.common.service.task.SetDefaultOrganisationPolicies; import uk.gov.hmcts.divorce.divorcecase.model.Application; import uk.gov.hmcts.divorce.divorcecase.model.CaseData; import uk.gov.hmcts.divorce.divorcecase.model.State; import uk.gov.hmcts.divorce.divorcecase.model.UserRole; +import uk.gov.hmcts.reform.ccd.client.model.SubmittedCallbackResponse; import java.util.List; @@ -40,6 +43,9 @@ public class CaseworkerProgressPaperCase implements CCDConfig configBuild .showEventNotes() .showSummary() .aboutToSubmitCallback(this::aboutToSubmit) + .submittedCallback(this::submitted) .grant(CREATE_READ_UPDATE, CASE_WORKER) .grant(CREATE_READ_UPDATE_DELETE, @@ -84,6 +91,8 @@ public AboutToStartOrSubmitResponse aboutToSubmit(CaseDetails result = caseTasks(setDefaultOrganisationPolicies).run(details); @@ -108,4 +117,11 @@ public AboutToStartOrSubmitResponse aboutToSubmit(CaseDetails details, + final CaseDetails beforeDetails) { + log.info("Add payment submitted callback invoked CaseID: {}", details.getId()); + caseFlagsService.setSupplementaryDataForCaseFlags(details.getId()); + return SubmittedCallbackResponse.builder().build(); + } } diff --git a/src/main/java/uk/gov/hmcts/divorce/caseworker/service/CaseFlagsService.java b/src/main/java/uk/gov/hmcts/divorce/caseworker/service/CaseFlagsService.java new file mode 100644 index 00000000000..24c9b167427 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/divorce/caseworker/service/CaseFlagsService.java @@ -0,0 +1,30 @@ +package uk.gov.hmcts.divorce.caseworker.service; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.divorce.idam.IdamService; +import uk.gov.hmcts.divorce.systemupdate.service.CcdUpdateService; +import uk.gov.hmcts.reform.authorisation.generators.AuthTokenGenerator; + +@Service +@RequiredArgsConstructor +@Slf4j +public class CaseFlagsService { + + private final CcdUpdateService ccdUpdateService; + private final IdamService idamService; + private final AuthTokenGenerator authTokenGenerator; + + public void setSupplementaryDataForCaseFlags(Long caseId) { + + String sysUserToken = idamService.retrieveSystemUpdateUserDetails().getAuthToken(); + String s2sToken = authTokenGenerator.generate(); + + ccdUpdateService.submitSupplementaryDataToCcdForServiceID( + caseId.toString(), + sysUserToken, + s2sToken + ); + } +} diff --git a/src/main/java/uk/gov/hmcts/divorce/citizen/event/CitizenPaymentMade.java b/src/main/java/uk/gov/hmcts/divorce/citizen/event/CitizenPaymentMade.java index 452e331d23f..581b01bfd21 100644 --- a/src/main/java/uk/gov/hmcts/divorce/citizen/event/CitizenPaymentMade.java +++ b/src/main/java/uk/gov/hmcts/divorce/citizen/event/CitizenPaymentMade.java @@ -8,11 +8,13 @@ import uk.gov.hmcts.ccd.sdk.api.CaseDetails; import uk.gov.hmcts.ccd.sdk.api.ConfigBuilder; import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse; +import uk.gov.hmcts.divorce.caseworker.service.CaseFlagsService; import uk.gov.hmcts.divorce.common.service.PaymentValidatorService; import uk.gov.hmcts.divorce.common.service.SubmissionService; import uk.gov.hmcts.divorce.divorcecase.model.CaseData; import uk.gov.hmcts.divorce.divorcecase.model.State; import uk.gov.hmcts.divorce.divorcecase.model.UserRole; +import uk.gov.hmcts.reform.ccd.client.model.SubmittedCallbackResponse; import java.util.List; @@ -36,6 +38,8 @@ public class CitizenPaymentMade implements CCDConfig public static final String CITIZEN_PAYMENT_MADE = "citizen-payment-made"; + private final CaseFlagsService caseFlagsService; + private final SubmissionService submissionService; private final PaymentValidatorService paymentValidatorService; @@ -51,7 +55,8 @@ public void configure(final ConfigBuilder configBuild .retries(120, 120) .grant(CREATE_READ_UPDATE, CITIZEN, SYSTEMUPDATE) .grantHistoryOnly(SUPER_USER, CASE_WORKER, LEGAL_ADVISOR) - .aboutToSubmitCallback(this::aboutToSubmit); + .aboutToSubmitCallback(this::aboutToSubmit) + .submittedCallback(this::submitted); } public AboutToStartOrSubmitResponse aboutToSubmit(final CaseDetails details, @@ -97,5 +102,12 @@ public AboutToStartOrSubmitResponse aboutToSubmit(final CaseDet .state(updatedCaseDetails.getState()) .build(); } + + public SubmittedCallbackResponse submitted(final CaseDetails details, + final CaseDetails beforeDetails) { + log.info("Add payment submitted callback invoked CaseID: {}", details.getId()); + caseFlagsService.setSupplementaryDataForCaseFlags(details.getId()); + return SubmittedCallbackResponse.builder().build(); + } } diff --git a/src/main/java/uk/gov/hmcts/divorce/citizen/event/CitizenSubmitApplication.java b/src/main/java/uk/gov/hmcts/divorce/citizen/event/CitizenSubmitApplication.java index 496aa9a49ab..e4b737fe90d 100644 --- a/src/main/java/uk/gov/hmcts/divorce/citizen/event/CitizenSubmitApplication.java +++ b/src/main/java/uk/gov/hmcts/divorce/citizen/event/CitizenSubmitApplication.java @@ -8,12 +8,15 @@ import uk.gov.hmcts.ccd.sdk.api.ConfigBuilder; import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse; import uk.gov.hmcts.ccd.sdk.type.OrderSummary; +import uk.gov.hmcts.divorce.caseworker.service.CaseFlagsService; import uk.gov.hmcts.divorce.common.service.SubmissionService; import uk.gov.hmcts.divorce.divorcecase.model.Application; import uk.gov.hmcts.divorce.divorcecase.model.CaseData; import uk.gov.hmcts.divorce.divorcecase.model.State; import uk.gov.hmcts.divorce.divorcecase.model.UserRole; import uk.gov.hmcts.divorce.payment.PaymentSetupService; +import uk.gov.hmcts.divorce.systemupdate.service.CcdUpdateService; +import uk.gov.hmcts.reform.ccd.client.model.SubmittedCallbackResponse; import java.util.List; @@ -41,6 +44,12 @@ public class CitizenSubmitApplication implements CCDConfig configBuilder) { @@ -53,7 +62,8 @@ public void configure(final ConfigBuilder configBuild .retries(120, 120) .grant(CREATE_READ_UPDATE, CITIZEN) .grantHistoryOnly(CASE_WORKER, SUPER_USER, LEGAL_ADVISOR, JUDGE) - .aboutToSubmitCallback(this::aboutToSubmit); + .aboutToSubmitCallback(this::aboutToSubmit) + .submittedCallback(this::submitted); } public AboutToStartOrSubmitResponse aboutToSubmit(CaseDetails details, @@ -102,6 +112,14 @@ public AboutToStartOrSubmitResponse aboutToSubmit(CaseDetails details, + final CaseDetails beforeDetails) { + log.info("{} submitted callback invoked CaseID: {}", CITIZEN_SUBMIT, details.getId()); + caseFlagsService.setSupplementaryDataForCaseFlags(details.getId()); + + return SubmittedCallbackResponse.builder().build(); + } + public void prepareCaseDataForApplicationPayment(CaseData data, long caseId, String redirectUrl) { Application application = data.getApplication(); diff --git a/src/main/java/uk/gov/hmcts/divorce/common/service/SubmissionService.java b/src/main/java/uk/gov/hmcts/divorce/common/service/SubmissionService.java index 52c6dc6c2a8..1def1c71711 100644 --- a/src/main/java/uk/gov/hmcts/divorce/common/service/SubmissionService.java +++ b/src/main/java/uk/gov/hmcts/divorce/common/service/SubmissionService.java @@ -6,6 +6,7 @@ import uk.gov.hmcts.divorce.common.service.task.SendSubmissionNotifications; import uk.gov.hmcts.divorce.common.service.task.SetApplicant2Email; import uk.gov.hmcts.divorce.common.service.task.SetApplicantOfflineStatus; +import uk.gov.hmcts.divorce.common.service.task.SetCaseFlagsSetupStatus; import uk.gov.hmcts.divorce.common.service.task.SetDateSubmitted; import uk.gov.hmcts.divorce.common.service.task.SetDefaultOrganisationPolicies; import uk.gov.hmcts.divorce.common.service.task.SetStateAfterSubmission; @@ -34,6 +35,9 @@ public class SubmissionService { @Autowired private SetDefaultOrganisationPolicies setDefaultOrganisationPolicies; + @Autowired + private SetCaseFlagsSetupStatus setCaseFlagsSetupStatus; + public CaseDetails submitApplication(final CaseDetails caseDetails) { return CaseTaskRunner.caseTasks( @@ -42,7 +46,8 @@ public CaseDetails submitApplication(final CaseDetails apply(final CaseDetails caseDetails) { + + final CaseData caseData = caseDetails.getData(); + caseData.setCaseFlagsSetupComplete(YES); + + return caseDetails; + } +} diff --git a/src/main/java/uk/gov/hmcts/divorce/divorcecase/model/CaseData.java b/src/main/java/uk/gov/hmcts/divorce/divorcecase/model/CaseData.java index ca6966206f7..c72d956d2e1 100644 --- a/src/main/java/uk/gov/hmcts/divorce/divorcecase/model/CaseData.java +++ b/src/main/java/uk/gov/hmcts/divorce/divorcecase/model/CaseData.java @@ -192,6 +192,11 @@ public class CaseData { ) private YesOrNo isJudicialSeparation; + @CCD( + access = {DefaultAccess.class} + ) + private YesOrNo caseFlagsSetupComplete; + @CCD( label = "Previous Service Applications", typeOverride = Collection, diff --git a/src/main/java/uk/gov/hmcts/divorce/solicitor/event/SolicitorSubmitApplication.java b/src/main/java/uk/gov/hmcts/divorce/solicitor/event/SolicitorSubmitApplication.java index 41a94278e27..32858f86348 100644 --- a/src/main/java/uk/gov/hmcts/divorce/solicitor/event/SolicitorSubmitApplication.java +++ b/src/main/java/uk/gov/hmcts/divorce/solicitor/event/SolicitorSubmitApplication.java @@ -8,6 +8,7 @@ import uk.gov.hmcts.ccd.sdk.api.ConfigBuilder; import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse; import uk.gov.hmcts.ccd.sdk.type.OrderSummary; +import uk.gov.hmcts.divorce.caseworker.service.CaseFlagsService; import uk.gov.hmcts.divorce.common.ccd.CcdPageConfiguration; import uk.gov.hmcts.divorce.common.ccd.PageBuilder; import uk.gov.hmcts.divorce.common.service.SubmissionService; @@ -23,6 +24,7 @@ import uk.gov.hmcts.divorce.solicitor.event.page.SolPayment; import uk.gov.hmcts.divorce.solicitor.event.page.SolPaymentSummary; import uk.gov.hmcts.divorce.solicitor.event.page.SolStatementOfTruth; +import uk.gov.hmcts.reform.ccd.client.model.SubmittedCallbackResponse; import java.math.BigDecimal; import java.text.NumberFormat; @@ -55,6 +57,7 @@ public class SolicitorSubmitApplication implements CCDConfig configBuilder) { @@ -174,6 +177,13 @@ public AboutToStartOrSubmitResponse aboutToSubmit(final CaseDet .build(); } + public SubmittedCallbackResponse submitted(final CaseDetails details, + final CaseDetails beforeDetails) { + log.info("{} submitted callback invoked CaseID: {}", SOLICITOR_SUBMIT, details.getId()); + caseFlagsService.setSupplementaryDataForCaseFlags(details.getId()); + return SubmittedCallbackResponse.builder().build(); + } + private void updateApplicant2DigitalDetails(CaseData caseData) { if (caseData.getApplicant2().getSolicitor() != null && caseData.getApplicant2().getSolicitor().getOrganisationPolicy() != null) { @@ -195,6 +205,7 @@ private PageBuilder addEventConfig(final ConfigBuilder>> supplementaryData = new HashMap<>(); + supplementaryData.put("supplementary_data_updates", + singletonMap(SET_OPERATION, + singletonMap(SERVICE_ID_FIELD, SERVICE_ID))); + submitSupplementaryDataUpdateToCcd(caseId, authorisation, serviceAuth, supplementaryData); + } + private void submitSupplementaryDataUpdateToCcd(final String caseId, final String authorisation, final String serviceAuth, diff --git a/src/test/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerHwfApplicationAcceptedTest.java b/src/test/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerHwfApplicationAcceptedTest.java index 7981a35a71c..08d645d294f 100644 --- a/src/test/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerHwfApplicationAcceptedTest.java +++ b/src/test/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerHwfApplicationAcceptedTest.java @@ -8,9 +8,12 @@ import uk.gov.hmcts.ccd.sdk.ConfigBuilderImpl; import uk.gov.hmcts.ccd.sdk.api.CaseDetails; import uk.gov.hmcts.ccd.sdk.api.Event; +import uk.gov.hmcts.ccd.sdk.type.YesOrNo; +import uk.gov.hmcts.divorce.caseworker.service.CaseFlagsService; import uk.gov.hmcts.divorce.divorcecase.model.CaseData; import uk.gov.hmcts.divorce.divorcecase.model.State; import uk.gov.hmcts.divorce.divorcecase.model.UserRole; +import uk.gov.hmcts.divorce.testutil.TestConstants; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verify; @@ -27,6 +30,9 @@ class CaseworkerHwfApplicationAcceptedTest { @Mock private CaseworkerHwfApplicationAndPaymentHelper caseworkerHwfApplicationAndPaymentHelper; + @Mock + private CaseFlagsService caseFlagsService; + @InjectMocks private CaseworkerHwfApplicationAccepted caseworkerHwfApplicationAccepted; @@ -66,4 +72,30 @@ void shouldSetDefaultCaseDataRequiredForPostSubmissionCases() { verify(caseworkerHwfApplicationAndPaymentHelper).setRequiredCaseFieldsForPostSubmissionCase(caseDetails); } + + @Test + void shouldSetCaseFlagsSetupStatusInAboutToSubmit() { + final CaseData caseData = caseData(); + final CaseDetails caseDetails = new CaseDetails<>(); + caseDetails.setData(caseData); + caseData.setCaseFlagsSetupComplete(YesOrNo.YES); + + when(caseworkerHwfApplicationAndPaymentHelper.setDateSubmittedAndDueDate(caseData)).thenReturn(caseData); + + var response = caseworkerHwfApplicationAccepted.aboutToSubmit(caseDetails, null); + + assertThat(response.getData().getCaseFlagsSetupComplete()).isEqualTo(YesOrNo.YES); + } + + @Test + void shouldCallCaseFlagsServiceToSetHmctsServiceId() { + final CaseData caseData = caseData(); + final CaseDetails caseDetails = new CaseDetails<>(); + caseDetails.setData(caseData); + caseDetails.setId(TestConstants.TEST_CASE_ID); + + caseworkerHwfApplicationAccepted.submitted(caseDetails, null); + + verify(caseFlagsService).setSupplementaryDataForCaseFlags(TestConstants.TEST_CASE_ID); + } } diff --git a/src/test/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerProgressPaperCaseTest.java b/src/test/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerProgressPaperCaseTest.java index c64d5a3c050..d1a769d7d4c 100644 --- a/src/test/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerProgressPaperCaseTest.java +++ b/src/test/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerProgressPaperCaseTest.java @@ -9,10 +9,13 @@ import uk.gov.hmcts.ccd.sdk.api.CaseDetails; import uk.gov.hmcts.ccd.sdk.api.Event; import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse; +import uk.gov.hmcts.ccd.sdk.type.YesOrNo; +import uk.gov.hmcts.divorce.caseworker.service.CaseFlagsService; import uk.gov.hmcts.divorce.common.service.task.SetDefaultOrganisationPolicies; import uk.gov.hmcts.divorce.divorcecase.model.CaseData; import uk.gov.hmcts.divorce.divorcecase.model.State; import uk.gov.hmcts.divorce.divorcecase.model.UserRole; +import uk.gov.hmcts.divorce.testutil.TestConstants; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verify; @@ -30,6 +33,7 @@ import static uk.gov.hmcts.divorce.testutil.ConfigTestUtil.createCaseDataConfigBuilder; import static uk.gov.hmcts.divorce.testutil.ConfigTestUtil.getEventsFrom; import static uk.gov.hmcts.divorce.testutil.TestConstants.TEST_CASE_ID; +import static uk.gov.hmcts.divorce.testutil.TestDataHelper.caseData; import static uk.gov.hmcts.divorce.testutil.TestDataHelper.validApplicant1CaseData; @ExtendWith(MockitoExtension.class) @@ -38,6 +42,9 @@ public class CaseworkerProgressPaperCaseTest { @Mock private SetDefaultOrganisationPolicies setDefaultOrganisationPolicies; + @Mock + private CaseFlagsService caseFlagsService; + @InjectMocks private CaseworkerProgressPaperCase caseworkerProgressPaperCase; @@ -146,4 +153,31 @@ void shouldReturnErrorsIfCaseDataIsNotReadyForProgression() { "JurisdictionConnections cannot be empty or null" ); } + + @Test + void shouldSetCaseFlagsSetupCompleteFlagInAboutToSubmit() { + final long caseId = TEST_CASE_ID; + final CaseDetails caseDetails = new CaseDetails<>(); + CaseData caseData = validApplicant1CaseData(); + caseData.getApplication().setProgressPaperCase(AWAITING_HWF_DECISION); + + caseDetails.setData(caseData); + caseDetails.setId(caseId); + + final AboutToStartOrSubmitResponse response = caseworkerProgressPaperCase.aboutToSubmit(caseDetails, caseDetails); + + assertThat(response.getData().getCaseFlagsSetupComplete()).isEqualTo(YesOrNo.YES); + } + + @Test + void shouldCallCaseFlagsServiceToSetHmctsServiceId() { + final CaseData caseData = caseData(); + final CaseDetails caseDetails = new CaseDetails<>(); + caseDetails.setData(caseData); + caseDetails.setId(TestConstants.TEST_CASE_ID); + + caseworkerProgressPaperCase.submitted(caseDetails, null); + + verify(caseFlagsService).setSupplementaryDataForCaseFlags(TestConstants.TEST_CASE_ID); + } } diff --git a/src/test/java/uk/gov/hmcts/divorce/caseworker/service/CaseFlagsServiceTest.java b/src/test/java/uk/gov/hmcts/divorce/caseworker/service/CaseFlagsServiceTest.java new file mode 100644 index 00000000000..d7053018752 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/divorce/caseworker/service/CaseFlagsServiceTest.java @@ -0,0 +1,48 @@ +package uk.gov.hmcts.divorce.caseworker.service; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import uk.gov.hmcts.divorce.idam.IdamService; +import uk.gov.hmcts.divorce.idam.User; +import uk.gov.hmcts.divorce.systemupdate.service.CcdUpdateService; +import uk.gov.hmcts.reform.authorisation.generators.AuthTokenGenerator; + +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static uk.gov.hmcts.divorce.testutil.TestConstants.SERVICE_AUTHORIZATION; +import static uk.gov.hmcts.divorce.testutil.TestConstants.TEST_CASE_ID; +import static uk.gov.hmcts.divorce.testutil.TestConstants.TEST_SERVICE_AUTH_TOKEN; + +@ExtendWith(MockitoExtension.class) +class CaseFlagsServiceTest { + + @Mock + private IdamService idamService; + + @Mock + private AuthTokenGenerator authTokenGenerator; + + @Mock + private CcdUpdateService ccdUpdateService; + + @InjectMocks + private CaseFlagsService caseFlagsService; + + @Test + void shouldSetSupplementaryDataForCaseFlags() { + + when(idamService.retrieveSystemUpdateUserDetails()).thenReturn(new User(TEST_SERVICE_AUTH_TOKEN, null)); + when(authTokenGenerator.generate()).thenReturn(SERVICE_AUTHORIZATION); + + caseFlagsService.setSupplementaryDataForCaseFlags(TEST_CASE_ID); + + verify(ccdUpdateService).submitSupplementaryDataToCcdForServiceID( + TEST_CASE_ID.toString(), + TEST_SERVICE_AUTH_TOKEN, + SERVICE_AUTHORIZATION + ); + } +} diff --git a/src/test/java/uk/gov/hmcts/divorce/citizen/event/CitizenPaymentMadeTest.java b/src/test/java/uk/gov/hmcts/divorce/citizen/event/CitizenPaymentMadeTest.java index bb1cfac2867..3296aba9bc1 100644 --- a/src/test/java/uk/gov/hmcts/divorce/citizen/event/CitizenPaymentMadeTest.java +++ b/src/test/java/uk/gov/hmcts/divorce/citizen/event/CitizenPaymentMadeTest.java @@ -11,6 +11,7 @@ import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse; import uk.gov.hmcts.ccd.sdk.type.ListValue; import uk.gov.hmcts.ccd.sdk.type.OrderSummary; +import uk.gov.hmcts.divorce.caseworker.service.CaseFlagsService; import uk.gov.hmcts.divorce.citizen.notification.ApplicationSubmittedNotification; import uk.gov.hmcts.divorce.common.service.PaymentValidatorService; import uk.gov.hmcts.divorce.common.service.SubmissionService; @@ -18,6 +19,7 @@ import uk.gov.hmcts.divorce.divorcecase.model.Payment; import uk.gov.hmcts.divorce.divorcecase.model.State; import uk.gov.hmcts.divorce.divorcecase.model.UserRole; +import uk.gov.hmcts.divorce.testutil.TestConstants; import java.util.Collections; import java.util.List; @@ -59,6 +61,9 @@ public class CitizenPaymentMadeTest { @Mock private PaymentValidatorService paymentValidatorService; + @Mock + private CaseFlagsService caseFlagsService; + @InjectMocks private CitizenPaymentMade citizenPaymentMade; @@ -191,4 +196,16 @@ void shouldSetStateAsAwaitingDocumentsWhenSoleCaseAndApplicantDoesNotKnowRespond assertThat(result.getState()).isSameAs(AwaitingDocuments); verify(submissionService).submitApplication(details); } + + @Test + void shouldCallCaseFlagsServiceToSetHmctsServiceId() { + final CaseData caseData = caseData(); + final CaseDetails caseDetails = new CaseDetails<>(); + caseDetails.setData(caseData); + caseDetails.setId(TestConstants.TEST_CASE_ID); + + citizenPaymentMade.submitted(caseDetails, null); + + verify(caseFlagsService).setSupplementaryDataForCaseFlags(TestConstants.TEST_CASE_ID); + } } diff --git a/src/test/java/uk/gov/hmcts/divorce/citizen/event/CitizenSubmitApplicationTest.java b/src/test/java/uk/gov/hmcts/divorce/citizen/event/CitizenSubmitApplicationTest.java index df2cc3f299e..8c8cfa90b1c 100644 --- a/src/test/java/uk/gov/hmcts/divorce/citizen/event/CitizenSubmitApplicationTest.java +++ b/src/test/java/uk/gov/hmcts/divorce/citizen/event/CitizenSubmitApplicationTest.java @@ -11,6 +11,7 @@ import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse; import uk.gov.hmcts.ccd.sdk.type.OrderSummary; import uk.gov.hmcts.ccd.sdk.type.YesOrNo; +import uk.gov.hmcts.divorce.caseworker.service.CaseFlagsService; import uk.gov.hmcts.divorce.common.service.SubmissionService; import uk.gov.hmcts.divorce.divorcecase.model.ApplicationType; import uk.gov.hmcts.divorce.divorcecase.model.CaseData; @@ -22,6 +23,7 @@ import uk.gov.hmcts.divorce.payment.PaymentService; import uk.gov.hmcts.divorce.payment.PaymentSetupService; import uk.gov.hmcts.divorce.solicitor.service.SolicitorSubmitJointApplicationService; +import uk.gov.hmcts.divorce.testutil.TestConstants; import java.time.LocalDate; import java.time.temporal.ChronoUnit; @@ -42,6 +44,7 @@ import static uk.gov.hmcts.divorce.testutil.ConfigTestUtil.getEventsFrom; import static uk.gov.hmcts.divorce.testutil.TestConstants.TEST_CASE_ID; import static uk.gov.hmcts.divorce.testutil.TestConstants.TEST_SERVICE_REFERENCE; +import static uk.gov.hmcts.divorce.testutil.TestDataHelper.caseData; import static uk.gov.hmcts.divorce.testutil.TestDataHelper.getApplicant; @ExtendWith(MockitoExtension.class) @@ -59,6 +62,9 @@ class CitizenSubmitApplicationTest { @Mock private SubmissionService submissionService; + @Mock + private CaseFlagsService caseFlagsService; + @InjectMocks private CitizenSubmitApplication citizenSubmitApplication; private OrderSummary orderSummary; @@ -228,6 +234,18 @@ public void givenEventStartedWithValidJointCaseThenChangeStateAwaitingHwfDecisio assertThat(response.getData().getApplication().getApplicationPayments()).isNull(); } + @Test + void shouldCallCaseFlagsServiceToSetHmctsServiceId() { + final CaseData caseData = caseData(); + final CaseDetails caseDetails = new CaseDetails<>(); + caseDetails.setData(caseData); + caseDetails.setId(TestConstants.TEST_CASE_ID); + + citizenSubmitApplication.submitted(caseDetails, null); + + verify(caseFlagsService).setSupplementaryDataForCaseFlags(TestConstants.TEST_CASE_ID); + } + private OrderSummary orderSummary() { return OrderSummary .builder() diff --git a/src/test/java/uk/gov/hmcts/divorce/common/service/SubmissionServiceTest.java b/src/test/java/uk/gov/hmcts/divorce/common/service/SubmissionServiceTest.java index 8ee4364a15e..41edcd0686b 100644 --- a/src/test/java/uk/gov/hmcts/divorce/common/service/SubmissionServiceTest.java +++ b/src/test/java/uk/gov/hmcts/divorce/common/service/SubmissionServiceTest.java @@ -9,6 +9,7 @@ import uk.gov.hmcts.divorce.common.service.task.SendSubmissionNotifications; import uk.gov.hmcts.divorce.common.service.task.SetApplicant2Email; import uk.gov.hmcts.divorce.common.service.task.SetApplicantOfflineStatus; +import uk.gov.hmcts.divorce.common.service.task.SetCaseFlagsSetupStatus; import uk.gov.hmcts.divorce.common.service.task.SetDateSubmitted; import uk.gov.hmcts.divorce.common.service.task.SetDefaultOrganisationPolicies; import uk.gov.hmcts.divorce.common.service.task.SetStateAfterSubmission; @@ -40,6 +41,9 @@ class SubmissionServiceTest { @Mock private SetDefaultOrganisationPolicies setDefaultOrganisationPolicies; + @Mock + private SetCaseFlagsSetupStatus setCaseFlagsSetupStatus; + @InjectMocks private SubmissionService submissionService; @@ -55,6 +59,7 @@ void shouldProcessSubmissionCaseTasks() { when(setApplicantOfflineStatus.apply(caseDetails)).thenReturn(caseDetails); when(setDefaultOrganisationPolicies.apply(caseDetails)).thenReturn(caseDetails); when(sendSubmissionNotifications.apply(caseDetails)).thenReturn(expectedCaseDetails); + when(setCaseFlagsSetupStatus.apply(caseDetails)).thenReturn(expectedCaseDetails); final CaseDetails result = submissionService.submitApplication(caseDetails); @@ -66,5 +71,6 @@ void shouldProcessSubmissionCaseTasks() { verify(setApplicantOfflineStatus).apply(caseDetails); verify(setDefaultOrganisationPolicies).apply(caseDetails); verify(sendSubmissionNotifications).apply(caseDetails); + verify(setCaseFlagsSetupStatus).apply(caseDetails); } } diff --git a/src/test/java/uk/gov/hmcts/divorce/common/service/task/SetCaseFlagsSetupStatusTest.java b/src/test/java/uk/gov/hmcts/divorce/common/service/task/SetCaseFlagsSetupStatusTest.java new file mode 100644 index 00000000000..fbdb3afbe7d --- /dev/null +++ b/src/test/java/uk/gov/hmcts/divorce/common/service/task/SetCaseFlagsSetupStatusTest.java @@ -0,0 +1,34 @@ +package uk.gov.hmcts.divorce.common.service.task; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.junit.jupiter.MockitoExtension; +import uk.gov.hmcts.ccd.sdk.api.CaseDetails; +import uk.gov.hmcts.divorce.divorcecase.model.CaseData; +import uk.gov.hmcts.divorce.divorcecase.model.State; + +import static org.assertj.core.api.Assertions.assertThat; +import static uk.gov.hmcts.ccd.sdk.type.YesOrNo.YES; +import static uk.gov.hmcts.divorce.testutil.TestConstants.TEST_CASE_ID; +import static uk.gov.hmcts.divorce.testutil.TestDataHelper.caseData; + +@ExtendWith(MockitoExtension.class) +class SetCaseFlagsSetupStatusTest { + + @InjectMocks + private SetCaseFlagsSetupStatus setCaseFlagsSetupStatus; + + @Test + void shouldSetCaseFlagsSetupStatus() { + + final CaseData caseData = caseData(); + final CaseDetails caseDetails = new CaseDetails<>(); + caseDetails.setId(TEST_CASE_ID); + caseDetails.setData(caseData); + + final CaseDetails result = setCaseFlagsSetupStatus.apply(caseDetails); + + assertThat(result.getData().getCaseFlagsSetupComplete()).isEqualTo(YES); + } +} diff --git a/src/test/java/uk/gov/hmcts/divorce/solicitor/event/SolicitorSubmitApplicationTest.java b/src/test/java/uk/gov/hmcts/divorce/solicitor/event/SolicitorSubmitApplicationTest.java index 6157112613b..df6790241ac 100644 --- a/src/test/java/uk/gov/hmcts/divorce/solicitor/event/SolicitorSubmitApplicationTest.java +++ b/src/test/java/uk/gov/hmcts/divorce/solicitor/event/SolicitorSubmitApplicationTest.java @@ -16,6 +16,7 @@ import uk.gov.hmcts.ccd.sdk.type.OrderSummary; import uk.gov.hmcts.ccd.sdk.type.Organisation; import uk.gov.hmcts.ccd.sdk.type.OrganisationPolicy; +import uk.gov.hmcts.divorce.caseworker.service.CaseFlagsService; import uk.gov.hmcts.divorce.common.service.SubmissionService; import uk.gov.hmcts.divorce.divorcecase.model.CaseData; import uk.gov.hmcts.divorce.divorcecase.model.HelpWithFees; @@ -28,6 +29,7 @@ import uk.gov.hmcts.divorce.payment.PaymentSetupService; import uk.gov.hmcts.divorce.payment.model.PbaResponse; import uk.gov.hmcts.divorce.solicitor.event.page.SolPayment; +import uk.gov.hmcts.divorce.testutil.TestConstants; import java.time.LocalDateTime; import java.util.ArrayList; @@ -37,6 +39,7 @@ import static java.lang.Integer.parseInt; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.FORBIDDEN; @@ -53,6 +56,7 @@ import static uk.gov.hmcts.divorce.testutil.TestConstants.TEST_ORG_ID; import static uk.gov.hmcts.divorce.testutil.TestConstants.TEST_ORG_NAME; import static uk.gov.hmcts.divorce.testutil.TestConstants.TEST_SERVICE_REFERENCE; +import static uk.gov.hmcts.divorce.testutil.TestDataHelper.caseData; import static uk.gov.hmcts.divorce.testutil.TestDataHelper.getFeeListValue; import static uk.gov.hmcts.divorce.testutil.TestDataHelper.validApplicant1CaseData; @@ -82,6 +86,9 @@ public class SolicitorSubmitApplicationTest { @Mock private SolPayment solPayment; + @Mock + private CaseFlagsService caseFlagsService; + @InjectMocks private SolicitorSubmitApplication solicitorSubmitApplication; @@ -505,6 +512,18 @@ void shouldReturnErrorMessageIfPaymentMethodIsPbaAndPbaNumberIsNotPresent() { .containsExactly("PBA number not present when payment method is 'Solicitor fee account (PBA)'"); } + @Test + void shouldCallCaseFlagsServiceToSetHmctsServiceId() { + final CaseData caseData = caseData(); + final CaseDetails caseDetails = new CaseDetails<>(); + caseDetails.setData(caseData); + caseDetails.setId(TestConstants.TEST_CASE_ID); + + solicitorSubmitApplication.submitted(caseDetails, null); + + verify(caseFlagsService).setSupplementaryDataForCaseFlags(TestConstants.TEST_CASE_ID); + } + private void mockExpectedCaseDetails(CaseDetails caseDetails, CaseData caseData, State state) { final CaseDetails expectedCaseDetails = new CaseDetails<>(); expectedCaseDetails.setData(caseData); diff --git a/src/test/java/uk/gov/hmcts/divorce/systemupdate/service/CcdUpdateServiceTest.java b/src/test/java/uk/gov/hmcts/divorce/systemupdate/service/CcdUpdateServiceTest.java index a16ca95b9cf..1a29a2e1029 100644 --- a/src/test/java/uk/gov/hmcts/divorce/systemupdate/service/CcdUpdateServiceTest.java +++ b/src/test/java/uk/gov/hmcts/divorce/systemupdate/service/CcdUpdateServiceTest.java @@ -237,6 +237,20 @@ public void shouldIncrementOrgsAssignedUsersSupplementaryDataOnCaseToNewValue() ); } + @Test + public void shouldSetSupplementaryDataForServiceIDInCCD() { + ccdUpdateService.submitSupplementaryDataToCcdForServiceID(TEST_CASE_ID.toString(), + CASEWORKER_AUTH_TOKEN, + SERVICE_AUTHORIZATION); + + verify(coreCaseDataApi).submitSupplementaryData( + CASEWORKER_AUTH_TOKEN, + SERVICE_AUTHORIZATION, + TEST_CASE_ID.toString(), + Map.of("supplementary_data_updates", Map.of("$set", singletonMap("HMCTSServiceId", "ABA1"))) + ); + } + private StartEventResponse getStartEventResponse() { return StartEventResponse.builder() .eventId(SYSTEM_PROGRESS_HELD_CASE)