diff --git a/src/functionalTest/resources/scenarios/RIA-7326-internal-ada-apply-for-ftpa-appellant-letter.json b/src/functionalTest/resources/scenarios/RIA-7326-internal-ada-apply-for-ftpa-appellant-letter.json new file mode 100644 index 000000000..df0412da7 --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7326-internal-ada-apply-for-ftpa-appellant-letter.json @@ -0,0 +1,44 @@ +{ + "description": "RIA-7326 internal ADA apply for ftpa (appellant) letter generation", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "AdminOfficer", + "input": { + "id": 7326, + "eventId": "applyForFTPAAppellant", + "state": "decided", + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "isAcceleratedDetainedAppeal": "Yes" + } + } + } + }, + "expectation": { + "status": 200, + "errors": [], + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "notificationAttachmentDocuments": [ + { + "id": "1", + "value": { + "document": { + "document_url": "$/http.+\/documents/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/", + "document_binary_url": "$/http.+\/documents/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\/binary/", + "document_filename": "PA 12345 2019-Awan-apply-for-ftpa-appellant-letter.PDF" + }, + "description": "", + "dateUploaded": "{$TODAY}", + "tag": "internalFtpaSubmittedLetter" + } + } + ] + } + } + } +} diff --git a/src/functionalTest/resources/scenarios/RIA-7326-internal-detained-apply-for-ftpa-appellant-letter.json b/src/functionalTest/resources/scenarios/RIA-7326-internal-detained-apply-for-ftpa-appellant-letter.json new file mode 100644 index 000000000..7a8c0a7c1 --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7326-internal-detained-apply-for-ftpa-appellant-letter.json @@ -0,0 +1,43 @@ +{ + "description": "RIA-7326 internal detained (non-ada) apply for ftpa (appellant) letter generation", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "AdminOfficer", + "input": { + "id": 7326, + "eventId": "applyForFTPAAppellant", + "state": "decided", + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes" + } + } + } + }, + "expectation": { + "status": 200, + "errors": [], + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "notificationAttachmentDocuments": [ + { + "id": "1", + "value": { + "document": { + "document_url": "$/http.+\/documents/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/", + "document_binary_url": "$/http.+\/documents/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\/binary/", + "document_filename": "PA 12345 2019-Awan-apply-for-ftpa-appellant-letter.PDF" + }, + "description": "", + "dateUploaded": "{$TODAY}", + "tag": "internalFtpaSubmittedLetter" + } + } + ] + } + } + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/DocumentTag.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/DocumentTag.java index 6cbd74ed0..3d3e4d870 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/DocumentTag.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/DocumentTag.java @@ -56,6 +56,7 @@ public enum DocumentTag { INTERNAL_DET_MARK_AS_ADA_LETTER("internalDetMarkAsAdaLetter", CaseType.ASYLUM), INTERNAL_DECIDE_AN_APPLICATION_LETTER("internalDecideAnApplicationLetter", CaseType.ASYLUM), INTERNAL_APPLY_FOR_FTPA_RESPONDENT("internalApplyForFtpaRespondent", CaseType.ASYLUM), + INTERNAL_FTPA_SUBMITTED_LETTER("internalFtpaSubmittedLetter", CaseType.ASYLUM), BAIL_SUBMISSION("bailSubmission", CaseType.BAIL), BAIL_EVIDENCE("uploadTheBailEvidenceDocs", CaseType.BAIL), BAIL_DECISION_UNSIGNED("bailDecisionUnsigned", CaseType.BAIL), diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/ccd/Event.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/ccd/Event.java index 790d88e4e..d7c3fb5fb 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/ccd/Event.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/ccd/Event.java @@ -50,6 +50,7 @@ public enum Event { REQUEST_RESPONSE_REVIEW("requestResponseReview", CaseType.ASYLUM), MARK_APPEAL_AS_ADA("markAppealAsAda", CaseType.ASYLUM), APPLY_FOR_FTPA_RESPONDENT("applyForFTPARespondent", CaseType.ASYLUM), + APPLY_FOR_FTPA_APPELLANT("applyForFTPAAppellant", CaseType.ASYLUM), DECIDE_AN_APPLICATION("decideAnApplication", CaseType.ASYLUM), SUBMIT_APPLICATION("submitApplication", CaseType.BAIL), RECORD_THE_DECISION("recordTheDecision", CaseType.BAIL), diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalApplyForFtpaAppellantLetterGenerator.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalApplyForFtpaAppellantLetterGenerator.java new file mode 100644 index 000000000..f93d38517 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalApplyForFtpaAppellantLetterGenerator.java @@ -0,0 +1,73 @@ +package uk.gov.hmcts.reform.iacasedocumentsapi.domain.handlers.presubmit.letter; + +import static java.util.Objects.requireNonNull; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.NOTIFICATION_ATTACHMENT_DOCUMENTS; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isAppellantInDetention; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isInternalCase; + +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCase; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.DocumentTag; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.CaseDetails; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.Event; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.callback.Callback; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.callback.PreSubmitCallbackResponse; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.callback.PreSubmitCallbackStage; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.Document; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.handlers.PreSubmitCallbackHandler; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.service.DocumentCreator; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.service.DocumentHandler; + + +@Component +public class InternalApplyForFtpaAppellantLetterGenerator implements PreSubmitCallbackHandler { + + private final DocumentCreator internalApplyForFtpaAppellantLetter; + private final DocumentHandler documentHandler; + + public InternalApplyForFtpaAppellantLetterGenerator( + @Qualifier("internalApplyForFtpaAppellantLetter") DocumentCreator internalApplyForFtpaAppellantLetter, + DocumentHandler documentHandler + ) { + this.internalApplyForFtpaAppellantLetter = internalApplyForFtpaAppellantLetter; + this.documentHandler = documentHandler; + } + + public boolean canHandle( + PreSubmitCallbackStage callbackStage, + Callback callback + ) { + requireNonNull(callbackStage, "callbackStage must not be null"); + requireNonNull(callback, "callback must not be null"); + AsylumCase asylumCase = callback.getCaseDetails().getCaseData(); + + return callbackStage == PreSubmitCallbackStage.ABOUT_TO_SUBMIT + && callback.getEvent() == Event.APPLY_FOR_FTPA_APPELLANT + && isInternalCase(asylumCase) + && isAppellantInDetention(asylumCase); + } + + public PreSubmitCallbackResponse handle( + PreSubmitCallbackStage callbackStage, + Callback callback + ) { + if (!canHandle(callbackStage, callback)) { + throw new IllegalStateException("Cannot handle callback"); + } + + final CaseDetails caseDetails = callback.getCaseDetails(); + final AsylumCase asylumCase = caseDetails.getCaseData(); + + Document documentForUpload = internalApplyForFtpaAppellantLetter.create(caseDetails); + + documentHandler.addWithMetadata( + asylumCase, + documentForUpload, + NOTIFICATION_ATTACHMENT_DOCUMENTS, + DocumentTag.INTERNAL_FTPA_SUBMITTED_LETTER + ); + + return new PreSubmitCallbackResponse<>(asylumCase); + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/service/BundleOrder.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/service/BundleOrder.java index 5f8c728d1..dfc42f156 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/service/BundleOrder.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/service/BundleOrder.java @@ -149,7 +149,10 @@ private int bundlePositionIndex(DocumentWithMetadata document) { return 49; case INTERNAL_APPLY_FOR_FTPA_RESPONDENT: log.warn("INTERNAL_APPLY_FOR_FTPA_RESPONDENT_LETTER tag should not be checked for bundle ordering, document desc: {}", document.getDescription()); - return 49; + return 50; + case INTERNAL_FTPA_SUBMITTED_LETTER: + log.warn("INTERNAL_FTPA_SUBMITTED_LETTER tag should not be checked for bundle ordering, document desc: {}", document.getDescription()); + return 51; default: throw new IllegalStateException("document has unknown tag: " + document.getTag() + ", description: " + document.getDescription()); } diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalApplyForFtpaAppellantLetterTemplate.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalApplyForFtpaAppellantLetterTemplate.java new file mode 100644 index 000000000..1dee099d6 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalApplyForFtpaAppellantLetterTemplate.java @@ -0,0 +1,51 @@ +package uk.gov.hmcts.reform.iacasedocumentsapi.domain.templates.letter; + +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.getAppellantPersonalisation; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.DateUtils.formatDateForNotificationAttachmentDocument; + +import java.util.HashMap; +import java.util.Map; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.DateProvider; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCase; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.CaseDetails; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.templates.DocumentTemplate; +import uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.CustomerServicesProvider; + + +@Component +public class InternalApplyForFtpaAppellantLetterTemplate implements DocumentTemplate { + + private final String templateName; + private final DateProvider dateProvider; + private final CustomerServicesProvider customerServicesProvider; + + + public InternalApplyForFtpaAppellantLetterTemplate( + @Value("${internalApplyForFtpaAppellantLetter.templateName}") String templateName, + DateProvider dateProvider, + CustomerServicesProvider customerServicesProvider) { + this.templateName = templateName; + this.dateProvider = dateProvider; + this.customerServicesProvider = customerServicesProvider; + } + + public String getName() { + return templateName; + } + + public Map mapFieldValues( + CaseDetails caseDetails + ) { + final AsylumCase asylumCase = caseDetails.getCaseData(); + final Map fieldValues = new HashMap<>(); + + fieldValues.putAll(getAppellantPersonalisation(asylumCase)); + fieldValues.put("dateLetterSent", formatDateForNotificationAttachmentDocument(dateProvider.now())); + fieldValues.put("customerServicesTelephone", customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase)); + fieldValues.put("customerServicesEmail", customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)); + + return fieldValues; + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/config/DocumentCreatorConfiguration.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/config/DocumentCreatorConfiguration.java index 2f54e9525..ed7510b55 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/config/DocumentCreatorConfiguration.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/infrastructure/config/DocumentCreatorConfiguration.java @@ -1023,4 +1023,25 @@ public DocumentCreator getInternalFtpaSubmittedDocumentCreator( documentUploader ); } + + @Bean("internalApplyForFtpaAppellantLetter") + public DocumentCreator getInternalApplyForFtpaAppellantLetterCreator( + @Value("${internalApplyForFtpaAppellantLetter.contentType}") String contentType, + @Value("${internalApplyForFtpaAppellantLetter.fileExtension}") String fileExtension, + @Value("${internalApplyForFtpaAppellantLetter.fileName}") String fileName, + AsylumCaseFileNameQualifier fileNameQualifier, + InternalApplyForFtpaAppellantLetterTemplate documentTemplate, + DocumentGenerator documentGenerator, + DocumentUploader documentUploader + ) { + return new DocumentCreator<>( + contentType, + fileExtension, + fileName, + fileNameQualifier, + documentTemplate, + documentGenerator, + documentUploader + ); + } } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index dac509f5d..6b6f346cf 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -314,6 +314,11 @@ internalDetainedApplyForFtpaRespondentLetter.fileExtension: PDF internalDetainedApplyForFtpaRespondentLetter.fileName: "apply-for-ftpa-respondent-letter" internalDetainedApplyForFtpaRespondentLetter.templateName: ${IA_INTERNAL_DETAINED_APPLY_FOR_FTPA_RESPONDENT_LETTER_TEMPLATE:TB-IAC-LET-ENG-00009.docx} +internalApplyForFtpaAppellantLetter.contentType: application/pdf +internalApplyForFtpaAppellantLetter.fileExtension: PDF +internalApplyForFtpaAppellantLetter.fileName: "apply-for-ftpa-appellant-letter" +internalApplyForFtpaAppellantLetter.templateName: ${IA_INTERNAL_APPLY_FOR_FTPA_APPELLANT_LETTER_TEMPLATE:TB-IAC-LET-ENG-00017.docx} + ccdGatewayUrl: ${CCD_GW_URL:http://localhost:3453} docmosis.accessKey: ${DOCMOSIS_ACCESS_KEY} @@ -415,6 +420,7 @@ security: - "markAppealPaid" - "recordRemissionDecision" - "markAppealAsAda" + - "applyForFTPAAppellant" citizen: - "startAppeal" - "editAppeal" diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/DocumentTagTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/DocumentTagTest.java index 8c70ba243..82e247fcc 100644 --- a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/DocumentTagTest.java +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/DocumentTagTest.java @@ -59,10 +59,11 @@ public void has_correct_values() { assertEquals("internalDetMarkAsAdaLetter", DocumentTag.INTERNAL_DET_MARK_AS_ADA_LETTER.toString()); assertEquals("internalDecideAnApplicationLetter", DocumentTag.INTERNAL_DECIDE_AN_APPLICATION_LETTER.toString()); assertEquals("internalApplyForFtpaRespondent", DocumentTag.INTERNAL_APPLY_FOR_FTPA_RESPONDENT.toString()); + assertEquals("internalFtpaSubmittedLetter", DocumentTag.INTERNAL_FTPA_SUBMITTED_LETTER.toString()); } @Test public void if_this_test_fails_it_is_because_it_needs_updating_with_your_changes() { - assertEquals(58, DocumentTag.values().length); + assertEquals(59, DocumentTag.values().length); } } diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/ccd/EventTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/ccd/EventTest.java index 520a739d6..05c680fbc 100644 --- a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/ccd/EventTest.java +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/ccd/EventTest.java @@ -58,10 +58,11 @@ public void has_correct_values() { assertEquals("markAppealAsAda", Event.MARK_APPEAL_AS_ADA.toString()); assertEquals("decideAnApplication", Event.DECIDE_AN_APPLICATION.toString()); assertEquals("applyForFTPARespondent", Event.APPLY_FOR_FTPA_RESPONDENT.toString()); + assertEquals("applyForFTPAAppellant", Event.APPLY_FOR_FTPA_APPELLANT.toString()); } @Test public void if_this_test_fails_it_is_because_it_needs_updating_with_your_changes() { - assertEquals(53, Event.values().length); + assertEquals(54, Event.values().length); } } diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalApplyForFtpaAppellantLetterGeneratorTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalApplyForFtpaAppellantLetterGeneratorTest.java new file mode 100644 index 000000000..b0c4a8b5d --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalApplyForFtpaAppellantLetterGeneratorTest.java @@ -0,0 +1,153 @@ +package uk.gov.hmcts.reform.iacasedocumentsapi.domain.handlers.presubmit.letter; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.mockito.Mockito.*; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.*; + +import java.util.Optional; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCase; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.DocumentTag; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.CaseDetails; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.Event; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.callback.Callback; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.callback.PreSubmitCallbackResponse; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.callback.PreSubmitCallbackStage; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.Document; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.YesOrNo; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.service.DocumentCreator; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.service.DocumentHandler; + + +@ExtendWith(MockitoExtension.class) +@SuppressWarnings("unchecked") +@MockitoSettings(strictness = Strictness.LENIENT) +public class InternalApplyForFtpaAppellantLetterGeneratorTest { + + @Mock + private DocumentCreator internalApplyForFtpaAppellantLetterCreator; + @Mock + private DocumentHandler documentHandler; + @Mock + private Callback callback; + @Mock + private CaseDetails caseDetails; + @Mock + private AsylumCase asylumCase; + @Mock + private Document uploadedDocument; + private InternalApplyForFtpaAppellantLetterGenerator internalApplyForFtpaAppellantLetterGenerator; + + @BeforeEach + public void setUp() { + internalApplyForFtpaAppellantLetterGenerator = + new InternalApplyForFtpaAppellantLetterGenerator( + internalApplyForFtpaAppellantLetterCreator, + documentHandler + ); + + when(callback.getEvent()).thenReturn(Event.APPLY_FOR_FTPA_APPELLANT); + when(callback.getCaseDetails()).thenReturn(caseDetails); + when(caseDetails.getCaseData()).thenReturn(asylumCase); + when(asylumCase.read(IS_ADMIN, YesOrNo.class)).thenReturn(Optional.of(YesOrNo.YES)); + when(asylumCase.read(APPELLANT_IN_DETENTION, YesOrNo.class)).thenReturn(Optional.of(YesOrNo.YES)); + when(internalApplyForFtpaAppellantLetterCreator.create(caseDetails)).thenReturn(uploadedDocument); + } + + @Test + public void should_create_internal_ftpa_submitted_appellant_pdf_and_append_to_notification_attachment_documents_for_the_case() { + PreSubmitCallbackResponse callbackResponse = + internalApplyForFtpaAppellantLetterGenerator.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback); + + assertNotNull(callbackResponse); + assertEquals(asylumCase, callbackResponse.getData()); + + verify(documentHandler, times(1)).addWithMetadata(asylumCase, uploadedDocument, NOTIFICATION_ATTACHMENT_DOCUMENTS, DocumentTag.INTERNAL_FTPA_SUBMITTED_LETTER); + } + + @Test + public void should_not_allow_null_arguments() { + + assertThatThrownBy(() -> internalApplyForFtpaAppellantLetterGenerator.canHandle(null, callback)) + .hasMessage("callbackStage must not be null") + .isExactlyInstanceOf(NullPointerException.class); + + assertThatThrownBy(() -> internalApplyForFtpaAppellantLetterGenerator.canHandle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, null)) + .hasMessage("callback must not be null") + .isExactlyInstanceOf(NullPointerException.class); + + assertThatThrownBy(() -> internalApplyForFtpaAppellantLetterGenerator.handle(null, callback)) + .hasMessage("callbackStage must not be null") + .isExactlyInstanceOf(NullPointerException.class); + + assertThatThrownBy(() -> internalApplyForFtpaAppellantLetterGenerator.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, null)) + .hasMessage("callback must not be null") + .isExactlyInstanceOf(NullPointerException.class); + } + + @Test + public void it_should_only_handle_about_to_submit_and_apply_for_ftpa_appellant_event() { + + for (Event event : Event.values()) { + + when(callback.getEvent()).thenReturn(event); + when(callback.getCaseDetails()).thenReturn(caseDetails); + + for (PreSubmitCallbackStage callbackStage : PreSubmitCallbackStage.values()) { + boolean canHandle = internalApplyForFtpaAppellantLetterGenerator.canHandle(callbackStage, callback); + + if (callbackStage == PreSubmitCallbackStage.ABOUT_TO_SUBMIT + && callback.getEvent().equals(Event.APPLY_FOR_FTPA_APPELLANT)) { + assertTrue(canHandle); + } else { + assertFalse(canHandle); + } + } + reset(callback); + } + } + + @Test + public void it_cannot_handle_callback_if_appellant_is_not_in_detention() { + when(callback.getCaseDetails().getCaseData().read(APPELLANT_IN_DETENTION, YesOrNo.class)).thenReturn(Optional.of(YesOrNo.NO)); + + for (PreSubmitCallbackStage callbackStage : PreSubmitCallbackStage.values()) { + boolean canHandle = internalApplyForFtpaAppellantLetterGenerator.canHandle(callbackStage, callback); + assertFalse(canHandle); + } + } + + @ParameterizedTest + @EnumSource(value = YesOrNo.class) + public void it_should_only_handle_internal_cases(YesOrNo yesOrNo) { + when(asylumCase.read(IS_ADMIN, YesOrNo.class)).thenReturn(Optional.of(yesOrNo)); + + boolean canHandle = internalApplyForFtpaAppellantLetterGenerator.canHandle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback); + + if (yesOrNo.equals(YesOrNo.YES)) { + assertTrue(canHandle); + } else { + assertFalse(canHandle); + } + } + + @ParameterizedTest + @EnumSource(value = YesOrNo.class) + public void it_should_handle_both_detained_non_ada_and_ada_cases(YesOrNo yesOrNo) { + when(asylumCase.read(IS_ACCELERATED_DETAINED_APPEAL, YesOrNo.class)).thenReturn(Optional.of(yesOrNo)); + + boolean canHandle = internalApplyForFtpaAppellantLetterGenerator.canHandle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback); + assertTrue(canHandle); + } + +} diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/service/BundleOrderTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/service/BundleOrderTest.java index 298d64041..5808452e1 100644 --- a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/service/BundleOrderTest.java +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/service/BundleOrderTest.java @@ -37,7 +37,7 @@ public void should_sort_in_correct_order_excluding_bail_tags() { .map(DocumentWithMetadata::getTag) .collect(Collectors.toList()); - assertEquals(52, sortedTags.size()); + assertEquals(53, sortedTags.size()); List documentTagList = Arrays.asList( DocumentTag.CASE_SUMMARY, diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalApplyForFtpaAppellantLetterTemplateTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalApplyForFtpaAppellantLetterTemplateTest.java new file mode 100644 index 000000000..3c455b811 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalApplyForFtpaAppellantLetterTemplateTest.java @@ -0,0 +1,92 @@ +package uk.gov.hmcts.reform.iacasedocumentsapi.domain.templates.letter; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.when; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.*; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.DateUtils.formatDateForNotificationAttachmentDocument; + +import java.time.LocalDate; +import java.util.Map; +import java.util.Optional; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.DateProvider; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCase; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.CaseDetails; +import uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.CustomerServicesProvider; + + +@ExtendWith(MockitoExtension.class) +@SuppressWarnings("unchecked") +@MockitoSettings(strictness = Strictness.LENIENT) +public class InternalApplyForFtpaAppellantLetterTemplateTest { + + @Mock + private CaseDetails caseDetails; + @Mock + private AsylumCase asylumCase; + @Mock + private DateProvider dateProvider; + @Mock + private CustomerServicesProvider customerServicesProvider; + private final String templateName = "TB-IAC-DEC-ENG-00017.docx"; + private final String customerServicesTelephoneNumber = "0300 123 1711"; + private final String customerServicesEmailAddress = "IAC-ADA-HW@justice.gov.uk"; + private final String appealReferenceNumber = "RP/11111/2020"; + private final String homeOfficeReferenceNumber = "A1234567/001"; + private final String appellantGivenNames = "John"; + private final String appellantFamilyName = "Doe"; + private InternalApplyForFtpaAppellantLetterTemplate internalApplyForFtpaAppellantLetterTemplate; + + @BeforeEach + void setUp() { + internalApplyForFtpaAppellantLetterTemplate = + new InternalApplyForFtpaAppellantLetterTemplate( + templateName, + dateProvider, + customerServicesProvider + ); + } + + void dataSetup() { + when(caseDetails.getCaseData()).thenReturn(asylumCase); + when(asylumCase.read(APPEAL_REFERENCE_NUMBER, String.class)).thenReturn(Optional.of(appealReferenceNumber)); + when(asylumCase.read(HOME_OFFICE_REFERENCE_NUMBER, String.class)).thenReturn(Optional.of(homeOfficeReferenceNumber)); + when(asylumCase.read(APPELLANT_GIVEN_NAMES, String.class)).thenReturn(Optional.of(appellantGivenNames)); + when(asylumCase.read(APPELLANT_FAMILY_NAME, String.class)).thenReturn(Optional.of(appellantFamilyName)); + + when(customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase)) + .thenReturn(customerServicesTelephoneNumber); + when(customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)) + .thenReturn(customerServicesEmailAddress); + + when(dateProvider.now()).thenReturn(LocalDate.now()); + } + + @Test + void should_return_template_name() { + assertEquals(templateName, internalApplyForFtpaAppellantLetterTemplate.getName()); + } + + @Test + void should_map_case_data_to_template_field_values() { + dataSetup(); + + Map templateFieldValues = internalApplyForFtpaAppellantLetterTemplate.mapFieldValues(caseDetails); + + assertEquals(8, templateFieldValues.size()); + assertEquals("[userImage:hmcts.png]", templateFieldValues.get("hmcts")); + assertEquals(appealReferenceNumber, templateFieldValues.get("appealReferenceNumber")); + assertEquals(homeOfficeReferenceNumber, templateFieldValues.get("homeOfficeReferenceNumber")); + assertEquals(appellantGivenNames, templateFieldValues.get("appellantGivenNames")); + assertEquals(appellantFamilyName, templateFieldValues.get("appellantFamilyName")); + assertEquals(customerServicesTelephoneNumber, templateFieldValues.get("customerServicesTelephone")); + assertEquals(customerServicesEmailAddress, templateFieldValues.get("customerServicesEmail")); + assertEquals(formatDateForNotificationAttachmentDocument(dateProvider.now()), templateFieldValues.get("dateLetterSent")); + } +}