diff --git a/src/functionalTest/resources/scenarios/RIA-7331-internal-appellant-ftpa-decided-partially-granted.json b/src/functionalTest/resources/scenarios/RIA-7331-internal-appellant-ftpa-decided-partially-granted.json new file mode 100644 index 000000000..e935c7845 --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7331-internal-appellant-ftpa-decided-partially-granted.json @@ -0,0 +1,48 @@ +{ + "description": "RIA-7331 Internal appellant ftpa decided - partially granted letter", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 7331, + "eventId": "residentJudgeFtpaDecision", + "state": "ftpaSubmitted", + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "ftpaAppellantRjDecisionOutcomeType": "partiallyGranted", + "ftpaApplicantType": "appellant" + } + } + } + }, + "expectation": { + "status": 200, + "errors": [], + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "ftpaAppellantRjDecisionOutcomeType": "partiallyGranted", + "ftpaApplicantType": "appellant", + "notificationAttachmentDocuments": [ + { + "id": "1", + "value": { + "tag": "internalAppellantFtpaDecidedLetter", + "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_filename": "PA 12345 2019-Awan-appellant-ftpa-decided-partially-granted-letter.PDF", + "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/" + }, + "suppliedBy": "", + "description": "", + "dateUploaded": "{$TODAY}" + } + } + ] + } + } + } +} diff --git a/src/functionalTest/resources/scenarios/RIA-7360-internal-ho-ftpa-decided-granted-document.json b/src/functionalTest/resources/scenarios/RIA-7360-internal-ho-ftpa-decided-granted-document.json new file mode 100644 index 000000000..2f5a19603 --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7360-internal-ho-ftpa-decided-granted-document.json @@ -0,0 +1,48 @@ +{ + "description": "RIA-7360 Internal HO ftpa decided - granted letter", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 7360, + "eventId": "residentJudgeFtpaDecision", + "state": "ftpaSubmitted", + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "ftpaRespondentRjDecisionOutcomeType": "granted", + "ftpaApplicantType": "respondent" + } + } + } + }, + "expectation": { + "status": 200, + "errors": [], + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "ftpaRespondentRjDecisionOutcomeType": "granted", + "ftpaApplicantType": "respondent", + "notificationAttachmentDocuments": [ + { + "id": "1", + "value": { + "tag": "internalHoFtpaDecidedLetter", + "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_filename": "PA 12345 2019-Awan-ho-ftpa-decided-granted-letter.PDF", + "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/" + }, + "suppliedBy": "", + "description": "", + "dateUploaded": "{$TODAY}" + } + } + ] + } + } + } +} \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/RIA-7361-internal-ho-ftpa-decided-partially-granted-document.json b/src/functionalTest/resources/scenarios/RIA-7361-internal-ho-ftpa-decided-partially-granted-document.json new file mode 100644 index 000000000..aa295f208 --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7361-internal-ho-ftpa-decided-partially-granted-document.json @@ -0,0 +1,48 @@ +{ + "description": "RIA-7361 Internal HO ftpa decided - partially granted letter", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 7361, + "eventId": "residentJudgeFtpaDecision", + "state": "ftpaSubmitted", + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "ftpaRespondentRjDecisionOutcomeType": "partiallyGranted", + "ftpaApplicantType": "respondent" + } + } + } + }, + "expectation": { + "status": 200, + "errors": [], + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "ftpaRespondentRjDecisionOutcomeType": "partiallyGranted", + "ftpaApplicantType": "respondent", + "notificationAttachmentDocuments": [ + { + "id": "1", + "value": { + "tag": "internalHoFtpaDecidedLetter", + "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_filename": "PA 12345 2019-Awan-ho-ftpa-decided-partially-granted-letter.PDF", + "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/" + }, + "suppliedBy": "", + "description": "", + "dateUploaded": "{$TODAY}" + } + } + ] + } + } + } +} \ No newline at end of file diff --git a/src/functionalTest/resources/scenarios/RIA-7362-internal-ho-ftpa-decided-refused-document.json b/src/functionalTest/resources/scenarios/RIA-7362-internal-ho-ftpa-decided-refused-document.json new file mode 100644 index 000000000..f007d1375 --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7362-internal-ho-ftpa-decided-refused-document.json @@ -0,0 +1,48 @@ +{ + "description": "RIA-7362 Internal HO ftpa decided - refused letter", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 7362, + "eventId": "residentJudgeFtpaDecision", + "state": "ftpaSubmitted", + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "ftpaRespondentRjDecisionOutcomeType": "refused", + "ftpaApplicantType": "respondent" + } + } + } + }, + "expectation": { + "status": 200, + "errors": [], + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "ftpaRespondentRjDecisionOutcomeType": "refused", + "ftpaApplicantType": "respondent", + "notificationAttachmentDocuments": [ + { + "id": "1", + "value": { + "tag": "internalHoFtpaDecidedLetter", + "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_filename": "PA 12345 2019-Awan-ho-ftpa-decided-refused-letter.PDF", + "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/" + }, + "suppliedBy": "", + "description": "", + "dateUploaded": "{$TODAY}" + } + } + ] + } + } + } +} \ No newline at end of file diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/AsylumCaseDefinition.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/AsylumCaseDefinition.java index 044eb3ae2..6cff1682a 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/AsylumCaseDefinition.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/AsylumCaseDefinition.java @@ -562,14 +562,21 @@ public enum AsylumCaseDefinition { DECIDE_AN_APPLICATION_ID( "decideAnApplicationId", new TypeReference(){}), + TRANSFER_OUT_OF_ADA_REASON( "transferOutOfAdaReason", new TypeReference(){}), + TRANSFER_OUT_OF_ADA_MORE_DETAILS( "transferOutOfAdaMoreDetails", new TypeReference(){}), + FTPA_APPELLANT_RJ_DECISION_OUTCOME_TYPE( "ftpaAppellantRjDecisionOutcomeType", new TypeReference(){}), + FTPA_APPLICANT_TYPE( - "ftpaApplicantType", new TypeReference(){}); + "ftpaApplicantType", new TypeReference(){}), + + FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE( + "ftpaRespondentRjDecisionOutcomeType", new TypeReference(){}); private final String value; private final TypeReference typeReference; 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 f8980e271..557938e29 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 @@ -59,6 +59,7 @@ public enum DocumentTag { INTERNAL_DETAINED_TRANSFER_OUT_OF_ADA_LETTER("internalDetainedTransferOutOfAdaLetter", CaseType.ASYLUM), INTERNAL_FTPA_SUBMITTED_APPELLANT_LETTER("internalFtpaSubmittedAppellantLetter", CaseType.ASYLUM), INTERNAL_APPELLANT_FTPA_DECIDED_LETTER("internalAppellantFtpaDecidedLetter", CaseType.ASYLUM), + INTERNAL_HO_FTPA_DECIDED_LETTER("internalHoFtpaDecidedLetter", CaseType.ASYLUM), BAIL_SUBMISSION("bailSubmission", CaseType.BAIL), BAIL_EVIDENCE("uploadTheBailEvidenceDocs", CaseType.BAIL), diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/FtpaDecisionOutcomeType.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/FtpaDecisionOutcomeType.java index 5e478c5f5..93c0fc86f 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/FtpaDecisionOutcomeType.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/entities/FtpaDecisionOutcomeType.java @@ -6,7 +6,8 @@ public enum FtpaDecisionOutcomeType { FTPA_GRANTED("granted"), FTPA_PARTIALLY_GRANTED("partiallyGranted"), - FTPA_REFUSED("refused"); + FTPA_REFUSED("refused"), + FTPA_NOT_ADMITTED("notAdmitted"); @JsonValue private final String value; diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGenerator.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGenerator.java index c6b44defd..2eac9e30b 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGenerator.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGenerator.java @@ -2,7 +2,7 @@ import static java.util.Objects.requireNonNull; import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.*; -import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.FtpaDecisionOutcomeType.FTPA_GRANTED; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.FtpaDecisionOutcomeType.*; import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isAppellantInDetention; import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isInternalCase; @@ -26,34 +26,46 @@ public class InternalFtpaDecidedLetterGenerator implements PreSubmitCallbackHandler { private final DocumentCreator internalAppellantFtpaDecidedGrantedLetter; + private final DocumentCreator internalAppellantFtpaDecidedPartiallyGrantedLetter; + private final DocumentCreator internalHoFtpaDecidedGrantedLetter; + private final DocumentCreator internalHoFtpaDecidedPartiallyGrantedLetter; + private final DocumentCreator internalHoFtpaDecidedRefusedLetter; private final DocumentHandler documentHandler; private final String ftpaApplicantAppellant = "appellant"; public InternalFtpaDecidedLetterGenerator( - @Qualifier("internalAppellantFtpaDecidedGrantedLetter") DocumentCreator internalAppellantFtpaDecidedGrantedLetter, - DocumentHandler documentHandler + @Qualifier("internalAppellantFtpaDecidedGrantedLetter") DocumentCreator internalAppellantFtpaDecidedGrantedLetter, + @Qualifier("internalAppellantFtpaDecidedPartiallyGrantedLetter") DocumentCreator internalAppellantFtpaDecidedPartiallyGrantedLetter, + @Qualifier("internalHoFtpaDecidedGrantedLetter") DocumentCreator internalHoFtpaDecidedGrantedLetter, + @Qualifier("internalHoFtpaDecidedPartiallyGrantedLetter") DocumentCreator internalHoFtpaDecidedPartiallyGrantedLetter, + @Qualifier("internalHoFtpaDecidedRefusedLetter") DocumentCreator internalHoFtpaDecidedRefusedLetter, + DocumentHandler documentHandler ) { this.internalAppellantFtpaDecidedGrantedLetter = internalAppellantFtpaDecidedGrantedLetter; + this.internalAppellantFtpaDecidedPartiallyGrantedLetter = internalAppellantFtpaDecidedPartiallyGrantedLetter; + this.internalHoFtpaDecidedGrantedLetter = internalHoFtpaDecidedGrantedLetter; + this.internalHoFtpaDecidedPartiallyGrantedLetter = internalHoFtpaDecidedPartiallyGrantedLetter; + this.internalHoFtpaDecidedRefusedLetter = internalHoFtpaDecidedRefusedLetter; this.documentHandler = documentHandler; } public boolean canHandle( - PreSubmitCallbackStage callbackStage, - Callback callback + 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.RESIDENT_JUDGE_FTPA_DECISION - && isInternalCase(asylumCase) - && isAppellantInDetention(asylumCase); + && callback.getEvent() == Event.RESIDENT_JUDGE_FTPA_DECISION + && isInternalCase(asylumCase) + && isAppellantInDetention(asylumCase); } public PreSubmitCallbackResponse handle( - PreSubmitCallbackStage callbackStage, - Callback callback + PreSubmitCallbackStage callbackStage, + Callback callback ) { if (!canHandle(callbackStage, callback)) { throw new IllegalStateException("Cannot handle callback"); @@ -63,27 +75,44 @@ public PreSubmitCallbackResponse handle( final AsylumCase asylumCase = caseDetails.getCaseData(); Optional ftpaAppellantDecisionOutcomeType = asylumCase - .read(FTPA_APPELLANT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class); + .read(FTPA_APPELLANT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class); + + Optional ftpaRespondentDecisionOutcomeType = asylumCase + .read(FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class); Optional ftpaApplicantType = asylumCase.read(FTPA_APPLICANT_TYPE, String.class); Document documentForUpload; + DocumentTag documentTag; if (ftpaApplicantType.equals(Optional.of(ftpaApplicantAppellant))) { if (ftpaAppellantDecisionOutcomeType.equals(Optional.of(FTPA_GRANTED))) { documentForUpload = internalAppellantFtpaDecidedGrantedLetter.create(caseDetails); + } else if (ftpaAppellantDecisionOutcomeType.equals(Optional.of(FTPA_PARTIALLY_GRANTED))) { + documentForUpload = internalAppellantFtpaDecidedPartiallyGrantedLetter.create(caseDetails); } else { return new PreSubmitCallbackResponse<>(asylumCase); } + documentTag = DocumentTag.INTERNAL_APPELLANT_FTPA_DECIDED_LETTER; } else { - return new PreSubmitCallbackResponse<>(asylumCase); + if (ftpaRespondentDecisionOutcomeType.equals(Optional.of(FTPA_GRANTED))) { + documentForUpload = internalHoFtpaDecidedGrantedLetter.create(caseDetails); + } else if (ftpaRespondentDecisionOutcomeType.equals(Optional.of(FTPA_PARTIALLY_GRANTED))) { + documentForUpload = internalHoFtpaDecidedPartiallyGrantedLetter.create(caseDetails); + } else if (ftpaRespondentDecisionOutcomeType.equals(Optional.of(FTPA_REFUSED)) + || ftpaRespondentDecisionOutcomeType.equals(Optional.of(FTPA_NOT_ADMITTED))) { + documentForUpload = internalHoFtpaDecidedRefusedLetter.create(caseDetails); + } else { + return new PreSubmitCallbackResponse<>(asylumCase); + } + documentTag = DocumentTag.INTERNAL_HO_FTPA_DECIDED_LETTER; } documentHandler.addWithMetadata( - asylumCase, - documentForUpload, - NOTIFICATION_ATTACHMENT_DOCUMENTS, - DocumentTag.INTERNAL_APPELLANT_FTPA_DECIDED_LETTER + asylumCase, + documentForUpload, + NOTIFICATION_ATTACHMENT_DOCUMENTS, + documentTag ); 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 c2ca84a86..d7a0eb2f8 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 @@ -157,8 +157,11 @@ private int bundlePositionIndex(DocumentWithMetadata document) { log.warn("INTERNAL_FTPA_SUBMITTED_APPELLANT_LETTER tag should not be checked for bundle ordering, document desc: {}", document.getDescription()); return 52; case INTERNAL_APPELLANT_FTPA_DECIDED_LETTER: - log.warn("INTERNAL_FTPA_DECIDED_LETTER tag should not be checked for bundle ordering, document desc: {}", document.getDescription()); + log.warn("INTERNAL_FTPA_DECIDED_LETTER tag should not be checked for bundle ordering, document desc: {}", document.getDescription()); return 53; + case INTERNAL_HO_FTPA_DECIDED_LETTER: + log.warn("INTERNAL_HO_FTPA_DECIDED_LETTER tag should not be checked for bundle ordering, document desc: {}", document.getDescription()); + return 54; 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/InternalAppellantFtpaDecidedPartiallyGrantedTemplate.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalAppellantFtpaDecidedPartiallyGrantedTemplate.java new file mode 100644 index 000000000..de71fed5a --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalAppellantFtpaDecidedPartiallyGrantedTemplate.java @@ -0,0 +1,62 @@ +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.AsylumCaseUtils.isAcceleratedDetainedAppeal; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.DateUtils.formatDateForNotificationAttachmentDocument; + +import java.time.LocalDate; +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 InternalAppellantFtpaDecidedPartiallyGrantedTemplate implements DocumentTemplate { + + private final String templateName; + private final DateProvider dateProvider; + private final CustomerServicesProvider customerServicesProvider; + private final int adaDueInCalendarDays; + private final int nonAdaDueInCalendarDays; + + public InternalAppellantFtpaDecidedPartiallyGrantedTemplate( + @Value("${internalAppellantFtpaDecidedPartiallyGrantedLetter.templateName}") String templateName, + DateProvider dateProvider, + CustomerServicesProvider customerServicesProvider, + @Value("${internalAppellantFtpaDecidedPartiallyGrantedLetter.ftpaAdaDueCalendarDays}") int adaDueInCalendarDays, + @Value("${internalAppellantFtpaDecidedPartiallyGrantedLetter.ftpaNonAdaDueCalendarDays}") int nonAdaDueInCalendarDays) { + this.templateName = templateName; + this.dateProvider = dateProvider; + this.customerServicesProvider = customerServicesProvider; + this.adaDueInCalendarDays = adaDueInCalendarDays; + this.nonAdaDueInCalendarDays = nonAdaDueInCalendarDays; + } + + public String getName() { + return templateName; + } + + public Map mapFieldValues( + CaseDetails caseDetails + ) { + final AsylumCase asylumCase = caseDetails.getCaseData(); + final Map fieldValues = new HashMap<>(); + + LocalDate dueDate = isAcceleratedDetainedAppeal(asylumCase) + ? LocalDate.now().plusDays(adaDueInCalendarDays) + : LocalDate.now().plusDays(nonAdaDueInCalendarDays); + + fieldValues.putAll(getAppellantPersonalisation(asylumCase)); + fieldValues.put("dateLetterSent", formatDateForNotificationAttachmentDocument(dateProvider.now())); + fieldValues.put("customerServicesTelephone", customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase)); + fieldValues.put("customerServicesEmail", customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)); + fieldValues.put("utApplicationDeadline", formatDateForNotificationAttachmentDocument(dueDate)); + + return fieldValues; + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedGrantedLetterTemplate.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedGrantedLetterTemplate.java new file mode 100644 index 000000000..eba60f729 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedGrantedLetterTemplate.java @@ -0,0 +1,47 @@ +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.time.LocalDate; +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.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 InternalHoFtpaDecidedGrantedLetterTemplate implements DocumentTemplate { + + private final String templateName; + private final CustomerServicesProvider customerServicesProvider; + + public InternalHoFtpaDecidedGrantedLetterTemplate( + @Value("${internalDetainedHoFtpaDecidedGrantedLetter.templateName}") String templateName, + CustomerServicesProvider customerServicesProvider) { + this.templateName = templateName; + this.customerServicesProvider = customerServicesProvider; + } + + @Override + public String getName() { + return templateName; + } + + @Override + public Map mapFieldValues( + CaseDetails caseDetails + ) { + final AsylumCase asylumCase = caseDetails.getCaseData(); + + final Map fieldValues = new HashMap<>(getAppellantPersonalisation(asylumCase)); + fieldValues.putAll(getAppellantPersonalisation(asylumCase)); + fieldValues.put("customerServicesTelephone", customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase)); + fieldValues.put("customerServicesEmail", customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)); + fieldValues.put("dateLetterSent", formatDateForNotificationAttachmentDocument(LocalDate.now())); + return fieldValues; + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPartiallyGrantedLetterTemplate.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPartiallyGrantedLetterTemplate.java new file mode 100644 index 000000000..d90ffe4de --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPartiallyGrantedLetterTemplate.java @@ -0,0 +1,47 @@ +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.time.LocalDate; +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.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 InternalHoFtpaDecidedPartiallyGrantedLetterTemplate implements DocumentTemplate { + + private final String templateName; + private final CustomerServicesProvider customerServicesProvider; + + public InternalHoFtpaDecidedPartiallyGrantedLetterTemplate( + @Value("${internalDetainedHoFtpaDecidedPartiallyGrantedLetter.templateName}") String templateName, + CustomerServicesProvider customerServicesProvider) { + this.templateName = templateName; + this.customerServicesProvider = customerServicesProvider; + } + + @Override + public String getName() { + return templateName; + } + + @Override + public Map mapFieldValues( + CaseDetails caseDetails + ) { + final AsylumCase asylumCase = caseDetails.getCaseData(); + + final Map fieldValues = new HashMap<>(getAppellantPersonalisation(asylumCase)); + fieldValues.putAll(getAppellantPersonalisation(asylumCase)); + fieldValues.put("customerServicesTelephone", customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase)); + fieldValues.put("customerServicesEmail", customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)); + fieldValues.put("dateLetterSent", formatDateForNotificationAttachmentDocument(LocalDate.now())); + return fieldValues; + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedRefusedLetterTemplate.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedRefusedLetterTemplate.java new file mode 100644 index 000000000..0580d65c5 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedRefusedLetterTemplate.java @@ -0,0 +1,55 @@ +package uk.gov.hmcts.reform.iacasedocumentsapi.domain.templates.letter; + +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.FtpaDecisionOutcomeType.FTPA_REFUSED; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.getAppellantPersonalisation; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.DateUtils.formatDateForNotificationAttachmentDocument; + +import java.time.LocalDate; +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.entities.AsylumCase; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.FtpaDecisionOutcomeType; +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 InternalHoFtpaDecidedRefusedLetterTemplate implements DocumentTemplate { + + private final String templateName; + private final CustomerServicesProvider customerServicesProvider; + private final String refused = "refused"; + private final String notAdmitted = "not admitted"; + + public InternalHoFtpaDecidedRefusedLetterTemplate( + @Value("${internalDetainedHoFtpaDecidedRefusedLetter.templateName}") String templateName, + CustomerServicesProvider customerServicesProvider) { + this.templateName = templateName; + this.customerServicesProvider = customerServicesProvider; + } + + @Override + public String getName() { + return templateName; + } + + @Override + public Map mapFieldValues( + CaseDetails caseDetails + ) { + final AsylumCase asylumCase = caseDetails.getCaseData(); + + final Map fieldValues = new HashMap<>(getAppellantPersonalisation(asylumCase)); + fieldValues.putAll(getAppellantPersonalisation(asylumCase)); + fieldValues.put("customerServicesTelephone", customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase)); + fieldValues.put("customerServicesEmail", customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)); + fieldValues.put("dateLetterSent", formatDateForNotificationAttachmentDocument(LocalDate.now())); + fieldValues.put("refused", asylumCase.read(FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class) + .map(it -> it.equals(FTPA_REFUSED) ? refused : notAdmitted) + .orElseThrow(() -> new IllegalStateException("Judge decision 'refused' or 'not admitted' must be present"))); + 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 affd0bd90..4f4ae29f2 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 @@ -1086,4 +1086,88 @@ public DocumentCreator getInternalAppellantFtpaDecidedGrantedLetterC documentUploader ); } + + @Bean("internalHoFtpaDecidedGrantedLetter") + public DocumentCreator getInternalHoFtpaDecidedGrantedDocumentCreator( + @Value("${internalDetainedHoFtpaDecidedGrantedLetter.contentType}") String contentType, + @Value("${internalDetainedHoFtpaDecidedGrantedLetter.fileExtension}") String fileExtension, + @Value("${internalDetainedHoFtpaDecidedGrantedLetter.fileName}") String fileName, + AsylumCaseFileNameQualifier fileNameQualifier, + InternalHoFtpaDecidedGrantedLetterTemplate documentTemplate, + DocumentGenerator documentGenerator, + DocumentUploader documentUploader + ) { + return new DocumentCreator<>( + contentType, + fileExtension, + fileName, + fileNameQualifier, + documentTemplate, + documentGenerator, + documentUploader + ); + } + + @Bean("internalHoFtpaDecidedPartiallyGrantedLetter") + public DocumentCreator getInternalHoFtpaDecidedPartiallyGrantedDocumentCreator( + @Value("${internalDetainedHoFtpaDecidedPartiallyGrantedLetter.contentType}") String contentType, + @Value("${internalDetainedHoFtpaDecidedPartiallyGrantedLetter.fileExtension}") String fileExtension, + @Value("${internalDetainedHoFtpaDecidedPartiallyGrantedLetter.fileName}") String fileName, + AsylumCaseFileNameQualifier fileNameQualifier, + InternalHoFtpaDecidedPartiallyGrantedLetterTemplate documentTemplate, + DocumentGenerator documentGenerator, + DocumentUploader documentUploader + ) { + return new DocumentCreator<>( + contentType, + fileExtension, + fileName, + fileNameQualifier, + documentTemplate, + documentGenerator, + documentUploader + ); + } + + @Bean("internalHoFtpaDecidedRefusedLetter") + public DocumentCreator getInternalHoFtpaDecidedRefusedDocumentCreator( + @Value("${internalDetainedHoFtpaDecidedRefusedLetter.contentType}") String contentType, + @Value("${internalDetainedHoFtpaDecidedRefusedLetter.fileExtension}") String fileExtension, + @Value("${internalDetainedHoFtpaDecidedRefusedLetter.fileName}") String fileName, + AsylumCaseFileNameQualifier fileNameQualifier, + InternalHoFtpaDecidedRefusedLetterTemplate documentTemplate, + DocumentGenerator documentGenerator, + DocumentUploader documentUploader + ) { + return new DocumentCreator<>( + contentType, + fileExtension, + fileName, + fileNameQualifier, + documentTemplate, + documentGenerator, + documentUploader + ); + } + + @Bean("internalAppellantFtpaDecidedPartiallyGrantedLetter") + public DocumentCreator getInternalAppellantFtpaDecidedPartiallyGrantedLetterCreator( + @Value("${internalAppellantFtpaDecidedPartiallyGrantedLetter.contentType}") String contentType, + @Value("${internalAppellantFtpaDecidedPartiallyGrantedLetter.fileExtension}") String fileExtension, + @Value("${internalAppellantFtpaDecidedPartiallyGrantedLetter.fileName}") String fileName, + AsylumCaseFileNameQualifier fileNameQualifier, + InternalAppellantFtpaDecidedPartiallyGrantedTemplate 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 e538ae02b..3a0204caa 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -329,6 +329,28 @@ internalAppellantFtpaDecidedGrantedLetter.fileExtension: PDF internalAppellantFtpaDecidedGrantedLetter.fileName: "appellant-ftpa-decided-granted-letter" internalAppellantFtpaDecidedGrantedLetter.templateName: ${IA_INTERNAL_APPELLANT_FTPA_DECIDED_GRANTED_LETTER_TEMPLATE:TB-IAC-LET-ENG-00018.docx} +internalDetainedHoFtpaDecidedGrantedLetter.contentType: application/pdf +internalDetainedHoFtpaDecidedGrantedLetter.fileExtension: PDF +internalDetainedHoFtpaDecidedGrantedLetter.fileName: "ho-ftpa-decided-granted-letter" +internalDetainedHoFtpaDecidedGrantedLetter.templateName: ${IA_INTERNAL_DETAINED_HO_FTPA_DECIDED_GRANTED_LETTER_TEMPLATE:TB-IAC-LET-ENG-00019.docx} + +internalDetainedHoFtpaDecidedPartiallyGrantedLetter.contentType: application/pdf +internalDetainedHoFtpaDecidedPartiallyGrantedLetter.fileExtension: PDF +internalDetainedHoFtpaDecidedPartiallyGrantedLetter.fileName: "ho-ftpa-decided-partially-granted-letter" +internalDetainedHoFtpaDecidedPartiallyGrantedLetter.templateName: ${IA_INTERNAL_DETAINED_HO_FTPA_DECIDED_PARTIALLY_GRANTED_LETTER_TEMPLATE:TB-IAC-LET-ENG-00021.docx} + +internalDetainedHoFtpaDecidedRefusedLetter.contentType: application/pdf +internalDetainedHoFtpaDecidedRefusedLetter.fileExtension: PDF +internalDetainedHoFtpaDecidedRefusedLetter.fileName: "ho-ftpa-decided-refused-letter" +internalDetainedHoFtpaDecidedRefusedLetter.templateName: ${IA_INTERNAL_DETAINED_HO_FTPA_DECIDED_REFUSED_LETTER_TEMPLATE:TB-IAC-LET-ENG-00022.docx} + +internalAppellantFtpaDecidedPartiallyGrantedLetter.contentType: application/pdf +internalAppellantFtpaDecidedPartiallyGrantedLetter.fileExtension: PDF +internalAppellantFtpaDecidedPartiallyGrantedLetter.fileName: "appellant-ftpa-decided-partially-granted-letter" +internalAppellantFtpaDecidedPartiallyGrantedLetter.templateName: ${IA_INTERNAL_APPELLANT_FTPA_DECIDED_PARTIALLY_GRANTED_LETTER_TEMPLATE:TB-IAC-LET-ENG-00020.docx} +internalAppellantFtpaDecidedPartiallyGrantedLetter.ftpaAdaDueCalendarDays: 7 +internalAppellantFtpaDecidedPartiallyGrantedLetter.ftpaNonAdaDueCalendarDays: 14 + ccdGatewayUrl: ${CCD_GW_URL:http://localhost:3453} docmosis.accessKey: ${DOCMOSIS_ACCESS_KEY} @@ -377,6 +399,7 @@ security: - "submitApplication" - "makeNewApplication" - "requestHearingRequirementsFeature" + - "applyForFTPAAppellant" caseworker-ia-caseofficer: - "sendDirection" - "changeDirectionDueDate" 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 518fef2e1..f2dd6d973 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 @@ -62,10 +62,11 @@ public void has_correct_values() { assertEquals("internalDetainedTransferOutOfAdaLetter", DocumentTag.INTERNAL_DETAINED_TRANSFER_OUT_OF_ADA_LETTER.toString()); assertEquals("internalFtpaSubmittedAppellantLetter", DocumentTag.INTERNAL_FTPA_SUBMITTED_APPELLANT_LETTER.toString()); assertEquals("internalAppellantFtpaDecidedLetter", DocumentTag.INTERNAL_APPELLANT_FTPA_DECIDED_LETTER.toString()); + assertEquals("internalHoFtpaDecidedLetter", DocumentTag.INTERNAL_HO_FTPA_DECIDED_LETTER.toString()); } @Test public void if_this_test_fails_it_is_because_it_needs_updating_with_your_changes() { - assertEquals(61, DocumentTag.values().length); + assertEquals(62, DocumentTag.values().length); } } diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGeneratorTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGeneratorTest.java index 3ba7a274d..6581233c7 100644 --- a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGeneratorTest.java +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalFtpaDecidedLetterGeneratorTest.java @@ -9,6 +9,8 @@ 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; @@ -32,7 +34,15 @@ class InternalFtpaDecidedLetterGeneratorTest { @Mock - private DocumentCreator internalFtpaDecidedCreator; + private DocumentCreator internalAppelantFtpaDecidedGrantedCreator; + @Mock + private DocumentCreator internalAppelantFtpaDecidedPartiallyGrantedCreator; + @Mock + private DocumentCreator internalHoFtpaDecidedGrantedCreator; + @Mock + private DocumentCreator internalHoFtpaDecidedPartiallyGrantedCreator; + @Mock + private DocumentCreator internalHoFtpaDecidedRefusedCreator; @Mock private DocumentHandler documentHandler; @Mock @@ -44,14 +54,19 @@ class InternalFtpaDecidedLetterGeneratorTest { @Mock private Document uploadedDocument; private final String ftpaApplicantAppellant = "appellant"; + private final String ftpaApplicantRespondent = "respondent"; private InternalFtpaDecidedLetterGenerator internalFtpaDecidedLetterGenerator; @BeforeEach public void setUp() { internalFtpaDecidedLetterGenerator = new InternalFtpaDecidedLetterGenerator( - internalFtpaDecidedCreator, - documentHandler + internalAppelantFtpaDecidedGrantedCreator, + internalAppelantFtpaDecidedPartiallyGrantedCreator, + internalHoFtpaDecidedGrantedCreator, + internalHoFtpaDecidedPartiallyGrantedCreator, + internalHoFtpaDecidedRefusedCreator, + documentHandler ); when(callback.getEvent()).thenReturn(Event.RESIDENT_JUDGE_FTPA_DECISION); @@ -67,7 +82,7 @@ void should_create_internal_appellant_ftpa_decided_granted_letter_and_append_to_ when(asylumCase.read(FTPA_APPELLANT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class)).thenReturn(Optional.of(FtpaDecisionOutcomeType.FTPA_GRANTED)); when(asylumCase.read(FTPA_APPLICANT_TYPE, String.class)).thenReturn(Optional.of(ftpaApplicantAppellant)); - when(internalFtpaDecidedCreator.create(caseDetails)).thenReturn(uploadedDocument); + when(internalAppelantFtpaDecidedGrantedCreator.create(caseDetails)).thenReturn(uploadedDocument); PreSubmitCallbackResponse callbackResponse = internalFtpaDecidedLetterGenerator.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback); @@ -83,6 +98,91 @@ void should_create_internal_appellant_ftpa_decided_granted_letter_and_append_to_ ); } + @Test + void should_create_internal_appellant_ftpa_decided_partially_granted_letter_and_append_to_notification_attachment_documents() { + when(asylumCase.read(FTPA_APPELLANT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class)).thenReturn(Optional.of(FtpaDecisionOutcomeType.FTPA_PARTIALLY_GRANTED)); + when(asylumCase.read(FTPA_APPLICANT_TYPE, String.class)).thenReturn(Optional.of(ftpaApplicantAppellant)); + + when(internalAppelantFtpaDecidedPartiallyGrantedCreator.create(caseDetails)).thenReturn(uploadedDocument); + + PreSubmitCallbackResponse callbackResponse = + internalFtpaDecidedLetterGenerator.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback); + + assertNotNull(callbackResponse); + assertEquals(asylumCase, callbackResponse.getData()); + + verify(documentHandler, times(1)).addWithMetadata( + asylumCase, + uploadedDocument, + NOTIFICATION_ATTACHMENT_DOCUMENTS, + DocumentTag.INTERNAL_APPELLANT_FTPA_DECIDED_LETTER + ); + } + + @Test + void should_create_internal_ho_ftpa_decided_granted_letter_and_append_to_notification_attachment_documents() { + when(asylumCase.read(FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class)).thenReturn(Optional.of(FtpaDecisionOutcomeType.FTPA_GRANTED)); + when(asylumCase.read(FTPA_APPLICANT_TYPE, String.class)).thenReturn(Optional.of(ftpaApplicantRespondent)); + + when(internalHoFtpaDecidedGrantedCreator.create(caseDetails)).thenReturn(uploadedDocument); + + PreSubmitCallbackResponse callbackResponse = + internalFtpaDecidedLetterGenerator.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback); + + assertNotNull(callbackResponse); + assertEquals(asylumCase, callbackResponse.getData()); + + verify(documentHandler, times(1)).addWithMetadata( + asylumCase, + uploadedDocument, + NOTIFICATION_ATTACHMENT_DOCUMENTS, + DocumentTag.INTERNAL_HO_FTPA_DECIDED_LETTER + ); + } + + @Test + void should_create_internal_ho_ftpa_decided_partially_granted_letter_and_append_to_notification_attachment_documents() { + when(asylumCase.read(FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class)).thenReturn(Optional.of(FtpaDecisionOutcomeType.FTPA_PARTIALLY_GRANTED)); + when(asylumCase.read(FTPA_APPLICANT_TYPE, String.class)).thenReturn(Optional.of(ftpaApplicantRespondent)); + + when(internalHoFtpaDecidedPartiallyGrantedCreator.create(caseDetails)).thenReturn(uploadedDocument); + + PreSubmitCallbackResponse callbackResponse = + internalFtpaDecidedLetterGenerator.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback); + + assertNotNull(callbackResponse); + assertEquals(asylumCase, callbackResponse.getData()); + + verify(documentHandler, times(1)).addWithMetadata( + asylumCase, + uploadedDocument, + NOTIFICATION_ATTACHMENT_DOCUMENTS, + DocumentTag.INTERNAL_HO_FTPA_DECIDED_LETTER + ); + } + + @ParameterizedTest + @EnumSource(value = FtpaDecisionOutcomeType.class, names = {"FTPA_REFUSED", "FTPA_NOT_ADMITTED"}) + void should_create_internal_ho_ftpa_decided_refused_letter_and_append_to_notification_attachment_documents(FtpaDecisionOutcomeType ftpaDecisionOutcomeType) { + when(asylumCase.read(FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class)).thenReturn(Optional.of(ftpaDecisionOutcomeType)); + when(asylumCase.read(FTPA_APPLICANT_TYPE, String.class)).thenReturn(Optional.of(ftpaApplicantRespondent)); + + when(internalHoFtpaDecidedRefusedCreator.create(caseDetails)).thenReturn(uploadedDocument); + + PreSubmitCallbackResponse callbackResponse = + internalFtpaDecidedLetterGenerator.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback); + + assertNotNull(callbackResponse); + assertEquals(asylumCase, callbackResponse.getData()); + + verify(documentHandler, times(1)).addWithMetadata( + asylumCase, + uploadedDocument, + NOTIFICATION_ATTACHMENT_DOCUMENTS, + DocumentTag.INTERNAL_HO_FTPA_DECIDED_LETTER + ); + } + @Test void handling_should_throw_if_cannot_actually_handle() { when(callback.getCaseDetails()).thenReturn(caseDetails); 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 99c7fb384..e56c62bce 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(55, sortedTags.size()); + assertEquals(56, sortedTags.size()); List documentTagList = Arrays.asList( DocumentTag.CASE_SUMMARY, diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalAppellantFtpaDecidedPartiallyGrantedTemplateTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalAppellantFtpaDecidedPartiallyGrantedTemplateTest.java new file mode 100644 index 000000000..2e42b97cd --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalAppellantFtpaDecidedPartiallyGrantedTemplateTest.java @@ -0,0 +1,117 @@ +package uk.gov.hmcts.reform.iacasedocumentsapi.domain.templates.letter; + +import static org.junit.Assert.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.Assertions; +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.domain.entities.ccd.field.YesOrNo; +import uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.CustomerServicesProvider; + +@MockitoSettings(strictness = Strictness.LENIENT) +@SuppressWarnings("unchecked") +@ExtendWith(MockitoExtension.class) +class InternalAppellantFtpaDecidedPartiallyGrantedTemplateTest { + + @Mock + private CaseDetails caseDetails; + @Mock + private AsylumCase asylumCase; + @Mock + private DateProvider dateProvider; + @Mock + private CustomerServicesProvider customerServicesProvider; + private final String templateName = "TB-IAC-LET-ENG-00020.docx"; + private final String customerServicesTelephone = "0300 123 1711"; + private final String customerServicesEmail = "email@example.com"; + private final String appealReferenceNumber = "RP/11111/2020"; + private final String homeOfficeReferenceNumber = "A1234567/001"; + private final String appellantGivenNames = "John"; + private final String appellantFamilyName = "Doe"; + private final int adaDueInCalendarDays = 7; + private final int nonAdaDueInCalendarDays = 14; + private final LocalDate now = LocalDate.now(); + private InternalAppellantFtpaDecidedPartiallyGrantedTemplate internalAppellantFtpaDecidedPartiallyGrantedTemplate; + + @BeforeEach + void setUp() { + internalAppellantFtpaDecidedPartiallyGrantedTemplate = + new InternalAppellantFtpaDecidedPartiallyGrantedTemplate( + templateName, + dateProvider, + customerServicesProvider, + adaDueInCalendarDays, + nonAdaDueInCalendarDays + ); + } + + 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(asylumCase.read(APPELLANT_IN_DETENTION, YesOrNo.class)).thenReturn(Optional.of(YesOrNo.YES)); + + when(customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase)) + .thenReturn(customerServicesTelephone); + when(customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)) + .thenReturn(customerServicesEmail); + + when(dateProvider.now()).thenReturn(LocalDate.now()); + } + + @Test + void should_return_template_name() { + Assertions.assertEquals(templateName, internalAppellantFtpaDecidedPartiallyGrantedTemplate.getName()); + } + + @Test + void should_map_case_data_to_template_field_values() { + dataSetup(); + + Map templateFieldValues = internalAppellantFtpaDecidedPartiallyGrantedTemplate.mapFieldValues(caseDetails); + + assertEquals(9, 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(customerServicesTelephone, templateFieldValues.get("customerServicesTelephone")); + assertEquals(customerServicesEmail, templateFieldValues.get("customerServicesEmail")); + + assertEquals(formatDateForNotificationAttachmentDocument(dateProvider.now()), templateFieldValues.get("dateLetterSent")); + + } + + @Test + void should_return_7_calendar_days_for_ada() { + dataSetup(); + when(asylumCase.read(IS_ACCELERATED_DETAINED_APPEAL, YesOrNo.class)).thenReturn(Optional.of(YesOrNo.YES)); + Map templateFieldValues = internalAppellantFtpaDecidedPartiallyGrantedTemplate.mapFieldValues(caseDetails); + Assertions.assertEquals(formatDateForNotificationAttachmentDocument(now.plusDays(adaDueInCalendarDays)), templateFieldValues.get("utApplicationDeadline")); + } + + @Test + void should_return_14_calendar_days_for_non_ada() { + dataSetup(); + when(asylumCase.read(IS_ACCELERATED_DETAINED_APPEAL, YesOrNo.class)).thenReturn(Optional.of(YesOrNo.NO)); + Map templateFieldValues = internalAppellantFtpaDecidedPartiallyGrantedTemplate.mapFieldValues(caseDetails); + Assertions.assertEquals(formatDateForNotificationAttachmentDocument(now.plusDays(nonAdaDueInCalendarDays)), templateFieldValues.get("utApplicationDeadline")); + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedGrantedLetterTemplateTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedGrantedLetterTemplateTest.java new file mode 100644 index 000000000..c68e8f0cb --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedGrantedLetterTemplateTest.java @@ -0,0 +1,78 @@ +package uk.gov.hmcts.reform.iacasedocumentsapi.domain.templates.letter; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.*; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +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.entities.AsylumCase; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.CaseDetails; +import uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.CustomerServicesProvider; + +@MockitoSettings(strictness = Strictness.LENIENT) +@SuppressWarnings("unchecked") +@ExtendWith(MockitoExtension.class) +class InternalHoFtpaDecidedGrantedLetterTemplateTest { + + @Mock + private CaseDetails caseDetails; + @Mock + private AsylumCase asylumCase; + @Mock + private CustomerServicesProvider customerServicesProvider; + private final String telephoneNumber = "0300 123 1711"; + private final String email = "IAC-ADA-HW@justice.gov.uk"; + private String appellantGivenNames = "John"; + private String appellantFamilyName = "Smith"; + private String homeOfficeReferenceNumber = "123654"; + private String appealReferenceNumber = "HU/11111/2022"; + private String appealSubmissionDate = "2023-07-01"; + private String remissionRejectedDate = "14 Jul 2023"; + private final String templateName = "INTERNAL_HO_FTPA_DECIDED_GRANTED_NOTICE_TEMPLATE.docx"; + private final String logo = "[userImage:hmcts.png]"; + private InternalHoFtpaDecidedGrantedLetterTemplate internalHoFtpaDecidedGrantedLetterTemplate; + private Map fieldValuesMap; + + @BeforeEach + public void setUp() { + internalHoFtpaDecidedGrantedLetterTemplate = + new InternalHoFtpaDecidedGrantedLetterTemplate(templateName, customerServicesProvider); + } + + @Test + void should_return_template_name() { + assertEquals(templateName, internalHoFtpaDecidedGrantedLetterTemplate.getName()); + } + + void dataSetup() { + when(caseDetails.getCaseData()).thenReturn(asylumCase); + when(customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase)).thenReturn(telephoneNumber); + when(customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)).thenReturn(email); + when(asylumCase.read(APPEAL_REFERENCE_NUMBER, String.class)).thenReturn(Optional.of(appealReferenceNumber)); + 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(asylumCase.read(HOME_OFFICE_REFERENCE_NUMBER, String.class)).thenReturn(Optional.of(homeOfficeReferenceNumber)); + } + + @Test + void should_populate_template() { + dataSetup(); + fieldValuesMap = internalHoFtpaDecidedGrantedLetterTemplate.mapFieldValues(caseDetails); + assertEquals(logo, fieldValuesMap.get("hmcts")); + assertEquals(appealReferenceNumber, fieldValuesMap.get("appealReferenceNumber")); + assertEquals(appellantGivenNames, fieldValuesMap.get("appellantGivenNames")); + assertEquals(appellantFamilyName, fieldValuesMap.get("appellantFamilyName")); + assertEquals(homeOfficeReferenceNumber, fieldValuesMap.get("homeOfficeReferenceNumber")); + assertEquals(LocalDate.now().format(DateTimeFormatter.ofPattern("d MMM yyyy")), fieldValuesMap.get("dateLetterSent")); + } +} \ No newline at end of file diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPartiallyGrantedLetterTemplateTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPartiallyGrantedLetterTemplateTest.java new file mode 100644 index 000000000..ec7f3e418 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedPartiallyGrantedLetterTemplateTest.java @@ -0,0 +1,76 @@ +package uk.gov.hmcts.reform.iacasedocumentsapi.domain.templates.letter; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.*; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +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.entities.AsylumCase; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.CaseDetails; +import uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.CustomerServicesProvider; + +@MockitoSettings(strictness = Strictness.LENIENT) +@SuppressWarnings("unchecked") +@ExtendWith(MockitoExtension.class) +class InternalHoFtpaDecidedPartiallyGrantedLetterTemplateTest { + + @Mock + private CaseDetails caseDetails; + @Mock + private AsylumCase asylumCase; + @Mock + private CustomerServicesProvider customerServicesProvider; + private final String telephoneNumber = "0300 123 1711"; + private final String email = "IAC-ADA-HW@justice.gov.uk"; + private String appellantGivenNames = "John"; + private String appellantFamilyName = "Smith"; + private String homeOfficeReferenceNumber = "123654"; + private String appealReferenceNumber = "HU/11111/2022"; + private final String templateName = "INTERNAL_HO_FTPA_DECIDED_PARTIALLY_GRANTED_NOTICE_TEMPLATE.docx"; + private final String logo = "[userImage:hmcts.png]"; + private InternalHoFtpaDecidedPartiallyGrantedLetterTemplate internalHoFtpaDecidedPartiallyGrantedLetterTemplate; + private Map fieldValuesMap; + + @BeforeEach + public void setUp() { + internalHoFtpaDecidedPartiallyGrantedLetterTemplate = + new InternalHoFtpaDecidedPartiallyGrantedLetterTemplate(templateName, customerServicesProvider); + } + + @Test + void should_return_template_name() { + assertEquals(templateName, internalHoFtpaDecidedPartiallyGrantedLetterTemplate.getName()); + } + + void dataSetup() { + when(caseDetails.getCaseData()).thenReturn(asylumCase); + when(customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase)).thenReturn(telephoneNumber); + when(customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)).thenReturn(email); + when(asylumCase.read(APPEAL_REFERENCE_NUMBER, String.class)).thenReturn(Optional.of(appealReferenceNumber)); + 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(asylumCase.read(HOME_OFFICE_REFERENCE_NUMBER, String.class)).thenReturn(Optional.of(homeOfficeReferenceNumber)); + } + + @Test + void should_populate_template() { + dataSetup(); + fieldValuesMap = internalHoFtpaDecidedPartiallyGrantedLetterTemplate.mapFieldValues(caseDetails); + assertEquals(logo, fieldValuesMap.get("hmcts")); + assertEquals(appealReferenceNumber, fieldValuesMap.get("appealReferenceNumber")); + assertEquals(appellantGivenNames, fieldValuesMap.get("appellantGivenNames")); + assertEquals(appellantFamilyName, fieldValuesMap.get("appellantFamilyName")); + assertEquals(homeOfficeReferenceNumber, fieldValuesMap.get("homeOfficeReferenceNumber")); + assertEquals(LocalDate.now().format(DateTimeFormatter.ofPattern("d MMM yyyy")), fieldValuesMap.get("dateLetterSent")); + } +} \ No newline at end of file diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedRefusedLetterTemplateTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedRefusedLetterTemplateTest.java new file mode 100644 index 000000000..db73ddc38 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalHoFtpaDecidedRefusedLetterTemplateTest.java @@ -0,0 +1,100 @@ +package uk.gov.hmcts.reform.iacasedocumentsapi.domain.templates.letter; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.*; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +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.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.FtpaDecisionOutcomeType; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.CaseDetails; +import uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.CustomerServicesProvider; + +@MockitoSettings(strictness = Strictness.LENIENT) +@SuppressWarnings("unchecked") +@ExtendWith(MockitoExtension.class) +class InternalHoFtpaDecidedRefusedLetterTemplateTest { + + @Mock + private CaseDetails caseDetails; + @Mock + private AsylumCase asylumCase; + @Mock + private CustomerServicesProvider customerServicesProvider; + private final String telephoneNumber = "0300 123 1711"; + private final String email = "IAC-ADA-HW@justice.gov.uk"; + private String appellantGivenNames = "John"; + private String appellantFamilyName = "Smith"; + private String homeOfficeReferenceNumber = "123654"; + private String appealReferenceNumber = "HU/11111/2022"; + private final String templateName = "INTERNAL_HO_FTPA_DECIDED_REFUSED_NOTICE_TEMPLATE.docx"; + private final String logo = "[userImage:hmcts.png]"; + private final String refused = "refused"; + private final String notAdmitted = "not admitted"; + private InternalHoFtpaDecidedRefusedLetterTemplate internalHoFtpaDecidedRefusedLetterTemplate; + private Map fieldValuesMap; + + @BeforeEach + public void setUp() { + internalHoFtpaDecidedRefusedLetterTemplate = + new InternalHoFtpaDecidedRefusedLetterTemplate(templateName, customerServicesProvider); + } + + @Test + void should_return_template_name() { + assertEquals(templateName, internalHoFtpaDecidedRefusedLetterTemplate.getName()); + } + + void dataSetup() { + when(caseDetails.getCaseData()).thenReturn(asylumCase); + when(customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase)).thenReturn(telephoneNumber); + when(customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)).thenReturn(email); + when(asylumCase.read(APPEAL_REFERENCE_NUMBER, String.class)).thenReturn(Optional.of(appealReferenceNumber)); + 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(asylumCase.read(HOME_OFFICE_REFERENCE_NUMBER, String.class)).thenReturn(Optional.of(homeOfficeReferenceNumber)); + when(asylumCase.read(FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class)).thenReturn(Optional.of(FtpaDecisionOutcomeType.FTPA_REFUSED)); + } + + @ParameterizedTest + @EnumSource(value = FtpaDecisionOutcomeType.class, names = {"FTPA_REFUSED", "FTPA_NOT_ADMITTED"}) + void should_populate_template(FtpaDecisionOutcomeType ftpaDecisionOutcomeType) { + dataSetup(); + + when(asylumCase.read(FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class)).thenReturn(Optional.of(ftpaDecisionOutcomeType)); + + fieldValuesMap = internalHoFtpaDecidedRefusedLetterTemplate.mapFieldValues(caseDetails); + assertEquals(logo, fieldValuesMap.get("hmcts")); + assertEquals(appealReferenceNumber, fieldValuesMap.get("appealReferenceNumber")); + assertEquals(appellantGivenNames, fieldValuesMap.get("appellantGivenNames")); + assertEquals(appellantFamilyName, fieldValuesMap.get("appellantFamilyName")); + assertEquals(homeOfficeReferenceNumber, fieldValuesMap.get("homeOfficeReferenceNumber")); + assertEquals(LocalDate.now().format(DateTimeFormatter.ofPattern("d MMM yyyy")), fieldValuesMap.get("dateLetterSent")); + assertEquals(ftpaDecisionOutcomeType.equals(FtpaDecisionOutcomeType.FTPA_REFUSED) + ? refused + : notAdmitted, fieldValuesMap.get("refused")); + } + + @Test + void should_throw_if_refused_decision_is_not_present() { + dataSetup(); + when(asylumCase.read(FTPA_RESPONDENT_RJ_DECISION_OUTCOME_TYPE, FtpaDecisionOutcomeType.class)).thenReturn(Optional.empty()); + + assertThatThrownBy(() -> internalHoFtpaDecidedRefusedLetterTemplate.mapFieldValues(caseDetails)) + .isExactlyInstanceOf(IllegalStateException.class) + .hasMessage("Judge decision 'refused' or 'not admitted' must be present"); + } +} \ No newline at end of file