From 02c7234d69e4a5e81feb14ce7794162addfe71c4 Mon Sep 17 00:00:00 2001 From: FarukH Date: Mon, 11 Sep 2023 20:47:50 +0100 Subject: [PATCH] RIA-7368 * Addedn functionality to generate letter when HO application decided * Refactored RIA-7365 * Added/updated unit/FTs --- ...ation-adjourn-decision-refused-letter.json | 63 ++++++++ ...tion-expedite-decision-refused-letter.json | 63 ++++++++ ...-judge-review-decision-refused-letter.json | 63 ++++++++ ...er-out-of-ada-decision-refused-letter.json | 63 ++++++++ ...ation-adjourn-decision-refused-letter.json | 62 ++++++++ ...tion-expedite-decision-refused-letter.json | 62 ++++++++ ...-judge-review-decision-refused-letter.json | 62 ++++++++ ...er-out-of-ada-decision-refused-letter.json | 62 ++++++++ ...ernalDecideAnApplicationLetterHandler.java | 12 +- ...icationDecisionRefusedLetterTemplate.java} | 6 +- ...licationDecisionRefusedLetterTemplate.java | 81 ++++++++++ .../config/DocumentCreatorConfiguration.java | 33 +++- src/main/resources/application.yaml | 13 +- ...DecideAnApplicationLetterHandlerTest.java} | 83 +++------- ...ionDecisionRefusedLetterTemplateTest.java} | 6 +- ...tionDecisionRefusedLetterTemplateTest.java | 149 ++++++++++++++++++ 16 files changed, 805 insertions(+), 78 deletions(-) create mode 100644 src/functionalTest/resources/scenarios/RIA-7368-internal-ada-decide-a-respondent-application-adjourn-decision-refused-letter.json create mode 100644 src/functionalTest/resources/scenarios/RIA-7368-internal-ada-decide-a-respondent-application-expedite-decision-refused-letter.json create mode 100644 src/functionalTest/resources/scenarios/RIA-7368-internal-ada-decide-a-respondent-application-judge-review-decision-refused-letter.json create mode 100644 src/functionalTest/resources/scenarios/RIA-7368-internal-ada-decide-a-respondent-application-transfer-out-of-ada-decision-refused-letter.json create mode 100644 src/functionalTest/resources/scenarios/RIA-7368-internal-detained-decide-a-respondent-application-adjourn-decision-refused-letter.json create mode 100644 src/functionalTest/resources/scenarios/RIA-7368-internal-detained-decide-a-respondent-application-expedite-decision-refused-letter.json create mode 100644 src/functionalTest/resources/scenarios/RIA-7368-internal-detained-decide-a-respondent-application-judge-review-decision-refused-letter.json create mode 100644 src/functionalTest/resources/scenarios/RIA-7368-internal-detained-decide-a-respondent-application-transfer-out-of-ada-decision-refused-letter.json rename src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/{InternalDecideAnApplicationDecisionRefusedLetterTemplate.java => InternalDecideAnAppellantApplicationDecisionRefusedLetterTemplate.java} (94%) create mode 100644 src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideHomeOfficeApplicationDecisionRefusedLetterTemplate.java rename src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/{InternalDecideAnAppellantApplicationLetterHandlerTest.java => InternalDecideAnApplicationLetterHandlerTest.java} (82%) rename src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/{InternalDecideAnApplicationDecisionRefusedLetterTemplateTest.java => InternalDecideAnAppellantApplicationDecisionRefusedLetterTemplateTest.java} (97%) create mode 100644 src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideHomeOfficeApplicationDecisionRefusedLetterTemplateTest.java diff --git a/src/functionalTest/resources/scenarios/RIA-7368-internal-ada-decide-a-respondent-application-adjourn-decision-refused-letter.json b/src/functionalTest/resources/scenarios/RIA-7368-internal-ada-decide-a-respondent-application-adjourn-decision-refused-letter.json new file mode 100644 index 000000000..924669084 --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7368-internal-ada-decide-a-respondent-application-adjourn-decision-refused-letter.json @@ -0,0 +1,63 @@ +{ + "description": "RIA-7368 internal ADA application decided letter (Adjourn - Refused)", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 73681, + "eventId": "decideAnApplication", + "state": "appealSubmitted", + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "isAcceleratedDetainedAppeal": "Yes", + "decideAnApplicationId": "1", + "makeAnApplications": [ + { + "id": "1", + "value": { + "type":"Adjourn", + "details":"", + "evidence":[], + "applicant":"Respondent", + "date":"{$TODAY}", + "decision":"Refused", + "state":"appealSubmitted", + "applicantRole":"caseworker-ia-admofficer", + "decisionReason":"No Reason given", + "decisionDate":"{$TODAY}", + "decisionMaker": "Admin Officer" + } + } + ] + } + } + } + }, + "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-respondent-letter-application-refused.PDF" + }, + "description": "", + "dateUploaded": "{$TODAY}", + "tag": "internalDecideHomeOfficeApplicationLetter" + } + } + ] + } + } + } +} diff --git a/src/functionalTest/resources/scenarios/RIA-7368-internal-ada-decide-a-respondent-application-expedite-decision-refused-letter.json b/src/functionalTest/resources/scenarios/RIA-7368-internal-ada-decide-a-respondent-application-expedite-decision-refused-letter.json new file mode 100644 index 000000000..b0e5caecd --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7368-internal-ada-decide-a-respondent-application-expedite-decision-refused-letter.json @@ -0,0 +1,63 @@ +{ + "description": "RIA-7368 internal ADA application decided letter (Expedite - Refused)", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 73682, + "eventId": "decideAnApplication", + "state": "appealSubmitted", + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "isAcceleratedDetainedAppeal": "Yes", + "decideAnApplicationId": "1", + "makeAnApplications": [ + { + "id": "1", + "value": { + "type":"Expedite", + "details":"", + "evidence":[], + "applicant":"Respondent", + "date":"{$TODAY}", + "decision":"Refused", + "state":"appealSubmitted", + "applicantRole":"caseworker-ia-admofficer", + "decisionReason":"No Reason given", + "decisionDate":"{$TODAY}", + "decisionMaker": "Admin Officer" + } + } + ] + } + } + } + }, + "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-respondent-letter-application-refused.PDF" + }, + "description": "", + "dateUploaded": "{$TODAY}", + "tag": "internalDecideHomeOfficeApplicationLetter" + } + } + ] + } + } + } +} diff --git a/src/functionalTest/resources/scenarios/RIA-7368-internal-ada-decide-a-respondent-application-judge-review-decision-refused-letter.json b/src/functionalTest/resources/scenarios/RIA-7368-internal-ada-decide-a-respondent-application-judge-review-decision-refused-letter.json new file mode 100644 index 000000000..03c42bf0d --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7368-internal-ada-decide-a-respondent-application-judge-review-decision-refused-letter.json @@ -0,0 +1,63 @@ +{ + "description": "RIA-7368 internal ADA application decided letter (Judges review - Refused)", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 73683, + "eventId": "decideAnApplication", + "state": "appealSubmitted", + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "isAcceleratedDetainedAppeal": "Yes", + "decideAnApplicationId": "1", + "makeAnApplications": [ + { + "id": "1", + "value": { + "type":"Judge's review of Legal Officer decision", + "details":"", + "evidence":[], + "applicant":"Respondent", + "date":"{$TODAY}", + "decision":"Refused", + "state":"appealSubmitted", + "applicantRole":"caseworker-ia-admofficer", + "decisionReason":"No Reason given", + "decisionDate":"{$TODAY}", + "decisionMaker": "Admin Officer" + } + } + ] + } + } + } + }, + "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-respondent-letter-application-refused.PDF" + }, + "description": "", + "dateUploaded": "{$TODAY}", + "tag": "internalDecideHomeOfficeApplicationLetter" + } + } + ] + } + } + } +} diff --git a/src/functionalTest/resources/scenarios/RIA-7368-internal-ada-decide-a-respondent-application-transfer-out-of-ada-decision-refused-letter.json b/src/functionalTest/resources/scenarios/RIA-7368-internal-ada-decide-a-respondent-application-transfer-out-of-ada-decision-refused-letter.json new file mode 100644 index 000000000..490efca32 --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7368-internal-ada-decide-a-respondent-application-transfer-out-of-ada-decision-refused-letter.json @@ -0,0 +1,63 @@ +{ + "description": "RIA-7368 internal ADA application decided letter (Transfer out of ada- Refused)", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 73684, + "eventId": "decideAnApplication", + "state": "appealSubmitted", + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "isAcceleratedDetainedAppeal": "Yes", + "decideAnApplicationId": "1", + "makeAnApplications": [ + { + "id": "1", + "value": { + "type":"Transfer out of accelerated detained appeals process", + "details":"", + "evidence":[], + "applicant":"Respondent", + "date":"{$TODAY}", + "decision":"Refused", + "state":"appealSubmitted", + "applicantRole":"caseworker-ia-admofficer", + "decisionReason":"No Reason given", + "decisionDate":"{$TODAY}", + "decisionMaker": "Admin Officer" + } + } + ] + } + } + } + }, + "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-respondent-letter-application-refused.PDF" + }, + "description": "", + "dateUploaded": "{$TODAY}", + "tag": "internalDecideHomeOfficeApplicationLetter" + } + } + ] + } + } + } +} diff --git a/src/functionalTest/resources/scenarios/RIA-7368-internal-detained-decide-a-respondent-application-adjourn-decision-refused-letter.json b/src/functionalTest/resources/scenarios/RIA-7368-internal-detained-decide-a-respondent-application-adjourn-decision-refused-letter.json new file mode 100644 index 000000000..d4d9b8088 --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7368-internal-detained-decide-a-respondent-application-adjourn-decision-refused-letter.json @@ -0,0 +1,62 @@ +{ + "description": "RIA-7368 internal detained (non-ada) application decided letter (Adjourn - Refused)", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 73685, + "eventId": "decideAnApplication", + "state": "appealSubmitted", + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "decideAnApplicationId": "1", + "makeAnApplications": [ + { + "id": "1", + "value": { + "type":"Adjourn", + "details":"", + "evidence":[], + "applicant":"Respondent", + "date":"{$TODAY}", + "decision":"Refused", + "state":"appealSubmitted", + "applicantRole":"caseworker-ia-admofficer", + "decisionReason":"No Reason given", + "decisionDate":"{$TODAY}", + "decisionMaker": "Admin Officer" + } + } + ] + } + } + } + }, + "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-respondent-letter-application-refused.PDF" + }, + "description": "", + "dateUploaded": "{$TODAY}", + "tag": "internalDecideHomeOfficeApplicationLetter" + } + } + ] + } + } + } +} diff --git a/src/functionalTest/resources/scenarios/RIA-7368-internal-detained-decide-a-respondent-application-expedite-decision-refused-letter.json b/src/functionalTest/resources/scenarios/RIA-7368-internal-detained-decide-a-respondent-application-expedite-decision-refused-letter.json new file mode 100644 index 000000000..34aa332aa --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7368-internal-detained-decide-a-respondent-application-expedite-decision-refused-letter.json @@ -0,0 +1,62 @@ +{ + "description": "RIA-7368 internal detained (non-ada) application decided letter (Expedite - Refused)", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 73686, + "eventId": "decideAnApplication", + "state": "appealSubmitted", + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "decideAnApplicationId": "1", + "makeAnApplications": [ + { + "id": "1", + "value": { + "type":"Expedite", + "details":"", + "evidence":[], + "applicant":"Respondent", + "date":"{$TODAY}", + "decision":"Refused", + "state":"appealSubmitted", + "applicantRole":"caseworker-ia-admofficer", + "decisionReason":"No Reason given", + "decisionDate":"{$TODAY}", + "decisionMaker": "Admin Officer" + } + } + ] + } + } + } + }, + "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-respondent-letter-application-refused.PDF" + }, + "description": "", + "dateUploaded": "{$TODAY}", + "tag": "internalDecideHomeOfficeApplicationLetter" + } + } + ] + } + } + } +} diff --git a/src/functionalTest/resources/scenarios/RIA-7368-internal-detained-decide-a-respondent-application-judge-review-decision-refused-letter.json b/src/functionalTest/resources/scenarios/RIA-7368-internal-detained-decide-a-respondent-application-judge-review-decision-refused-letter.json new file mode 100644 index 000000000..61a72cabb --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7368-internal-detained-decide-a-respondent-application-judge-review-decision-refused-letter.json @@ -0,0 +1,62 @@ +{ + "description": "RIA-7368 internal detained (non-ada) application decided letter (Judges review - Refused)", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 73687, + "eventId": "decideAnApplication", + "state": "appealSubmitted", + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "decideAnApplicationId": "1", + "makeAnApplications": [ + { + "id": "1", + "value": { + "type":"Judge's review of Legal Officer decision", + "details":"", + "evidence":[], + "applicant":"Respondent", + "date":"{$TODAY}", + "decision":"Refused", + "state":"appealSubmitted", + "applicantRole":"caseworker-ia-admofficer", + "decisionReason":"No Reason given", + "decisionDate":"{$TODAY}", + "decisionMaker": "Admin Officer" + } + } + ] + } + } + } + }, + "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-respondent-letter-application-refused.PDF" + }, + "description": "", + "dateUploaded": "{$TODAY}", + "tag": "internalDecideHomeOfficeApplicationLetter" + } + } + ] + } + } + } +} diff --git a/src/functionalTest/resources/scenarios/RIA-7368-internal-detained-decide-a-respondent-application-transfer-out-of-ada-decision-refused-letter.json b/src/functionalTest/resources/scenarios/RIA-7368-internal-detained-decide-a-respondent-application-transfer-out-of-ada-decision-refused-letter.json new file mode 100644 index 000000000..1021357e6 --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7368-internal-detained-decide-a-respondent-application-transfer-out-of-ada-decision-refused-letter.json @@ -0,0 +1,62 @@ +{ + "description": "RIA-7368 internal detained (non-ada) application decided letter (Transfer out of ada - Refused)", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 73688, + "eventId": "decideAnApplication", + "state": "appealSubmitted", + "caseData": { + "template": "minimal-internal-appeal-submitted.json", + "replacements": { + "appellantInDetention": "Yes", + "decideAnApplicationId": "1", + "makeAnApplications": [ + { + "id": "1", + "value": { + "type":"Transfer out of accelerated detained appeals process", + "details":"", + "evidence":[], + "applicant":"Respondent", + "date":"{$TODAY}", + "decision":"Refused", + "state":"appealSubmitted", + "applicantRole":"caseworker-ia-admofficer", + "decisionReason":"No Reason given", + "decisionDate":"{$TODAY}", + "decisionMaker": "Admin Officer" + } + } + ] + } + } + } + }, + "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-respondent-letter-application-refused.PDF" + }, + "description": "", + "dateUploaded": "{$TODAY}", + "tag": "internalDecideHomeOfficeApplicationLetter" + } + } + ] + } + } + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDecideAnApplicationLetterHandler.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDecideAnApplicationLetterHandler.java index 8409a7cec..11bcde30c 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDecideAnApplicationLetterHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDecideAnApplicationLetterHandler.java @@ -28,6 +28,7 @@ public class InternalDecideAnApplicationLetterHandler implements PreSubmitCallba private final DocumentCreator internalDecideAnAppellantApplicationDecisionGrantedLetter; private final DocumentCreator internalDecideAnAppellantApplicationDecisionRefusedLetter; private final DocumentCreator internalDecideHomeOfficeApplicationDecisionGrantedLetter; + private final DocumentCreator internalDecideHomeOfficeApplicationDecisionRefusedLetter; private final DocumentHandler documentHandler; private final MakeAnApplicationService makeAnApplicationService; private final String decisionGranted = "Granted"; @@ -36,14 +37,16 @@ public class InternalDecideAnApplicationLetterHandler implements PreSubmitCallba public InternalDecideAnApplicationLetterHandler( @Qualifier("internalDecideAnAppellantApplicationDecisionGrantedLetter") DocumentCreator internalDecideAnAppellantApplicationDecisionGrantedLetter, - @Qualifier("internalDecideAnApplicationDecisionRefusedLetter") DocumentCreator internalDecideAnAppellantApplicationDecisionRefusedLetter, + @Qualifier("internalDecideAnAppellantApplicationDecisionRefusedLetter") DocumentCreator internalDecideAnAppellantApplicationDecisionRefusedLetter, @Qualifier("internalDecideHomeOfficeApplicationDecisionGrantedLetter") DocumentCreator internalDecideHomeOfficeApplicationDecisionGrantedLetter, + @Qualifier("internalDecideHomeOfficeApplicationDecisionRefusedLetter") DocumentCreator internalDecideHomeOfficeApplicationDecisionRefusedLetter, DocumentHandler documentHandler, MakeAnApplicationService makeAnApplicationService ) { this.internalDecideAnAppellantApplicationDecisionGrantedLetter = internalDecideAnAppellantApplicationDecisionGrantedLetter; this.internalDecideAnAppellantApplicationDecisionRefusedLetter = internalDecideAnAppellantApplicationDecisionRefusedLetter; this.internalDecideHomeOfficeApplicationDecisionGrantedLetter = internalDecideHomeOfficeApplicationDecisionGrantedLetter; + this.internalDecideHomeOfficeApplicationDecisionRefusedLetter = internalDecideHomeOfficeApplicationDecisionRefusedLetter; this.documentHandler = documentHandler; this.makeAnApplicationService = makeAnApplicationService; } @@ -93,7 +96,12 @@ public PreSubmitCallbackResponse handle( documentForUpload = internalDecideHomeOfficeApplicationDecisionGrantedLetter.create(caseDetails); } } else if (applicationRefused) { - documentForUpload = internalDecideAnAppellantApplicationDecisionRefusedLetter.create(caseDetails); + if (isAppellantApplication) { + documentForUpload = internalDecideAnAppellantApplicationDecisionRefusedLetter.create(caseDetails); + } else { + documentTagForUpload = DocumentTag.INTERNAL_DECIDE_HOME_OFFICE_APPLICATION_LETTER; + documentForUpload = internalDecideHomeOfficeApplicationDecisionRefusedLetter.create(caseDetails); + } } else { return new PreSubmitCallbackResponse<>(asylumCase); } diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnApplicationDecisionRefusedLetterTemplate.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnAppellantApplicationDecisionRefusedLetterTemplate.java similarity index 94% rename from src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnApplicationDecisionRefusedLetterTemplate.java rename to src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnAppellantApplicationDecisionRefusedLetterTemplate.java index 3c6b2321c..9111af247 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnApplicationDecisionRefusedLetterTemplate.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnAppellantApplicationDecisionRefusedLetterTemplate.java @@ -18,7 +18,7 @@ import uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.MakeAnApplicationService; @Component -public class InternalDecideAnApplicationDecisionRefusedLetterTemplate implements DocumentTemplate { +public class InternalDecideAnAppellantApplicationDecisionRefusedLetterTemplate implements DocumentTemplate { private static final String judgeRole = "caseworker-ia-iacjudge"; private static final String legalOfficerRole = "caseworker-ia-caseofficer"; @@ -31,8 +31,8 @@ public class InternalDecideAnApplicationDecisionRefusedLetterTemplate implements private final UserDetailsProvider userDetailsProvider; - public InternalDecideAnApplicationDecisionRefusedLetterTemplate( - @Value("${internalDecideAnApplicationDecisionRefusedLetter.templateName}") String templateName, + public InternalDecideAnAppellantApplicationDecisionRefusedLetterTemplate( + @Value("${internalDecideAnAppellantApplicationDecisionRefusedLetter.templateName}") String templateName, DateProvider dateProvider, CustomerServicesProvider customerServicesProvider, MakeAnApplicationService makeAnApplicationService, diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideHomeOfficeApplicationDecisionRefusedLetterTemplate.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideHomeOfficeApplicationDecisionRefusedLetterTemplate.java new file mode 100644 index 000000000..d2f7e26ff --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideHomeOfficeApplicationDecisionRefusedLetterTemplate.java @@ -0,0 +1,81 @@ +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 java.util.Optional; +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.MakeAnApplication; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.MakeAnApplicationTypes; +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; +import uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.MakeAnApplicationService; + + +@Component +public class InternalDecideHomeOfficeApplicationDecisionRefusedLetterTemplate implements DocumentTemplate { + private final String templateName; + private final DateProvider dateProvider; + private final CustomerServicesProvider customerServicesProvider; + private final MakeAnApplicationService makeAnApplicationService; + + public InternalDecideHomeOfficeApplicationDecisionRefusedLetterTemplate( + @Value("${internalDecideHomeOfficeApplicationDecisionRefusedLetter.templateName}") String templateName, + DateProvider dateProvider, + CustomerServicesProvider customerServicesProvider, + MakeAnApplicationService makeAnApplicationService + ) { + this.templateName = templateName; + this.dateProvider = dateProvider; + this.customerServicesProvider = customerServicesProvider; + this.makeAnApplicationService = makeAnApplicationService; + } + + public String getName() { + return templateName; + } + + public Map mapFieldValues( + CaseDetails caseDetails + ) { + final AsylumCase asylumCase = caseDetails.getCaseData(); + final Map fieldValues = new HashMap<>(); + + Optional optionalMakeAnApplication = getMakeAnApplication(asylumCase); + + String applicationType = ""; + String applicationDecisionReason = "No reason given"; + if (optionalMakeAnApplication.isPresent()) { + MakeAnApplication makeAnApplication = optionalMakeAnApplication.get(); + applicationType = makeAnApplication.getType(); + applicationDecisionReason = makeAnApplication.getDecisionReason(); + } + + Optional optionalApplicationType = MakeAnApplicationTypes.from(applicationType); + MakeAnApplicationTypes makeAnApplicationTypes; + if (optionalApplicationType.isPresent()) { + makeAnApplicationTypes = optionalApplicationType.get(); + } else { + throw new IllegalStateException("Application type could not be parsed"); + } + + fieldValues.putAll(getAppellantPersonalisation(asylumCase)); + fieldValues.put("dateLetterSent", formatDateForNotificationAttachmentDocument(dateProvider.now())); + fieldValues.put("customerServicesTelephone", customerServicesProvider.getInternalCustomerServicesTelephone(asylumCase)); + fieldValues.put("customerServicesEmail", customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)); + fieldValues.put("applicationType", applicationType); + fieldValues.put("applicationReason", applicationDecisionReason); + + return fieldValues; + } + + private Optional getMakeAnApplication(AsylumCase asylumCase) { + return makeAnApplicationService.getMakeAnApplication(asylumCase, true); + } +} 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 aea9eb341..526d4a9fc 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 @@ -1003,13 +1003,34 @@ public DocumentCreator getinternalDecideHomeOfficeApplicationDecisio ); } - @Bean("internalDecideAnApplicationDecisionRefusedLetter") - public DocumentCreator getinternalDetainedDecideAnApplicationDecisionRefusedLetterCreator( - @Value("${internalDecideAnApplicationDecisionRefusedLetter.contentType}") String contentType, - @Value("${internalDecideAnApplicationDecisionRefusedLetter.fileExtension}") String fileExtension, - @Value("${internalDecideAnApplicationDecisionRefusedLetter.fileName}") String fileName, + @Bean("internalDecideAnAppellantApplicationDecisionRefusedLetter") + public DocumentCreator getinternalDetainedDecideAnAppellantApplicationDecisionRefusedLetterCreator( + @Value("${internalDecideAnAppellantApplicationDecisionRefusedLetter.contentType}") String contentType, + @Value("${internalDecideAnAppellantApplicationDecisionRefusedLetter.fileExtension}") String fileExtension, + @Value("${internalDecideAnAppellantApplicationDecisionRefusedLetter.fileName}") String fileName, AsylumCaseFileNameQualifier fileNameQualifier, - InternalDecideAnApplicationDecisionRefusedLetterTemplate documentTemplate, + InternalDecideAnAppellantApplicationDecisionRefusedLetterTemplate documentTemplate, + DocumentGenerator documentGenerator, + DocumentUploader documentUploader + ) { + return new DocumentCreator<>( + contentType, + fileExtension, + fileName, + fileNameQualifier, + documentTemplate, + documentGenerator, + documentUploader + ); + } + + @Bean("internalDecideHomeOfficeApplicationDecisionRefusedLetter") + public DocumentCreator getinternalDecideHomeOfficeApplicationDecisionRefusedLetterCreator( + @Value("${internalDecideHomeOfficeApplicationDecisionRefusedLetter.contentType}") String contentType, + @Value("${internalDecideHomeOfficeApplicationDecisionRefusedLetter.fileExtension}") String fileExtension, + @Value("${internalDecideHomeOfficeApplicationDecisionRefusedLetter.fileName}") String fileName, + AsylumCaseFileNameQualifier fileNameQualifier, + InternalDecideHomeOfficeApplicationDecisionRefusedLetterTemplate documentTemplate, DocumentGenerator documentGenerator, DocumentUploader documentUploader ) { diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 78ea64362..34f68c45d 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -309,10 +309,15 @@ internalDecideHomeOfficeApplicationDecisionGrantedLetter.fileExtension: PDF internalDecideHomeOfficeApplicationDecisionGrantedLetter.fileName: "respondent-letter-application-granted" internalDecideHomeOfficeApplicationDecisionGrantedLetter.templateName: ${IA_INTERNAL_DECIDE_HOME_OFFICE_APPLICATION_DECISION_GRANTED_LETTER_TEMPLATE:TB-IAC-LET-ENG-00024.docx} -internalDecideAnApplicationDecisionRefusedLetter.contentType: application/pdf -internalDecideAnApplicationDecisionRefusedLetter.fileExtension: PDF -internalDecideAnApplicationDecisionRefusedLetter.fileName: "appellant-letter-application-refused" -internalDecideAnApplicationDecisionRefusedLetter.templateName: ${IA_INTERNAL_DECIDE_AN_APPLICATION_DECISION_REFUSED_LETTER_TEMPLATE:TB-IAC-LET-ENG-00016.docx} +internalDecideAnAppellantApplicationDecisionRefusedLetter.contentType: application/pdf +internalDecideAnAppellantApplicationDecisionRefusedLetter.fileExtension: PDF +internalDecideAnAppellantApplicationDecisionRefusedLetter.fileName: "appellant-letter-application-refused" +internalDecideAnAppellantApplicationDecisionRefusedLetter.templateName: ${IA_INTERNAL_DECIDE_AN_APPLICATION_DECISION_REFUSED_LETTER_TEMPLATE:TB-IAC-LET-ENG-00016.docx} + +internalDecideHomeOfficeApplicationDecisionRefusedLetter.contentType: application/pdf +internalDecideHomeOfficeApplicationDecisionRefusedLetter.fileExtension: PDF +internalDecideHomeOfficeApplicationDecisionRefusedLetter.fileName: "respondent-letter-application-refused" +internalDecideHomeOfficeApplicationDecisionRefusedLetter.templateName: ${IA_INTERNAL_DECIDE_HOME_OFFICE_APPLICATION_DECISION_REFUSED_LETTER_TEMPLATE:TB-IAC-LET-ENG-00025.docx} internalDetainedApplyForFtpaRespondentLetter.contentType: application/pdf internalDetainedApplyForFtpaRespondentLetter.fileExtension: PDF diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDecideAnAppellantApplicationLetterHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDecideAnApplicationLetterHandlerTest.java similarity index 82% rename from src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDecideAnAppellantApplicationLetterHandlerTest.java rename to src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDecideAnApplicationLetterHandlerTest.java index dc99797d9..b6a3f866a 100644 --- a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDecideAnAppellantApplicationLetterHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDecideAnApplicationLetterHandlerTest.java @@ -43,14 +43,16 @@ @ExtendWith(MockitoExtension.class) @SuppressWarnings("unchecked") @MockitoSettings(strictness = Strictness.LENIENT) -public class InternalDecideAnAppellantApplicationLetterHandlerTest { +public class InternalDecideAnApplicationLetterHandlerTest { @Mock - private DocumentCreator internalAppellantApplicationDecidedLetterCreator; + private DocumentCreator internalAppellantApplicationGrantedLetterCreator; @Mock - private DocumentCreator internalAppellantApplicationDecidedRefusedLetterCreator; + private DocumentCreator internalAppellantApplicationRefusedLetterCreator; @Mock - private DocumentCreator internalHomeOfficeApplicationDecidedLetterCreator; + private DocumentCreator internalHomeOfficeApplicationGrantedLetterCreator; + @Mock + private DocumentCreator internalHomeOfficeApplicationRefusedLetterCreator; @Mock private DocumentHandler documentHandler; @Mock @@ -85,9 +87,10 @@ public class InternalDecideAnAppellantApplicationLetterHandlerTest { public void setUp() { internalDecideAnAppellantApplicationLetterHandler = new InternalDecideAnApplicationLetterHandler( - internalAppellantApplicationDecidedLetterCreator, - internalAppellantApplicationDecidedRefusedLetterCreator, - internalHomeOfficeApplicationDecidedLetterCreator, + internalAppellantApplicationGrantedLetterCreator, + internalAppellantApplicationRefusedLetterCreator, + internalHomeOfficeApplicationGrantedLetterCreator, + internalHomeOfficeApplicationRefusedLetterCreator, documentHandler, makeAnApplicationService ); @@ -105,13 +108,16 @@ public void setUp() { when(asylumCase.read(DECIDE_AN_APPLICATION_ID)).thenReturn(Optional.of("1")); when(makeAnApplicationService.getMakeAnApplication(asylumCase, true)).thenReturn(Optional.of(makeAnApplication)); + + when(internalAppellantApplicationGrantedLetterCreator.create(caseDetails)).thenReturn(uploadedDocument); + when(internalAppellantApplicationRefusedLetterCreator.create(caseDetails)).thenReturn(uploadedDocument); + when(internalHomeOfficeApplicationGrantedLetterCreator.create(caseDetails)).thenReturn(uploadedDocument); + when(internalHomeOfficeApplicationRefusedLetterCreator.create(caseDetails)).thenReturn(uploadedDocument); } - @Test // change + @Test public void should_create_application_decided_letter_and_append_to_notification_attachment_documents() { - when(internalAppellantApplicationDecidedLetterCreator.create(caseDetails)).thenReturn(uploadedDocument); - PreSubmitCallbackResponse callbackResponse = internalDecideAnAppellantApplicationLetterHandler.handle(ABOUT_TO_SUBMIT, callback); @@ -220,7 +226,7 @@ public void it_should_handle_both_internal_detained_cases_and_internal_ada_cases @ParameterizedTest @ValueSource(strings = {decisionGranted, decisionRefused, decisionPending}) - public void it_should_only_generate_the_letter_for_granted_and_refused_applications(String decision) { + public void it_should_only_generate_the_appellant_letter_for_granted_and_refused_applications_only(String decision) { List> testApplications = new ArrayList<>(); final MakeAnApplication testApplication = new MakeAnApplication( "Admin Officer", @@ -237,9 +243,6 @@ public void it_should_only_generate_the_letter_for_granted_and_refused_applicati when(asylumCase.read(DECIDE_AN_APPLICATION_ID)).thenReturn(Optional.of("1")); when(makeAnApplicationService.getMakeAnApplication(asylumCase, true)).thenReturn(Optional.of(testApplication)); - when(internalAppellantApplicationDecidedLetterCreator.create(caseDetails)).thenReturn(uploadedDocument); - when(internalAppellantApplicationDecidedRefusedLetterCreator.create(caseDetails)).thenReturn(uploadedDocument); - PreSubmitCallbackResponse callbackResponse = internalDecideAnAppellantApplicationLetterHandler.handle(ABOUT_TO_SUBMIT, callback); @@ -254,16 +257,16 @@ public void it_should_only_generate_the_letter_for_granted_and_refused_applicati } @ParameterizedTest - @ValueSource(strings = {adminOfficerRole, respondentRole}) - public void it_should_generate_the_granted_letter_for_both_appellant_and_respondent_applications(String user) { + @ValueSource(strings = {decisionGranted, decisionRefused, decisionPending}) + public void it_should_only_generate_the_home_office_letter_for_granted_and_refused_applications_only(String decision) { List> testApplications = new ArrayList<>(); final MakeAnApplication testApplication = new MakeAnApplication( - user, + "Respondent", MakeAnApplicationTypes.ADJOURN.getValue(), "someRandomDetails", new ArrayList<>(), LocalDate.now().toString(), - decisionGranted, + decision.toString(), State.APPEAL_SUBMITTED.toString(), "caseworker-ia-admofficer"); testApplications.add(new IdValue<>("1", testApplication)); @@ -272,56 +275,19 @@ public void it_should_generate_the_granted_letter_for_both_appellant_and_respond when(asylumCase.read(DECIDE_AN_APPLICATION_ID)).thenReturn(Optional.of("1")); when(makeAnApplicationService.getMakeAnApplication(asylumCase, true)).thenReturn(Optional.of(testApplication)); - when(internalAppellantApplicationDecidedLetterCreator.create(caseDetails)).thenReturn(uploadedDocument); - when(internalAppellantApplicationDecidedRefusedLetterCreator.create(caseDetails)).thenReturn(uploadedDocument); - PreSubmitCallbackResponse callbackResponse = internalDecideAnAppellantApplicationLetterHandler.handle(ABOUT_TO_SUBMIT, callback); assertNotNull(callbackResponse); assertEquals(asylumCase, callbackResponse.getData()); - if (user.equals(adminOfficerRole)) { - verify(documentHandler, times(1)).addWithMetadata(asylumCase, uploadedDocument, NOTIFICATION_ATTACHMENT_DOCUMENTS, DocumentTag.INTERNAL_DECIDE_AN_APPELLANT_APPLICATION_LETTER); + if (List.of(decisionGranted, decisionRefused).contains(decision)) { + verify(documentHandler, times(1)).addWithMetadata(asylumCase, uploadedDocument, NOTIFICATION_ATTACHMENT_DOCUMENTS, DocumentTag.INTERNAL_DECIDE_HOME_OFFICE_APPLICATION_LETTER); } else { verify(documentHandler, times(0)).addWithMetadata(asylumCase, uploadedDocument, NOTIFICATION_ATTACHMENT_DOCUMENTS, DocumentTag.INTERNAL_DECIDE_HOME_OFFICE_APPLICATION_LETTER); } } - @ParameterizedTest - @ValueSource(strings = {adminOfficerRole, respondentRole}) - public void it_should_generate_the_refused_letter_for_both_appellant_and_respondent_applications(String user) { - List> testApplications = new ArrayList<>(); - final MakeAnApplication testApplication = new MakeAnApplication( - user, - MakeAnApplicationTypes.ADJOURN.getValue(), - "someRandomDetails", - new ArrayList<>(), - LocalDate.now().toString(), - decisionRefused, - State.APPEAL_SUBMITTED.toString(), - "caseworker-ia-admofficer"); - testApplications.add(new IdValue<>("1", testApplication)); - - when(asylumCase.read(MAKE_AN_APPLICATIONS)).thenReturn(Optional.of(testApplications)); - when(asylumCase.read(DECIDE_AN_APPLICATION_ID)).thenReturn(Optional.of("1")); - when(makeAnApplicationService.getMakeAnApplication(asylumCase, true)).thenReturn(Optional.of(testApplication)); - - when(internalAppellantApplicationDecidedLetterCreator.create(caseDetails)).thenReturn(uploadedDocument); - when(internalAppellantApplicationDecidedRefusedLetterCreator.create(caseDetails)).thenReturn(uploadedDocument); - - PreSubmitCallbackResponse callbackResponse = - internalDecideAnAppellantApplicationLetterHandler.handle(ABOUT_TO_SUBMIT, callback); - - assertNotNull(callbackResponse); - assertEquals(asylumCase, callbackResponse.getData()); - - if (user.equals(adminOfficerRole)) { - verify(documentHandler, times(1)).addWithMetadata(asylumCase, uploadedDocument, NOTIFICATION_ATTACHMENT_DOCUMENTS, DocumentTag.INTERNAL_DECIDE_AN_APPELLANT_APPLICATION_LETTER); - } else { - verify(documentHandler, times(0)).addWithMetadata(asylumCase, uploadedDocument, NOTIFICATION_ATTACHMENT_DOCUMENTS, DocumentTag.INTERNAL_DECIDE_HOME_OFFICE_APPLICATION_LETTER); - } - } @ParameterizedTest @ValueSource(strings = {adminOfficerRole, respondentRole}) @@ -342,9 +308,6 @@ public void it_should_not_generate_any_letters_for_any_user_when_decision_is_pen when(asylumCase.read(DECIDE_AN_APPLICATION_ID)).thenReturn(Optional.of("1")); when(makeAnApplicationService.getMakeAnApplication(asylumCase, true)).thenReturn(Optional.of(testApplication)); - when(internalAppellantApplicationDecidedLetterCreator.create(caseDetails)).thenReturn(uploadedDocument); - when(internalAppellantApplicationDecidedRefusedLetterCreator.create(caseDetails)).thenReturn(uploadedDocument); - PreSubmitCallbackResponse callbackResponse = internalDecideAnAppellantApplicationLetterHandler.handle(ABOUT_TO_SUBMIT, callback); diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnApplicationDecisionRefusedLetterTemplateTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnAppellantApplicationDecisionRefusedLetterTemplateTest.java similarity index 97% rename from src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnApplicationDecisionRefusedLetterTemplateTest.java rename to src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnAppellantApplicationDecisionRefusedLetterTemplateTest.java index 2cc53a601..99cef0fd0 100644 --- a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnApplicationDecisionRefusedLetterTemplateTest.java +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnAppellantApplicationDecisionRefusedLetterTemplateTest.java @@ -33,7 +33,7 @@ @ExtendWith(MockitoExtension.class) @SuppressWarnings("unchecked") @MockitoSettings(strictness = Strictness.LENIENT) -public class InternalDecideAnApplicationDecisionRefusedLetterTemplateTest { +public class InternalDecideAnAppellantApplicationDecisionRefusedLetterTemplateTest { @Mock private CaseDetails caseDetails; @@ -70,12 +70,12 @@ public class InternalDecideAnApplicationDecisionRefusedLetterTemplateTest { "Refused", State.APPEAL_SUBMITTED.toString(), "caseworker-ia-admofficer"); - private InternalDecideAnApplicationDecisionRefusedLetterTemplate internalDecideAnApplicationDecisionRefusedLetterTemplate; + private InternalDecideAnAppellantApplicationDecisionRefusedLetterTemplate internalDecideAnApplicationDecisionRefusedLetterTemplate; @BeforeEach void setUp() { internalDecideAnApplicationDecisionRefusedLetterTemplate = - new InternalDecideAnApplicationDecisionRefusedLetterTemplate( + new InternalDecideAnAppellantApplicationDecisionRefusedLetterTemplate( templateName, dateProvider, customerServicesProvider, diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideHomeOfficeApplicationDecisionRefusedLetterTemplateTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideHomeOfficeApplicationDecisionRefusedLetterTemplateTest.java new file mode 100644 index 000000000..7bafcb3c4 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideHomeOfficeApplicationDecisionRefusedLetterTemplateTest.java @@ -0,0 +1,149 @@ +package uk.gov.hmcts.reform.iacasedocumentsapi.domain.templates.letter; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +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.entities.AsylumCaseDefinition.DECIDE_AN_APPLICATION_ID; +import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.DateUtils.formatDateForNotificationAttachmentDocument; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; +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.MakeAnApplication; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.CaseDetails; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.State; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.IdValue; +import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.YesOrNo; +import uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.CustomerServicesProvider; +import uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.MakeAnApplicationService; + + +@ExtendWith(MockitoExtension.class) +@SuppressWarnings("unchecked") +@MockitoSettings(strictness = Strictness.LENIENT) +public class InternalDecideHomeOfficeApplicationDecisionRefusedLetterTemplateTest { + + @Mock + private CaseDetails caseDetails; + @Mock + private AsylumCase asylumCase; + @Mock + private DateProvider dateProvider; + @Mock + private CustomerServicesProvider customerServicesProvider; + @Mock + private MakeAnApplicationService makeAnApplicationService; + private final String templateName = "TB-IAC-DEC-ENG-00016.docx"; + private final String internalAdaCustomerServicesTelephoneNumber = "0300 123 1711"; + private final String internalAdaCustomerServicesEmailAddress = "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 List> makeAnApplications = new ArrayList<>(); + private final MakeAnApplication application = new MakeAnApplication( + "Admin Officer", + "Adjourn", + "someRandomDetails", + new ArrayList<>(), + LocalDate.now().toString(), + "Refused", + State.APPEAL_SUBMITTED.toString(), + "caseworker-ia-admofficer"); + private InternalDecideHomeOfficeApplicationDecisionRefusedLetterTemplate internalDecideHomeOfficeApplicationDecisionRefusedLetterTemplate; + + @BeforeEach + void setUp() { + internalDecideHomeOfficeApplicationDecisionRefusedLetterTemplate = + new InternalDecideHomeOfficeApplicationDecisionRefusedLetterTemplate( + templateName, + dateProvider, + customerServicesProvider, + makeAnApplicationService + ); + } + + 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(internalAdaCustomerServicesTelephoneNumber); + when(customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)) + .thenReturn(internalAdaCustomerServicesEmailAddress); + + when(dateProvider.now()).thenReturn(LocalDate.now()); + + makeAnApplications.add(new IdValue<>("1", application)); + + when(asylumCase.read(MAKE_AN_APPLICATIONS)).thenReturn(Optional.of(makeAnApplications)); + when(asylumCase.read(DECIDE_AN_APPLICATION_ID)).thenReturn(Optional.of("1")); + + when(makeAnApplicationService.getMakeAnApplication(asylumCase, true)).thenReturn(Optional.of(application)); + } + + @Test + void should_return_template_name() { + assertEquals(templateName, internalDecideHomeOfficeApplicationDecisionRefusedLetterTemplate.getName()); + } + + @Test + void should_map_case_data_to_template_field_values() { + dataSetup(); + + Map templateFieldValues = internalDecideHomeOfficeApplicationDecisionRefusedLetterTemplate.mapFieldValues(caseDetails); + + assertEquals(10, 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(internalAdaCustomerServicesTelephoneNumber, templateFieldValues.get("customerServicesTelephone")); + assertEquals(internalAdaCustomerServicesEmailAddress, templateFieldValues.get("customerServicesEmail")); + assertEquals(formatDateForNotificationAttachmentDocument(dateProvider.now()), templateFieldValues.get("dateLetterSent")); + assertEquals(application.getType(), templateFieldValues.get("applicationType")); + assertEquals(application.getDecisionReason(), templateFieldValues.get("applicationReason")); + } + + @Test + void should_throw_exception_if_application_type_cannot_be_parsed() { + dataSetup(); + List> makeAnApplications = new ArrayList<>(); + final MakeAnApplication testApplication = new MakeAnApplication( + "Admin Officer", + "someRandomApplicationTypeThatShouldCauseAnException", + "someRandomDetails", + new ArrayList<>(), + LocalDate.now().toString(), + "Granted", + State.APPEAL_SUBMITTED.toString(), + "caseworker-ia-admofficer"); + makeAnApplications.add(new IdValue<>("1", testApplication)); + + when(asylumCase.read(MAKE_AN_APPLICATIONS)).thenReturn(Optional.of(makeAnApplications)); + when(asylumCase.read(DECIDE_AN_APPLICATION_ID)).thenReturn(Optional.of("1")); + + when(makeAnApplicationService.getMakeAnApplication(asylumCase, true)).thenReturn(Optional.of(testApplication)); + + assertThatThrownBy(() -> internalDecideHomeOfficeApplicationDecisionRefusedLetterTemplate.mapFieldValues(caseDetails)) + .hasMessage("Application type could not be parsed") + .isExactlyInstanceOf(IllegalStateException.class); + } +}