diff --git a/Jenkinsfile_CNP b/Jenkinsfile_CNP index 28023fa77fc..9fc08c827b4 100644 --- a/Jenkinsfile_CNP +++ b/Jenkinsfile_CNP @@ -172,6 +172,7 @@ withPipeline(type, product, component) { env.CITIZEN_UPDATE_CASE_STATE_ENABLED=true env.SERVICE_AUTH_MICROSERVICE = "nfdiv_case_api" env.SERVICE_AUTH_PROVIDER_URL = "http://rpe-service-auth-provider-aat.service.core-compute-aat.internal" + env.CREATE_PAPER_CASE_MOCK_NOTIFICATION=true setCommonEnvVariables() } @@ -185,6 +186,7 @@ withPipeline(type, product, component) { env.ADMIN_UNLINK_APPLICANT_2_ENABLED=true env.SERVICE_AUTH_MICROSERVICE = "nfdiv_case_api" env.SERVICE_AUTH_PROVIDER_URL = "http://rpe-service-auth-provider-aat.service.core-compute-aat.internal" + env.CREATE_PAPER_CASE_MOCK_NOTIFICATION=true setCommonEnvVariables() } @@ -199,6 +201,7 @@ withPipeline(type, product, component) { env.IDAM_API_URL_BASE = "https://idam-api.platform.hmcts.net" env.S2S_URL_BASE = "http://rpe-service-auth-provider-prod.service.core-compute-prod.internal" env.BEFTA_S2S_CLIENT_ID = "ccd_data" + env.CREATE_PAPER_CASE_MOCK_NOTIFICATION=false // re-run to generate prod definition builder.gradle('generateCCDConfig --rerun-tasks') @@ -211,6 +214,7 @@ withPipeline(type, product, component) { env.CCD_DEF_NAME = "demo" env.IDAM_API_URL_BASE = "https://idam-api.demo.platform.hmcts.net" env.S2S_URL_BASE = "http://rpe-service-auth-provider-demo.service.core-compute-demo.internal" + env.CREATE_PAPER_CASE_MOCK_NOTIFICATION=true } onPerftest { diff --git a/build.gradle b/build.gradle index b440f4e2add..d3af38c6e99 100644 --- a/build.gradle +++ b/build.gradle @@ -431,6 +431,7 @@ bootWithCCD { environment 'ROLE_ASSIGNMENT_URL', 'http://localhost:4096' environment 'CASE_DATA_STORE_BASEURL', 'http://localhost:4452' environment 'XUI_MO_PORT', '3009' + environment 'CREATE_PAPER_CASE_MOCK_NOTIFICATION', 'true' } } diff --git a/src/main/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerCreatePaperCase.java b/src/main/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerCreatePaperCase.java index a170c92bd57..e4378e63a26 100644 --- a/src/main/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerCreatePaperCase.java +++ b/src/main/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerCreatePaperCase.java @@ -1,21 +1,25 @@ package uk.gov.hmcts.divorce.caseworker.event; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import uk.gov.hmcts.ccd.sdk.api.CCDConfig; 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.notification.PaperApplicationReceivedNotification; 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.divorce.notification.NotificationDispatcher; import static org.apache.commons.lang3.StringUtils.isBlank; import static uk.gov.hmcts.ccd.sdk.type.YesOrNo.NO; import static uk.gov.hmcts.ccd.sdk.type.YesOrNo.YES; import static uk.gov.hmcts.divorce.divorcecase.model.ApplicationType.JOINT_APPLICATION; import static uk.gov.hmcts.divorce.divorcecase.model.ApplicationType.SOLE_APPLICATION; +import static uk.gov.hmcts.divorce.divorcecase.model.DivorceOrDissolution.DIVORCE; import static uk.gov.hmcts.divorce.divorcecase.model.State.NewPaperCase; import static uk.gov.hmcts.divorce.divorcecase.model.UserRole.CASE_WORKER; import static uk.gov.hmcts.divorce.divorcecase.model.UserRole.CASE_WORKER_BULK_SCAN; @@ -30,6 +34,12 @@ public class CaseworkerCreatePaperCase implements CCDConfig configBuilder) { new PageBuilder(configBuilder @@ -62,6 +72,19 @@ public AboutToStartOrSubmitResponse aboutToSubmit(final CaseDet applicant2.setOffline(NO); } + final boolean mockNotification = Boolean.parseBoolean(System.getenv().get("CREATE_PAPER_CASE_MOCK_NOTIFICATION")); + final boolean notProd = !"prod".equalsIgnoreCase(System.getenv().get("ENVIRONMENT")); + if (notProd && mockNotification) { + if (data.getDivorceOrDissolution() == null) { + data.setDivorceOrDissolution(DIVORCE); + } + + if (data.getApplicationType() == null) { + data.setApplicationType(SOLE_APPLICATION); + } + } + notificationDispatcher.send(paperApplicationReceivedNotification, data, details.getId()); + return AboutToStartOrSubmitResponse.builder() .data(data) .build(); diff --git a/src/main/java/uk/gov/hmcts/divorce/caseworker/service/notification/PaperApplicationReceivedNotification.java b/src/main/java/uk/gov/hmcts/divorce/caseworker/service/notification/PaperApplicationReceivedNotification.java new file mode 100644 index 00000000000..bcfb8ed49e4 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/divorce/caseworker/service/notification/PaperApplicationReceivedNotification.java @@ -0,0 +1,111 @@ +package uk.gov.hmcts.divorce.caseworker.service.notification; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import uk.gov.hmcts.ccd.sdk.type.Document; +import uk.gov.hmcts.divorce.divorcecase.model.Applicant; +import uk.gov.hmcts.divorce.divorcecase.model.CaseData; +import uk.gov.hmcts.divorce.document.CaseDataDocumentService; +import uk.gov.hmcts.divorce.document.content.PaperApplicationReceivedTemplateContent; +import uk.gov.hmcts.divorce.document.model.ConfidentialDivorceDocument; +import uk.gov.hmcts.divorce.document.model.DivorceDocument; +import uk.gov.hmcts.divorce.document.print.BulkPrintService; +import uk.gov.hmcts.divorce.document.print.model.Letter; +import uk.gov.hmcts.divorce.document.print.model.Print; +import uk.gov.hmcts.divorce.notification.ApplicantNotification; + +import java.util.List; +import java.util.UUID; + +import static uk.gov.hmcts.divorce.divorcecase.model.CaseDocuments.addDocumentToTop; +import static uk.gov.hmcts.divorce.document.DocumentConstants.PAPER_APPLICATION_RECEIVED_TEMPLATE_ID; +import static uk.gov.hmcts.divorce.document.model.ConfidentialDocumentsReceived.PAPER_APPLICATION_RECEIVED_CONFIDENTIAL_LETTER; +import static uk.gov.hmcts.divorce.document.model.DocumentType.PAPER_APPLICATION_RECEIVED_LETTER; + +@Component +@RequiredArgsConstructor +@Slf4j +public class PaperApplicationReceivedNotification implements ApplicantNotification { + + private final BulkPrintService bulkPrintService; + private final CaseDataDocumentService caseDataDocumentService; + private final PaperApplicationReceivedTemplateContent templateContent; + + public static final String LETTER_TYPE_PAPER_APPLICATION_RECEIVED = "paper-application-received"; + public static final String APPLICANT1_DOCUMENT_NAME = "Paper Application Received Letter - Applicant/Applicant1"; + public static final String APPLICANT2_DOCUMENT_NAME = "Paper Application Received Letter - Applicant2"; + + @Override + public void sendToApplicant1Offline(CaseData caseData, Long caseId) { + log.info("Sending application received letter to applicant 1 for case : {}", caseId); + generateApplicationReceivedLetterAndSend(caseData, caseId, caseData.getApplicant1()); + } + + @Override + public void sendToApplicant2Offline(CaseData caseData, Long caseId) { + if (!caseData.getApplicationType().isSole()) { + log.info("Sending application received letter to applicant 2 for case : {}", caseId); + generateApplicationReceivedLetterAndSend(caseData, caseId, caseData.getApplicant2()); + } + } + + private void generateApplicationReceivedLetterAndSend(CaseData caseData, Long caseId, Applicant applicant) { + + Document generatedDocument = generateDocument(caseId, applicant, caseData); + + updateCaseDataWithDocument(caseData,generatedDocument, applicant); + + Letter letter = new Letter(generatedDocument, 1); + String caseIdString = String.valueOf(caseId); + + final Print print = new Print( + List.of(letter), + caseIdString, + caseIdString, + LETTER_TYPE_PAPER_APPLICATION_RECEIVED, + applicant.getFullName(), + applicant.getAddressOverseas() + ); + + final UUID letterId = bulkPrintService.print(print); + + log.info("Letter service responded with letter Id {} for case {}", letterId, caseId); + } + + private Document generateDocument(final long caseId, + final Applicant applicant, + final CaseData caseData) { + + boolean isApplicant1 = applicant.equals(caseData.getApplicant1()); + String documentName = isApplicant1 ? APPLICANT1_DOCUMENT_NAME : APPLICANT2_DOCUMENT_NAME; + return caseDataDocumentService.renderDocument(templateContent.getTemplateContent(caseData, caseId, applicant), + caseId, + PAPER_APPLICATION_RECEIVED_TEMPLATE_ID, + applicant.getLanguagePreference(), + documentName); + } + + private void updateCaseDataWithDocument(final CaseData caseData, final Document document, final Applicant applicant) { + if (applicant.isConfidentialContactDetails()) { + ConfidentialDivorceDocument divorceDocument = ConfidentialDivorceDocument + .builder() + .documentLink(document) + .documentFileName(document.getFilename()) + .confidentialDocumentsReceived(PAPER_APPLICATION_RECEIVED_CONFIDENTIAL_LETTER) + .build(); + caseData.getDocuments().setConfidentialDocumentsGenerated(addDocumentToTop( + caseData.getDocuments().getConfidentialDocumentsGenerated(), divorceDocument)); + } else { + DivorceDocument divorceDocument = DivorceDocument + .builder() + .documentLink(document) + .documentFileName(document.getFilename()) + .documentType(PAPER_APPLICATION_RECEIVED_LETTER) + .build(); + + caseData.getDocuments().setDocumentsGenerated(addDocumentToTop( + caseData.getDocuments().getDocumentsGenerated(), divorceDocument)); + } + } +} diff --git a/src/main/java/uk/gov/hmcts/divorce/document/DocumentConstants.java b/src/main/java/uk/gov/hmcts/divorce/document/DocumentConstants.java index 43336931d5b..3b2a54e1c6d 100644 --- a/src/main/java/uk/gov/hmcts/divorce/document/DocumentConstants.java +++ b/src/main/java/uk/gov/hmcts/divorce/document/DocumentConstants.java @@ -195,6 +195,8 @@ public final class DocumentConstants { public static final String NOC_CITIZEN_LETTER_TEMPLATE_ID = "NOC_TO_SOLS_CITIZEN_LETTER"; public static final String NOC_CITIZEN_LETTER_DOCUMENT_NAME = "Noc"; + public static final String PAPER_APPLICATION_RECEIVED_TEMPLATE_ID = "NFD_APPLICANT_PAPERCASE_RECEIVED"; + public static final String APPLICANT1 = "applicant1"; public static final String APPLICANT2 = "applicant2"; diff --git a/src/main/java/uk/gov/hmcts/divorce/document/content/PaperApplicationReceivedTemplateContent.java b/src/main/java/uk/gov/hmcts/divorce/document/content/PaperApplicationReceivedTemplateContent.java new file mode 100644 index 00000000000..fba4da28f8d --- /dev/null +++ b/src/main/java/uk/gov/hmcts/divorce/document/content/PaperApplicationReceivedTemplateContent.java @@ -0,0 +1,45 @@ +package uk.gov.hmcts.divorce.document.content; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import uk.gov.hmcts.divorce.divorcecase.model.Applicant; +import uk.gov.hmcts.divorce.divorcecase.model.CaseData; +import uk.gov.hmcts.divorce.divorcecase.util.AddressUtil; + +import java.time.Clock; +import java.time.LocalDate; +import java.util.Map; + +import static uk.gov.hmcts.divorce.document.content.DocmosisTemplateConstants.CASE_REFERENCE; +import static uk.gov.hmcts.divorce.document.content.DocmosisTemplateConstants.RECIPIENT_ADDRESS; +import static uk.gov.hmcts.divorce.document.content.DocmosisTemplateConstants.RECIPIENT_NAME; +import static uk.gov.hmcts.divorce.notification.CommonContent.IS_DIVORCE; +import static uk.gov.hmcts.divorce.notification.FormatUtil.DATE_TIME_FORMATTER; +import static uk.gov.hmcts.divorce.notification.FormatUtil.formatId; + +@Component +@RequiredArgsConstructor +@Slf4j +public class PaperApplicationReceivedTemplateContent { + + private final DocmosisCommonContent docmosisCommonContent; + private final Clock clock; + + public static final String DATE_OF_RESPONSE = "dateOfResponse"; + private static final int SUBMISSION_RESPONSE_DAYS = 28; + + public Map getTemplateContent(CaseData caseData, Long caseId, Applicant applicant) { + Map templateContent = docmosisCommonContent + .getBasicDocmosisTemplateContent(applicant.getLanguagePreference()); + + templateContent.put(CASE_REFERENCE, formatId(caseId)); + templateContent.put(RECIPIENT_NAME, applicant.getFullName()); + templateContent.put(RECIPIENT_ADDRESS, AddressUtil.getPostalAddress(applicant.getAddress())); + templateContent.put(IS_DIVORCE, caseData.isDivorce()); + templateContent.put(DATE_OF_RESPONSE, LocalDate.now(clock) + .plusDays(SUBMISSION_RESPONSE_DAYS).format(DATE_TIME_FORMATTER)); + + return templateContent; + } +} diff --git a/src/main/java/uk/gov/hmcts/divorce/document/model/ConfidentialDocumentsReceived.java b/src/main/java/uk/gov/hmcts/divorce/document/model/ConfidentialDocumentsReceived.java index 2be6e5e803f..fb690c68d6a 100644 --- a/src/main/java/uk/gov/hmcts/divorce/document/model/ConfidentialDocumentsReceived.java +++ b/src/main/java/uk/gov/hmcts/divorce/document/model/ConfidentialDocumentsReceived.java @@ -169,7 +169,10 @@ public enum ConfidentialDocumentsReceived implements HasLabel { SEPARATION_ORDER_REFUSAL_COVER_LETTER("Separation order refusal cover letter"), @JsonProperty("conditionalOrderRefusalCoverLetter") - CONDITIONAL_ORDER_REFUSAL_COVER_LETTER("Conditional order refusal cover letter"); + CONDITIONAL_ORDER_REFUSAL_COVER_LETTER("Conditional order refusal cover letter"), + + @JsonProperty("paperApplicationReceivedLetter") + PAPER_APPLICATION_RECEIVED_CONFIDENTIAL_LETTER("Paper Application received letter"); private final String label; } diff --git a/src/main/java/uk/gov/hmcts/divorce/document/model/DocumentType.java b/src/main/java/uk/gov/hmcts/divorce/document/model/DocumentType.java index 12305de838e..dd9544cbe50 100644 --- a/src/main/java/uk/gov/hmcts/divorce/document/model/DocumentType.java +++ b/src/main/java/uk/gov/hmcts/divorce/document/model/DocumentType.java @@ -256,7 +256,10 @@ public enum DocumentType implements HasLabel { GRANT_OF_REPRESENTATION("NoC grant of representation letter", true), @JsonProperty("requestForInformationResponseDoc") - REQUEST_FOR_INFORMATION_RESPONSE_DOC("RFI response document", true); + REQUEST_FOR_INFORMATION_RESPONSE_DOC("RFI response document", true), + + @JsonProperty("paperApplicationReceivedLetter") + PAPER_APPLICATION_RECEIVED_LETTER("Paper Application Received Letter", true); private final String label; private final boolean potentiallyConfidential; diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 523121ba650..2f4a6025396 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -475,6 +475,7 @@ docmosis: JUDICIAL_SEPARATION_JOINT_APPLICATION: FL-NFD-APP-ENG-Judicial-Separation-Application-Joint_V1.docx NFD_NOTICE_OF_CHANGE_CONFIRMATION_APP1__APP2: FL-NFD-GRP-ENG-Grant-Of-Representation-V2.docx NFD_APP1_SOLICITOR_APPLIED_FOR_FINAL_ORDER: FL-NFD-GOR-ENG-SOLICITOR-APPLIED-FOR-FINAL-ORDER.docx + NFD_APPLICANT_PAPERCASE_RECEIVED: FL-NFD-GOR-ENG-PaperCase-Received-Applicant.docx NFD_NOTICE_OF_CHANGE_INVITE_APP: FL-NFD-GOR-ENG-Solicitor_stopped_representation_citizen_letter_V1.docx NFD_SOL_STOPPED_REP_NOTIFY_APP: FL-NFD-GOR-ENG-Solicitor_stopped_representation_notify_citizen_V1.docx welsh: @@ -561,6 +562,7 @@ docmosis: JUDICIAL_SEPARATION_JOINT_APPLICATION: FL-NFD-APP-ENG-Judicial-Separation-Application-Joint_V1.docx NFD_NOTICE_OF_CHANGE_CONFIRMATION_APP1__APP2: FL-NFD-GRP-WEL-Grant-Of-Representation.docx NFD_APP1_SOLICITOR_APPLIED_FOR_FINAL_ORDER: FL-NFD-GOR-WEL-SOLICITOR-APPLIED-FOR-FINAL-ORDER.docx + NFD_APPLICANT_PAPERCASE_RECEIVED: FL-NFD-GOR-WEL-PaperCase-Received-Applicant.docx NFD_NOTICE_OF_CHANGE_INVITE_APP: FL-NFD-GOR-WEL-Solicitor_stopped_representation_citizen_letter_V1.docx NFD_SOL_STOPPED_REP_NOTIFY_APP: FL-NFD-GOR-ENG-Solicitor_stopped_representation_notify_citizen_V1.docx #TODO: update Welsh content templateVars: diff --git a/src/test/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerCreatePaperCaseTest.java b/src/test/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerCreatePaperCaseTest.java index f59f2a5ee79..1ad5f4d3c2c 100644 --- a/src/test/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerCreatePaperCaseTest.java +++ b/src/test/java/uk/gov/hmcts/divorce/caseworker/event/CaseworkerCreatePaperCaseTest.java @@ -3,20 +3,24 @@ 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.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.api.callback.AboutToStartOrSubmitResponse; +import uk.gov.hmcts.divorce.caseworker.service.notification.PaperApplicationReceivedNotification; import uk.gov.hmcts.divorce.divorcecase.model.ApplicationType; import uk.gov.hmcts.divorce.divorcecase.model.CaseData; import uk.gov.hmcts.divorce.divorcecase.model.LabelContent; import uk.gov.hmcts.divorce.divorcecase.model.State; import uk.gov.hmcts.divorce.divorcecase.model.SupplementaryCaseType; import uk.gov.hmcts.divorce.divorcecase.model.UserRole; +import uk.gov.hmcts.divorce.notification.NotificationDispatcher; import uk.gov.hmcts.divorce.testutil.ConfigTestUtil; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.verify; import static uk.gov.hmcts.ccd.sdk.type.YesOrNo.NO; import static uk.gov.hmcts.ccd.sdk.type.YesOrNo.YES; import static uk.gov.hmcts.divorce.caseworker.event.CaseworkerCreatePaperCase.CREATE_PAPER_CASE; @@ -28,6 +32,11 @@ @ExtendWith(MockitoExtension.class) public class CaseworkerCreatePaperCaseTest { + + @Mock + private NotificationDispatcher notificationDispatcher; + @Mock + private PaperApplicationReceivedNotification paperApplicationReceivedNotification; @InjectMocks private CaseworkerCreatePaperCase caseworkerCreatePaperCase; @@ -163,4 +172,16 @@ public void shouldSetBothApplicantsOfflineWhenSeparation() { assertThat(submitResponse.getData().getApplicant1().getOffline()).isEqualTo(YES); assertThat(submitResponse.getData().getApplicant2().getOffline()).isEqualTo(YES); } + + @Test + public void shouldSendNotificationInAboutToSubmitCallBack() { + final CaseData caseData = caseData(); + final CaseDetails details = new CaseDetails<>(); + details.setId(TEST_CASE_ID); + details.setData(caseData); + + AboutToStartOrSubmitResponse response = caseworkerCreatePaperCase.aboutToSubmit(details, details); + + verify(notificationDispatcher).send(paperApplicationReceivedNotification, caseData, TEST_CASE_ID); + } } diff --git a/src/test/java/uk/gov/hmcts/divorce/caseworker/service/notification/PaperApplicationReceivedNotificationTest.java b/src/test/java/uk/gov/hmcts/divorce/caseworker/service/notification/PaperApplicationReceivedNotificationTest.java new file mode 100644 index 00000000000..73da35491aa --- /dev/null +++ b/src/test/java/uk/gov/hmcts/divorce/caseworker/service/notification/PaperApplicationReceivedNotificationTest.java @@ -0,0 +1,226 @@ +package uk.gov.hmcts.divorce.caseworker.service.notification; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import uk.gov.hmcts.ccd.sdk.type.Document; +import uk.gov.hmcts.ccd.sdk.type.YesOrNo; +import uk.gov.hmcts.divorce.divorcecase.model.Applicant; +import uk.gov.hmcts.divorce.divorcecase.model.CaseData; +import uk.gov.hmcts.divorce.divorcecase.model.ContactDetailsType; +import uk.gov.hmcts.divorce.document.CaseDataDocumentService; +import uk.gov.hmcts.divorce.document.content.PaperApplicationReceivedTemplateContent; +import uk.gov.hmcts.divorce.document.print.BulkPrintService; +import uk.gov.hmcts.divorce.document.print.model.Print; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static uk.gov.hmcts.ccd.sdk.type.YesOrNo.YES; +import static uk.gov.hmcts.divorce.caseworker.service.notification.PaperApplicationReceivedNotification.APPLICANT1_DOCUMENT_NAME; +import static uk.gov.hmcts.divorce.caseworker.service.notification.PaperApplicationReceivedNotification.APPLICANT2_DOCUMENT_NAME; +import static uk.gov.hmcts.divorce.caseworker.service.notification.PaperApplicationReceivedNotification.LETTER_TYPE_PAPER_APPLICATION_RECEIVED; +import static uk.gov.hmcts.divorce.divorcecase.model.ApplicationType.JOINT_APPLICATION; +import static uk.gov.hmcts.divorce.divorcecase.model.Gender.MALE; +import static uk.gov.hmcts.divorce.divorcecase.model.LanguagePreference.ENGLISH; +import static uk.gov.hmcts.divorce.divorcecase.model.LanguagePreference.WELSH; +import static uk.gov.hmcts.divorce.document.DocumentConstants.PAPER_APPLICATION_RECEIVED_TEMPLATE_ID; +import static uk.gov.hmcts.divorce.document.model.ConfidentialDocumentsReceived.PAPER_APPLICATION_RECEIVED_CONFIDENTIAL_LETTER; +import static uk.gov.hmcts.divorce.document.model.DocumentType.PAPER_APPLICATION_RECEIVED_LETTER; +import static uk.gov.hmcts.divorce.testutil.TestConstants.TEST_CASE_ID; + +@ExtendWith(MockitoExtension.class) +class PaperApplicationReceivedNotificationTest { + @Mock + private PaperApplicationReceivedTemplateContent paperApplicationReceivedTemplateContent; + + @Mock + private CaseDataDocumentService caseDataDocumentService; + + @InjectMocks + private PaperApplicationReceivedNotification notificationHandler; + + @Mock + private BulkPrintService bulkPrintService; + + @Captor + ArgumentCaptor printCaptor; + + @Test + void testSendToApplicant1Offline() { + CaseData caseData = createMockCaseData(); + + final Map templateContent = new HashMap<>(); + + when(bulkPrintService.print(printCaptor.capture())).thenReturn(UUID.randomUUID()); + + when(paperApplicationReceivedTemplateContent.getTemplateContent(caseData, TEST_CASE_ID, caseData.getApplicant1())) + .thenReturn(templateContent); + + Document document = + Document.builder() + .url("testUrl") + .filename("testFileName") + .binaryUrl("binaryUrl") + .build(); + + when(caseDataDocumentService.renderDocument( + templateContent, + TEST_CASE_ID, + PAPER_APPLICATION_RECEIVED_TEMPLATE_ID, + ENGLISH, + APPLICANT1_DOCUMENT_NAME)) + .thenReturn(document); + notificationHandler.sendToApplicant1Offline(caseData, TEST_CASE_ID); + + final Print print = printCaptor.getValue(); + + assertThat(print.getCaseId()).isEqualTo(TEST_CASE_ID.toString()); + assertThat(print.getCaseRef()).isEqualTo(TEST_CASE_ID.toString()); + assertThat(print.getLetterType()).isEqualTo(LETTER_TYPE_PAPER_APPLICATION_RECEIVED); + assertThat(print.getLetters()).hasSize(1); + assertThat(print.getLetters().get(0).getDocument()).isSameAs(document); + verify(caseDataDocumentService) + .renderDocument( + templateContent, + TEST_CASE_ID, + PAPER_APPLICATION_RECEIVED_TEMPLATE_ID, + ENGLISH, APPLICANT1_DOCUMENT_NAME); + } + + @Test + void testSendToApplicant2Offline() { + CaseData caseData = createMockCaseData(); + + final Map templateContent = new HashMap<>(); + + when(bulkPrintService.print(printCaptor.capture())).thenReturn(UUID.randomUUID()); + + when(paperApplicationReceivedTemplateContent.getTemplateContent(caseData, TEST_CASE_ID, caseData.getApplicant2())) + .thenReturn(templateContent); + + Document document = + Document.builder() + .url("testUrl") + .filename("testFileName") + .binaryUrl("binaryUrl") + .build(); + + when(caseDataDocumentService.renderDocument( + templateContent, + TEST_CASE_ID, + PAPER_APPLICATION_RECEIVED_TEMPLATE_ID, + WELSH, + APPLICANT2_DOCUMENT_NAME)) + .thenReturn(document); + notificationHandler.sendToApplicant2Offline(caseData, TEST_CASE_ID); + + final Print print = printCaptor.getValue(); + + assertThat(print.getCaseId()).isEqualTo(TEST_CASE_ID.toString()); + assertThat(print.getCaseRef()).isEqualTo(TEST_CASE_ID.toString()); + assertThat(print.getLetterType()).isEqualTo(LETTER_TYPE_PAPER_APPLICATION_RECEIVED); + assertThat(print.getLetters()).hasSize(1); + assertThat(print.getLetters().get(0).getDocument()).isSameAs(document); + verify(caseDataDocumentService) + .renderDocument( + templateContent, + TEST_CASE_ID, + PAPER_APPLICATION_RECEIVED_TEMPLATE_ID, + WELSH, APPLICANT2_DOCUMENT_NAME); + } + + @Test + void shouldAddDocumentToGeneratedDocumentsWhenApplicant1IsNotConfidential() { + CaseData caseData = createMockCaseData(); + caseData.getApplicant1().setContactDetailsType(ContactDetailsType.PUBLIC); + + final Map templateContent = new HashMap<>(); + + when(bulkPrintService.print(printCaptor.capture())).thenReturn(UUID.randomUUID()); + + when(paperApplicationReceivedTemplateContent.getTemplateContent(caseData, TEST_CASE_ID, caseData.getApplicant1())) + .thenReturn(templateContent); + + Document document = + Document.builder() + .url("testUrl") + .filename("testFileName") + .binaryUrl("binaryUrl") + .build(); + + when(caseDataDocumentService.renderDocument( + templateContent, + TEST_CASE_ID, + PAPER_APPLICATION_RECEIVED_TEMPLATE_ID, + ENGLISH, + APPLICANT1_DOCUMENT_NAME)) + .thenReturn(document); + notificationHandler.sendToApplicant1Offline(caseData, TEST_CASE_ID); + + assertThat(caseData.getDocuments().getDocumentsGenerated().size()).isEqualTo(1); + assertThat(caseData.getDocuments().getDocumentsGenerated().get(0).getValue().getDocumentLink()).isEqualTo(document); + assertThat(caseData.getDocuments().getDocumentsGenerated().get(0).getValue().getDocumentType()) + .isEqualTo(PAPER_APPLICATION_RECEIVED_LETTER); + } + + @Test + void shouldAddDocumentToConfidentialGeneratedDocumentsWhenApplicant1IsConfidential() { + CaseData caseData = createMockCaseData(); + caseData.getApplicant1().setContactDetailsType(ContactDetailsType.PRIVATE); + + final Map templateContent = new HashMap<>(); + + when(bulkPrintService.print(printCaptor.capture())).thenReturn(UUID.randomUUID()); + + when(paperApplicationReceivedTemplateContent.getTemplateContent(caseData, TEST_CASE_ID, caseData.getApplicant1())) + .thenReturn(templateContent); + + Document document = + Document.builder() + .url("testUrl") + .filename("testFileName") + .binaryUrl("binaryUrl") + .build(); + + when(caseDataDocumentService.renderDocument( + templateContent, + TEST_CASE_ID, + PAPER_APPLICATION_RECEIVED_TEMPLATE_ID, + ENGLISH, + APPLICANT1_DOCUMENT_NAME)) + .thenReturn(document); + notificationHandler.sendToApplicant1Offline(caseData, TEST_CASE_ID); + + assertThat(caseData.getDocuments().getDocumentsGenerated()).isNull(); + assertThat(caseData.getDocuments().getConfidentialDocumentsGenerated().size()).isEqualTo(1); + assertThat(caseData.getDocuments().getConfidentialDocumentsGenerated().get(0).getValue().getDocumentLink()).isEqualTo(document); + assertThat(caseData.getDocuments().getConfidentialDocumentsGenerated().get(0).getValue().getConfidentialDocumentsReceived()) + .isEqualTo(PAPER_APPLICATION_RECEIVED_CONFIDENTIAL_LETTER); + } + + private CaseData createMockCaseData() { + CaseData caseData = CaseData.builder().build(); + caseData.setApplicant1(createApplicant("test@test.com", YesOrNo.NO)); + caseData.setApplicant2(createApplicant("testtwo@test.com", YesOrNo.YES)); + caseData.setApplicationType(JOINT_APPLICATION); + caseData.getApplicant2().setGender(MALE); + caseData.getApplication().setApplicant1StatementOfTruth(YES); + return caseData; + } + + private Applicant createApplicant(String email, YesOrNo languagePreferenceWelsh) { + return Applicant.builder() + .email(email) + .languagePreferenceWelsh(languagePreferenceWelsh) + .build(); + } +} diff --git a/src/test/java/uk/gov/hmcts/divorce/document/content/PaperApplicationReceivedTemplateContentTest.java b/src/test/java/uk/gov/hmcts/divorce/document/content/PaperApplicationReceivedTemplateContentTest.java new file mode 100644 index 00000000000..02508ac4811 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/divorce/document/content/PaperApplicationReceivedTemplateContentTest.java @@ -0,0 +1,79 @@ +package uk.gov.hmcts.divorce.document.content; + +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.ccd.sdk.type.AddressGlobalUK; +import uk.gov.hmcts.divorce.divorcecase.model.CtscContactDetails; +import uk.gov.hmcts.divorce.testutil.TestDataHelper; + +import java.time.Clock; +import java.time.LocalDate; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; +import static org.mockito.Mockito.when; +import static uk.gov.hmcts.divorce.divorcecase.model.LanguagePreference.ENGLISH; +import static uk.gov.hmcts.divorce.document.content.DocmosisTemplateConstants.CASE_REFERENCE; +import static uk.gov.hmcts.divorce.document.content.DocmosisTemplateConstants.CTSC_CONTACT_DETAILS; +import static uk.gov.hmcts.divorce.document.content.DocmosisTemplateConstants.RECIPIENT_ADDRESS; +import static uk.gov.hmcts.divorce.document.content.DocmosisTemplateConstants.RECIPIENT_NAME; +import static uk.gov.hmcts.divorce.document.content.PaperApplicationReceivedTemplateContent.DATE_OF_RESPONSE; +import static uk.gov.hmcts.divorce.notification.CommonContent.IS_DIVORCE; +import static uk.gov.hmcts.divorce.testutil.ClockTestUtil.setMockClock; +import static uk.gov.hmcts.divorce.testutil.TestConstants.FORMATTED_TEST_CASE_ID; +import static uk.gov.hmcts.divorce.testutil.TestConstants.TEST_CASE_ID; +import static uk.gov.hmcts.divorce.testutil.TestDataHelper.getBasicDocmosisTemplateContentWithCtscContactDetails; + +@ExtendWith(MockitoExtension.class) +class PaperApplicationReceivedTemplateContentTest { + + @Mock + private Clock clock; + + @Mock + private DocmosisCommonContent docmosisCommonContent; + + @InjectMocks + private PaperApplicationReceivedTemplateContent paperApplicationReceivedTemplateContent; + + private static final CtscContactDetails CTSC_CONTACT = CtscContactDetails + .builder() + .centreName("HMCTS Digital Divorce and Dissolution") + .serviceCentre("Courts and Tribunals Service Centre") + .emailAddress("contactdivorce@justice.gov.uk") + .poBox("PO Box 13226") + .town("Harlow") + .postcode("CM20 9UG") + .phoneNumber("0300 303 0642") + .build(); + + void setUp() { + setMockClock(clock, LocalDate.of(2022, 3, 01)); + } + + @Test + public void shouldMapTemplateContentWhenRecipientIsApplicant1() { + setUp(); + var caseData = TestDataHelper.caseData(); + caseData.getApplicant1().setAddress(AddressGlobalUK.builder().addressLine1("line 1\ntown\npostcode").build()); + + when(docmosisCommonContent.getBasicDocmosisTemplateContent(caseData.getApplicant1().getLanguagePreference())) + .thenReturn(getBasicDocmosisTemplateContentWithCtscContactDetails(ENGLISH)); + + final Map templateContent = paperApplicationReceivedTemplateContent + .getTemplateContent(caseData, TEST_CASE_ID, caseData.getApplicant1()); + + assertThat(templateContent).contains( + entry(CASE_REFERENCE, FORMATTED_TEST_CASE_ID), + entry(RECIPIENT_NAME, "test_first_name test_middle_name test_last_name"), + entry(RECIPIENT_ADDRESS, "line 1\ntown\npostcode"), + entry(CTSC_CONTACT_DETAILS, CTSC_CONTACT), + entry(IS_DIVORCE, true), + entry(DATE_OF_RESPONSE, "29 March 2022") + ); + } +}