From be09e0e79cb550fa45d06c51067bbde6d63bfec4 Mon Sep 17 00:00:00 2001 From: FarukH Date: Thu, 24 Aug 2023 20:23:50 +0100 Subject: [PATCH] RIA-7365 * Added new template for internal decide an application where decision is refused * Refactored 7364 so granted+refused use a single handler with independent DocumentCreatorConfiguration beans and seperate templates. * 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 ++++++ ...rnalDecideAnApplicationLetterHandler.java} | 42 ++-- ...icationDecisionGrantedLetterTemplate.java} | 8 +- ...licationDecisionRefusedLetterTemplate.java | 106 ++++++++++ .../config/DocumentCreatorConfiguration.java | 31 ++- src/main/resources/application.yaml | 13 +- ...DecideAnApplicationLetterHandlerTest.java} | 48 +++-- ...ionDecisionGrantedLetterTemplateTest.java} | 16 +- ...tionDecisionRefusedLetterTemplateTest.java | 199 ++++++++++++++++++ 16 files changed, 905 insertions(+), 58 deletions(-) create mode 100644 src/functionalTest/resources/scenarios/RIA-7365-internal-ada-decide-an-application-adjourn-decision-refused-letter.json create mode 100644 src/functionalTest/resources/scenarios/RIA-7365-internal-ada-decide-an-application-expedite-decision-refused-letter.json create mode 100644 src/functionalTest/resources/scenarios/RIA-7365-internal-ada-decide-an-application-judge-review-decision-refused-letter.json create mode 100644 src/functionalTest/resources/scenarios/RIA-7365-internal-ada-decide-an-application-transfer-out-of-ada-decision-refused-letter.json create mode 100644 src/functionalTest/resources/scenarios/RIA-7365-internal-detained-decide-an-application-adjourn-decision-refused-letter.json create mode 100644 src/functionalTest/resources/scenarios/RIA-7365-internal-detained-decide-an-application-expedite-decision-refused-letter.json create mode 100644 src/functionalTest/resources/scenarios/RIA-7365-internal-detained-decide-an-application-judge-review-decision-refused-letter.json create mode 100644 src/functionalTest/resources/scenarios/RIA-7365-internal-detained-decide-an-application-transfer-out-of-ada-decision-refused-letter.json rename src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/{InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterHandler.java => InternalDecideAnApplicationLetterHandler.java} (68%) rename src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/{InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTemplate.java => InternalDecideAnApplicationDecisionGrantedLetterTemplate.java} (94%) create mode 100644 src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnApplicationDecisionRefusedLetterTemplate.java rename src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/{InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterHandlerTest.java => InternalDecideAnApplicationLetterHandlerTest.java} (84%) rename src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/{InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTemplateTest.java => InternalDecideAnApplicationDecisionGrantedLetterTemplateTest.java} (90%) create mode 100644 src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnApplicationDecisionRefusedLetterTemplateTest.java diff --git a/src/functionalTest/resources/scenarios/RIA-7365-internal-ada-decide-an-application-adjourn-decision-refused-letter.json b/src/functionalTest/resources/scenarios/RIA-7365-internal-ada-decide-an-application-adjourn-decision-refused-letter.json new file mode 100644 index 000000000..fd85aea69 --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7365-internal-ada-decide-an-application-adjourn-decision-refused-letter.json @@ -0,0 +1,63 @@ +{ + "description": "RIA-7365 internal ADA application decided letter (Adjourn - Refused)", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 73651, + "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":"", + "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-appellant-letter-application-refused.PDF" + }, + "description": "", + "dateUploaded": "{$TODAY}", + "tag": "internalDecideAnApplicationLetter" + } + } + ] + } + } + } +} diff --git a/src/functionalTest/resources/scenarios/RIA-7365-internal-ada-decide-an-application-expedite-decision-refused-letter.json b/src/functionalTest/resources/scenarios/RIA-7365-internal-ada-decide-an-application-expedite-decision-refused-letter.json new file mode 100644 index 000000000..69969567d --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7365-internal-ada-decide-an-application-expedite-decision-refused-letter.json @@ -0,0 +1,63 @@ +{ + "description": "RIA-7365 internal ADA application decided letter (Expedite - Refused)", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 73652, + "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":"", + "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-appellant-letter-application-refused.PDF" + }, + "description": "", + "dateUploaded": "{$TODAY}", + "tag": "internalDecideAnApplicationLetter" + } + } + ] + } + } + } +} diff --git a/src/functionalTest/resources/scenarios/RIA-7365-internal-ada-decide-an-application-judge-review-decision-refused-letter.json b/src/functionalTest/resources/scenarios/RIA-7365-internal-ada-decide-an-application-judge-review-decision-refused-letter.json new file mode 100644 index 000000000..1f4b6f3ff --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7365-internal-ada-decide-an-application-judge-review-decision-refused-letter.json @@ -0,0 +1,63 @@ +{ + "description": "RIA-7365 internal ADA application decided letter (Judges review - Refused)", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 73653, + "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":"", + "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-appellant-letter-application-refused.PDF" + }, + "description": "", + "dateUploaded": "{$TODAY}", + "tag": "internalDecideAnApplicationLetter" + } + } + ] + } + } + } +} diff --git a/src/functionalTest/resources/scenarios/RIA-7365-internal-ada-decide-an-application-transfer-out-of-ada-decision-refused-letter.json b/src/functionalTest/resources/scenarios/RIA-7365-internal-ada-decide-an-application-transfer-out-of-ada-decision-refused-letter.json new file mode 100644 index 000000000..1fb0b9c1e --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7365-internal-ada-decide-an-application-transfer-out-of-ada-decision-refused-letter.json @@ -0,0 +1,63 @@ +{ + "description": "RIA-7365 internal ADA application decided letter (Transfer out of ada- Refused)", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 73654, + "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":"", + "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-appellant-letter-application-refused.PDF" + }, + "description": "", + "dateUploaded": "{$TODAY}", + "tag": "internalDecideAnApplicationLetter" + } + } + ] + } + } + } +} diff --git a/src/functionalTest/resources/scenarios/RIA-7365-internal-detained-decide-an-application-adjourn-decision-refused-letter.json b/src/functionalTest/resources/scenarios/RIA-7365-internal-detained-decide-an-application-adjourn-decision-refused-letter.json new file mode 100644 index 000000000..5d15d1921 --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7365-internal-detained-decide-an-application-adjourn-decision-refused-letter.json @@ -0,0 +1,62 @@ +{ + "description": "RIA-7365 internal detained (non-ada) application decided letter (Adjourn - Refused)", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 73655, + "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":"", + "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-appellant-letter-application-refused.PDF" + }, + "description": "", + "dateUploaded": "{$TODAY}", + "tag": "internalDecideAnApplicationLetter" + } + } + ] + } + } + } +} diff --git a/src/functionalTest/resources/scenarios/RIA-7365-internal-detained-decide-an-application-expedite-decision-refused-letter.json b/src/functionalTest/resources/scenarios/RIA-7365-internal-detained-decide-an-application-expedite-decision-refused-letter.json new file mode 100644 index 000000000..b8547ed85 --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7365-internal-detained-decide-an-application-expedite-decision-refused-letter.json @@ -0,0 +1,62 @@ +{ + "description": "RIA-7365 internal detained (non-ada) application decided letter (Expedite - Refused)", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 73656, + "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":"", + "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-appellant-letter-application-refused.PDF" + }, + "description": "", + "dateUploaded": "{$TODAY}", + "tag": "internalDecideAnApplicationLetter" + } + } + ] + } + } + } +} diff --git a/src/functionalTest/resources/scenarios/RIA-7365-internal-detained-decide-an-application-judge-review-decision-refused-letter.json b/src/functionalTest/resources/scenarios/RIA-7365-internal-detained-decide-an-application-judge-review-decision-refused-letter.json new file mode 100644 index 000000000..a323d153b --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7365-internal-detained-decide-an-application-judge-review-decision-refused-letter.json @@ -0,0 +1,62 @@ +{ + "description": "RIA-7365 internal detained (non-ada) application decided letter (Judges review - Refused)", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 73657, + "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":"", + "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-appellant-letter-application-refused.PDF" + }, + "description": "", + "dateUploaded": "{$TODAY}", + "tag": "internalDecideAnApplicationLetter" + } + } + ] + } + } + } +} diff --git a/src/functionalTest/resources/scenarios/RIA-7365-internal-detained-decide-an-application-transfer-out-of-ada-decision-refused-letter.json b/src/functionalTest/resources/scenarios/RIA-7365-internal-detained-decide-an-application-transfer-out-of-ada-decision-refused-letter.json new file mode 100644 index 000000000..e60ff3b3e --- /dev/null +++ b/src/functionalTest/resources/scenarios/RIA-7365-internal-detained-decide-an-application-transfer-out-of-ada-decision-refused-letter.json @@ -0,0 +1,62 @@ +{ + "description": "RIA-7365 internal detained (non-ada) application decided letter (Transfer out of ada - Refused)", + "request": { + "uri": "/asylum/ccdAboutToSubmit", + "credentials": "Judge", + "input": { + "id": 73658, + "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":"", + "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-appellant-letter-application-refused.PDF" + }, + "description": "", + "dateUploaded": "{$TODAY}", + "tag": "internalDecideAnApplicationLetter" + } + } + ] + } + } + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterHandler.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDecideAnApplicationLetterHandler.java similarity index 68% rename from src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterHandler.java rename to src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDecideAnApplicationLetterHandler.java index 4c87925e1..5f9d376a4 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDecideAnApplicationLetterHandler.java @@ -23,19 +23,23 @@ @Component -public class InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterHandler implements PreSubmitCallbackHandler { +public class InternalDecideAnApplicationLetterHandler implements PreSubmitCallbackHandler { - private final DocumentCreator internalDetainedAndAdaDecideAnApplicationDecisionGrantedLetter; + private final DocumentCreator internalDecideAnApplicationDecisionGrantedLetter; + private final DocumentCreator internalDecideAnApplicationDecisionRefusedLetter; private final DocumentHandler documentHandler; private final MakeAnApplicationService makeAnApplicationService; private final String decisionGranted = "Granted"; + private final String decisionRefused = "Refused"; - public InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterHandler( - @Qualifier("internalDetainedAndAdaDecideAnApplicationDecisionGrantedLetter") DocumentCreator internalDetainedAndAdaDecideAnApplicationDecisionGrantedLetter, + public InternalDecideAnApplicationLetterHandler( + @Qualifier("internalDecideAnApplicationDecisionGrantedLetter") DocumentCreator internalDecideAnApplicationDecisionGrantedLetter, + @Qualifier("internalDecideAnApplicationDecisionRefusedLetter") DocumentCreator internalDecideAnApplicationDecisionRefusedLetter, DocumentHandler documentHandler, MakeAnApplicationService makeAnApplicationService ) { - this.internalDetainedAndAdaDecideAnApplicationDecisionGrantedLetter = internalDetainedAndAdaDecideAnApplicationDecisionGrantedLetter; + this.internalDecideAnApplicationDecisionGrantedLetter = internalDecideAnApplicationDecisionGrantedLetter; + this.internalDecideAnApplicationDecisionRefusedLetter = internalDecideAnApplicationDecisionRefusedLetter; this.documentHandler = documentHandler; this.makeAnApplicationService = makeAnApplicationService; } @@ -48,17 +52,10 @@ public boolean canHandle( requireNonNull(callback, "callback must not be null"); AsylumCase asylumCase = callback.getCaseDetails().getCaseData(); - Optional optionalMakeAnApplication = makeAnApplicationService.getMakeAnApplication(asylumCase, true); - if (!optionalMakeAnApplication.isPresent()) { - return false; - } - boolean applicationGranted = optionalMakeAnApplication.get().getDecision().equals(decisionGranted); - return callback.getEvent() == Event.DECIDE_AN_APPLICATION && callbackStage == PreSubmitCallbackStage.ABOUT_TO_SUBMIT && isInternalCase(asylumCase) - && isAppellantInDetention(asylumCase) - && applicationGranted; + && isAppellantInDetention(asylumCase); } public PreSubmitCallbackResponse handle( @@ -72,10 +69,25 @@ public PreSubmitCallbackResponse handle( final CaseDetails caseDetails = callback.getCaseDetails(); final AsylumCase asylumCase = caseDetails.getCaseData(); - Document applicationGrantedLetter = internalDetainedAndAdaDecideAnApplicationDecisionGrantedLetter.create(caseDetails); + Optional optionalMakeAnApplication = makeAnApplicationService.getMakeAnApplication(asylumCase, true); + if (!optionalMakeAnApplication.isPresent()) { + throw new IllegalStateException("Application not found"); + } + boolean applicationGranted = optionalMakeAnApplication.get().getDecision().equals(decisionGranted); + boolean applicationRefused = optionalMakeAnApplication.get().getDecision().equals(decisionRefused); + + Document documentForUpload; + if (applicationGranted) { + documentForUpload = internalDecideAnApplicationDecisionGrantedLetter.create(caseDetails); + } else if (applicationRefused) { + documentForUpload = internalDecideAnApplicationDecisionRefusedLetter.create(caseDetails); + } else { + return new PreSubmitCallbackResponse<>(asylumCase); + } + documentHandler.addWithMetadata( asylumCase, - applicationGrantedLetter, + documentForUpload, NOTIFICATION_ATTACHMENT_DOCUMENTS, DocumentTag.INTERNAL_DECIDE_AN_APPLICATION_LETTER ); diff --git a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTemplate.java b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnApplicationDecisionGrantedLetterTemplate.java similarity index 94% rename from src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTemplate.java rename to src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnApplicationDecisionGrantedLetterTemplate.java index 1d534b04b..bc82491c6 100644 --- a/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTemplate.java +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnApplicationDecisionGrantedLetterTemplate.java @@ -16,7 +16,7 @@ import uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.MakeAnApplicationService; @Component -public class InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTemplate implements DocumentTemplate { +public class InternalDecideAnApplicationDecisionGrantedLetterTemplate implements DocumentTemplate { private static final String timeExtentionContent = "The Tribunal will give you more time to complete your next task. You will get a notification with the new date soon."; private static final String adjournExpediteTransferOrUpdateHearingReqsContent = "The details of your hearing will be updated. The Tribunal will contact you when this happens."; @@ -31,8 +31,8 @@ public class InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTempl private final MakeAnApplicationService makeAnApplicationService; - public InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTemplate( - @Value("${internalDetainedAndAdaDecideAnApplicationDecisionGrantedLetter.templateName}") String templateName, + public InternalDecideAnApplicationDecisionGrantedLetterTemplate( + @Value("${internalDecideAnApplicationDecisionGrantedLetter.templateName}") String templateName, DateProvider dateProvider, CustomerServicesProvider customerServicesProvider, MakeAnApplicationService makeAnApplicationService) { @@ -78,10 +78,8 @@ public Map mapFieldValues( fieldValues.put("customerServicesEmail", customerServicesProvider.getInternalCustomerServicesEmail(asylumCase)); fieldValues.put("applicationType", applicationType); fieldValues.put("applicationReason", applicationDecisionReason); - fieldValues.put("whatHappensNextContent", getWhatHappensNextContent(makeAnApplicationTypes)); - return fieldValues; } 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/InternalDecideAnApplicationDecisionRefusedLetterTemplate.java new file mode 100644 index 000000000..3c6b2321c --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnApplicationDecisionRefusedLetterTemplate.java @@ -0,0 +1,106 @@ +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.util.*; +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.UserDetailsProvider; +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 InternalDecideAnApplicationDecisionRefusedLetterTemplate implements DocumentTemplate { + + private static final String judgeRole = "caseworker-ia-iacjudge"; + private static final String legalOfficerRole = "caseworker-ia-caseofficer"; + private static final String applicationRefusedAdaFormName = "IAFT-ADA4: Make an application – Accelerated detained appeal (ADA)"; + private static final String applicationRefusedDetainedNonAdaFormName = "IAFT-DE4: Make an application – Detained appeal"; + private final String templateName; + private final DateProvider dateProvider; + private final CustomerServicesProvider customerServicesProvider; + private final MakeAnApplicationService makeAnApplicationService; + private final UserDetailsProvider userDetailsProvider; + + + public InternalDecideAnApplicationDecisionRefusedLetterTemplate( + @Value("${internalDecideAnApplicationDecisionRefusedLetter.templateName}") String templateName, + DateProvider dateProvider, + CustomerServicesProvider customerServicesProvider, + MakeAnApplicationService makeAnApplicationService, + UserDetailsProvider userDetailsProvider) { + this.templateName = templateName; + this.dateProvider = dateProvider; + this.customerServicesProvider = customerServicesProvider; + this.makeAnApplicationService = makeAnApplicationService; + this.userDetailsProvider = userDetailsProvider; + } + + 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 applicationDecision = ""; + String applicationDecisionReason = "No reason given"; + if (optionalMakeAnApplication.isPresent()) { + MakeAnApplication makeAnApplication = optionalMakeAnApplication.get(); + applicationType = makeAnApplication.getType(); + applicationDecision = makeAnApplication.getDecision(); + 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"); + } + + final boolean applicationDecidedByLegalOfficer = userDetailsProvider.getUserDetails().getRoles().contains(legalOfficerRole); + final boolean applicationDecidedByJudge = userDetailsProvider.getUserDetails().getRoles().contains(judgeRole); + + String applicationDecidedBy = ""; + if (applicationDecidedByLegalOfficer) { + applicationDecidedBy = "Legal Officer"; + } else if (applicationDecidedByJudge) { + applicationDecidedBy = "Judge"; + } + + 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); + fieldValues.put("decisionMaker", applicationDecidedBy); + fieldValues.put("formName", getFormName(asylumCase)); + + return fieldValues; + } + + private Optional getMakeAnApplication(AsylumCase asylumCase) { + return makeAnApplicationService.getMakeAnApplication(asylumCase, true); + } + + private String getFormName(AsylumCase asylumCase) { + return isAcceleratedDetainedAppeal(asylumCase) ? applicationRefusedAdaFormName : applicationRefusedDetainedNonAdaFormName; + } +} 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 3e8f7698f..3a32a81f8 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 @@ -961,13 +961,34 @@ public DocumentCreator getInternalMarkAsAdaDocumentCreator( ); } - @Bean("internalDetainedAndAdaDecideAnApplicationDecisionGrantedLetter") + @Bean("internalDecideAnApplicationDecisionGrantedLetter") public DocumentCreator getinternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterCreator( - @Value("${internalDetainedAndAdaDecideAnApplicationDecisionGrantedLetter.contentType}") String contentType, - @Value("${internalDetainedAndAdaDecideAnApplicationDecisionGrantedLetter.fileExtension}") String fileExtension, - @Value("${internalDetainedAndAdaDecideAnApplicationDecisionGrantedLetter.fileName}") String fileName, + @Value("${internalDecideAnApplicationDecisionGrantedLetter.contentType}") String contentType, + @Value("${internalDecideAnApplicationDecisionGrantedLetter.fileExtension}") String fileExtension, + @Value("${internalDecideAnApplicationDecisionGrantedLetter.fileName}") String fileName, AsylumCaseFileNameQualifier fileNameQualifier, - InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTemplate documentTemplate, + InternalDecideAnApplicationDecisionGrantedLetterTemplate documentTemplate, + DocumentGenerator documentGenerator, + DocumentUploader documentUploader + ) { + return new DocumentCreator<>( + contentType, + fileExtension, + fileName, + fileNameQualifier, + documentTemplate, + documentGenerator, + documentUploader + ); + } + + @Bean("internalDecideAnApplicationDecisionRefusedLetter") + public DocumentCreator getinternalDetainedDecideAnApplicationDecisionRefusedLetterCreator( + @Value("${internalDecideAnApplicationDecisionRefusedLetter.contentType}") String contentType, + @Value("${internalDecideAnApplicationDecisionRefusedLetter.fileExtension}") String fileExtension, + @Value("${internalDecideAnApplicationDecisionRefusedLetter.fileName}") String fileName, + AsylumCaseFileNameQualifier fileNameQualifier, + InternalDecideAnApplicationDecisionRefusedLetterTemplate documentTemplate, DocumentGenerator documentGenerator, DocumentUploader documentUploader ) { diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index f73ce698f..1e446184a 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -299,10 +299,15 @@ internalMarkAppealAsAda.fileExtension: PDF internalMarkAppealAsAda.fileName: "detained-appellant-mark-as-ada-notice" internalMarkAppealAsAda.templateName: ${IA_INTERNAL_MARK_APPEAL_AS_ADA_TEMPLATE:TB-IAC-LET-ENG-00008.docx} -internalDetainedAndAdaDecideAnApplicationDecisionGrantedLetter.contentType: application/pdf -internalDetainedAndAdaDecideAnApplicationDecisionGrantedLetter.fileExtension: PDF -internalDetainedAndAdaDecideAnApplicationDecisionGrantedLetter.fileName: "appellant-letter-application-granted" -internalDetainedAndAdaDecideAnApplicationDecisionGrantedLetter.templateName: ${IA_INTERNAL_DETAINED_AND_ADA_DECIDE_AN_APPLICATION_DECISION_GRANTED_LETTER_TEMPLATE:TB-IAC-LET-ENG-00015.docx} +internalDecideAnApplicationDecisionGrantedLetter.contentType: application/pdf +internalDecideAnApplicationDecisionGrantedLetter.fileExtension: PDF +internalDecideAnApplicationDecisionGrantedLetter.fileName: "appellant-letter-application-granted" +internalDecideAnApplicationDecisionGrantedLetter.templateName: ${IA_INTERNAL_DECIDE_AN_APPLICATION_DECISION_GRANTED_LETTER_TEMPLATE:TB-IAC-LET-ENG-00015.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} ccdGatewayUrl: ${CCD_GW_URL:http://localhost:3453} diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDecideAnApplicationLetterHandlerTest.java similarity index 84% rename from src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterHandlerTest.java rename to src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDecideAnApplicationLetterHandlerTest.java index 846efe6b5..e4ac2d1d3 100644 --- a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/handlers/presubmit/letter/InternalDecideAnApplicationLetterHandlerTest.java @@ -6,6 +6,7 @@ import static org.mockito.Mockito.*; 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.ccd.callback.PreSubmitCallbackStage.ABOUT_TO_SUBMIT; import java.time.LocalDate; import java.util.ArrayList; @@ -42,12 +43,13 @@ @ExtendWith(MockitoExtension.class) @SuppressWarnings("unchecked") @MockitoSettings(strictness = Strictness.LENIENT) -public class InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterHandlerTest { - +public class InternalDecideAnApplicationLetterHandlerTest { @Mock private DocumentCreator internalApplicationDecidedLetterCreator; @Mock + private DocumentCreator internalApplicationDecidedRefusedLetterCreator; + @Mock private DocumentHandler documentHandler; @Mock private Callback callback; @@ -73,13 +75,14 @@ public class InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterHandl decisionGranted, State.APPEAL_SUBMITTED.toString(), "caseworker-ia-admofficer"); - private InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterHandler internalDecideAnApplicationLetterHandler; + private InternalDecideAnApplicationLetterHandler internalDecideAnApplicationLetterHandler; @BeforeEach public void setUp() { internalDecideAnApplicationLetterHandler = - new InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterHandler( + new InternalDecideAnApplicationLetterHandler( internalApplicationDecidedLetterCreator, + internalApplicationDecidedRefusedLetterCreator, documentHandler, makeAnApplicationService ); @@ -105,7 +108,7 @@ public void should_create_application_decided_letter_and_append_to_notification_ when(internalApplicationDecidedLetterCreator.create(caseDetails)).thenReturn(uploadedDocument); PreSubmitCallbackResponse callbackResponse = - internalDecideAnApplicationLetterHandler.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback); + internalDecideAnApplicationLetterHandler.handle(ABOUT_TO_SUBMIT, callback); assertNotNull(callbackResponse); assertEquals(asylumCase, callbackResponse.getData()); @@ -123,7 +126,7 @@ public void handling_should_throw_if_cannot_actually_handle() { .isExactlyInstanceOf(IllegalStateException.class); when(callback.getEvent()).thenReturn(Event.START_APPEAL); - assertThatThrownBy(() -> internalDecideAnApplicationLetterHandler.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback)) + assertThatThrownBy(() -> internalDecideAnApplicationLetterHandler.handle(ABOUT_TO_SUBMIT, callback)) .hasMessage("Cannot handle callback") .isExactlyInstanceOf(IllegalStateException.class); } @@ -176,7 +179,7 @@ public void it_should_only_handle_about_to_submit_and_decide_an_application_even for (PreSubmitCallbackStage callbackStage : PreSubmitCallbackStage.values()) { boolean canHandle = internalDecideAnApplicationLetterHandler.canHandle(callbackStage, callback); - if (callbackStage == PreSubmitCallbackStage.ABOUT_TO_SUBMIT && callback.getEvent().equals(Event.DECIDE_AN_APPLICATION)) { + if (callbackStage == ABOUT_TO_SUBMIT && callback.getEvent().equals(Event.DECIDE_AN_APPLICATION)) { assertTrue(canHandle); } else { assertFalse(canHandle); @@ -191,7 +194,7 @@ public void it_should_only_handle_about_to_submit_and_decide_an_application_even public void it_should_only_handle_internal_cases(YesOrNo yesOrNo) { when(asylumCase.read(IS_ADMIN, YesOrNo.class)).thenReturn(Optional.of(yesOrNo)); - boolean canHandle = internalDecideAnApplicationLetterHandler.canHandle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback); + boolean canHandle = internalDecideAnApplicationLetterHandler.canHandle(ABOUT_TO_SUBMIT, callback); if (yesOrNo == yes) { assertTrue(canHandle); @@ -205,17 +208,16 @@ public void it_should_only_handle_internal_cases(YesOrNo yesOrNo) { public void it_should_handle_both_internal_detained_cases_and_internal_ada_cases(YesOrNo yesOrNo) { when(asylumCase.read(IS_ACCELERATED_DETAINED_APPEAL, YesOrNo.class)).thenReturn(Optional.of(yesOrNo)); - boolean canHandle = internalDecideAnApplicationLetterHandler.canHandle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback); + boolean canHandle = internalDecideAnApplicationLetterHandler.canHandle(ABOUT_TO_SUBMIT, callback); assertTrue(canHandle); } @ParameterizedTest @ValueSource(strings = {decisionGranted, decisionRefused, decisionPending}) - public void it_should_only_handle_granted_applications(String decision) { + public void it_should_only_generate_the_letter_for_granted_and_refused_applications(String decision) { List> testApplications = new ArrayList<>(); - - MakeAnApplication testApplication = new MakeAnApplication( + final MakeAnApplication testApplication = new MakeAnApplication( "Admin Officer", MakeAnApplicationTypes.ADJOURN.getValue(), "someRandomDetails", @@ -224,19 +226,25 @@ public void it_should_only_handle_granted_applications(String decision) { decision.toString(), 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)); - boolean canHandle = internalDecideAnApplicationLetterHandler.canHandle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback); - - if (decision.equals(decisionGranted.toString())) { - assertTrue(canHandle); + when(internalApplicationDecidedLetterCreator.create(caseDetails)).thenReturn(uploadedDocument); + when(internalApplicationDecidedRefusedLetterCreator.create(caseDetails)).thenReturn(uploadedDocument); + + PreSubmitCallbackResponse callbackResponse = + internalDecideAnApplicationLetterHandler.handle(ABOUT_TO_SUBMIT, callback); + + assertNotNull(callbackResponse); + assertEquals(asylumCase, callbackResponse.getData()); + + if (List.of(decisionGranted, decisionRefused).contains(decision)) { + verify(documentHandler, times(1)).addWithMetadata(asylumCase, uploadedDocument, NOTIFICATION_ATTACHMENT_DOCUMENTS, DocumentTag.INTERNAL_DECIDE_AN_APPLICATION_LETTER); } else { - assertFalse(canHandle); + verify(documentHandler, times(0)).addWithMetadata(asylumCase, uploadedDocument, NOTIFICATION_ATTACHMENT_DOCUMENTS, DocumentTag.INTERNAL_DECIDE_AN_APPLICATION_LETTER); } } @@ -247,7 +255,7 @@ public void should_not_allow_null_arguments() { .hasMessage("callbackStage must not be null") .isExactlyInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> internalDecideAnApplicationLetterHandler.canHandle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, null)) + assertThatThrownBy(() -> internalDecideAnApplicationLetterHandler.canHandle(ABOUT_TO_SUBMIT, null)) .hasMessage("callback must not be null") .isExactlyInstanceOf(NullPointerException.class); @@ -255,7 +263,7 @@ public void should_not_allow_null_arguments() { .hasMessage("callbackStage must not be null") .isExactlyInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> internalDecideAnApplicationLetterHandler.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, null)) + assertThatThrownBy(() -> internalDecideAnApplicationLetterHandler.handle(ABOUT_TO_SUBMIT, null)) .hasMessage("callback must not be null") .isExactlyInstanceOf(NullPointerException.class); } diff --git a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTemplateTest.java b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnApplicationDecisionGrantedLetterTemplateTest.java similarity index 90% rename from src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTemplateTest.java rename to src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnApplicationDecisionGrantedLetterTemplateTest.java index 9c9405e15..28f6b93d3 100644 --- a/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTemplateTest.java +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnApplicationDecisionGrantedLetterTemplateTest.java @@ -30,7 +30,7 @@ @ExtendWith(MockitoExtension.class) @SuppressWarnings("unchecked") @MockitoSettings(strictness = Strictness.LENIENT) -public class InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTemplateTest { +public class InternalDecideAnApplicationDecisionGrantedLetterTemplateTest { @Mock private CaseDetails caseDetails; @Mock @@ -51,18 +51,16 @@ public class InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTempl private final String transferOutOfAdaContent = "Your appeal will continue but will no longer be decided within 25 working days. The Tribunal will change the date of your hearing. The Tribunal will contact you with a new date for your hearing and to tell you what will happen next with your appeal."; private final String internalAdaCustomerServicesTelephoneNumber = "0300 123 1711"; private final String internalAdaCustomerServicesEmailAddress = "IAC-ADA-HW@justice.gov.uk"; - private final String internalDetainedCustomerServicesTelephoneNumber = "0300 123 1711"; - private final String internalDetainedCustomerServicesEmailAddress = "contactia@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 InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTemplate internalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTemplate; + private InternalDecideAnApplicationDecisionGrantedLetterTemplate internalDecideAnApplicationDecisionGrantedLetterTemplate; @BeforeEach void setUp() { - internalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTemplate = - new InternalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTemplate( + internalDecideAnApplicationDecisionGrantedLetterTemplate = + new InternalDecideAnApplicationDecisionGrantedLetterTemplate( templateName, dateProvider, customerServicesProvider, @@ -88,7 +86,7 @@ void dataSetup() { @Test void should_return_template_name() { - assertEquals(templateName, internalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTemplate.getName()); + assertEquals(templateName, internalDecideAnApplicationDecisionGrantedLetterTemplate.getName()); } @ParameterizedTest @@ -112,7 +110,7 @@ void should_map_case_data_to_template_field_values(MakeAnApplicationTypes makeAn when(makeAnApplicationService.getMakeAnApplication(asylumCase, true)).thenReturn(Optional.of(testApplication)); - Map templateFieldValues = internalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTemplate.mapFieldValues(caseDetails); + Map templateFieldValues = internalDecideAnApplicationDecisionGrantedLetterTemplate.mapFieldValues(caseDetails); assertEquals(11, templateFieldValues.size()); assertEquals("[userImage:hmcts.png]", templateFieldValues.get("hmcts")); @@ -158,7 +156,7 @@ void should_throw_exception_if_application_type_cannot_be_parsed() { when(makeAnApplicationService.getMakeAnApplication(asylumCase, true)).thenReturn(Optional.of(testApplication)); - assertThatThrownBy(() -> internalDetainedAndAdaDecideAnApplicationDecisionGrantedLetterTemplate.mapFieldValues(caseDetails)) + assertThatThrownBy(() -> internalDecideAnApplicationDecisionGrantedLetterTemplate.mapFieldValues(caseDetails)) .hasMessage("Application type could not be parsed") .isExactlyInstanceOf(IllegalStateException.class); } 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/InternalDecideAnApplicationDecisionRefusedLetterTemplateTest.java new file mode 100644 index 000000000..2cc53a601 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/iacasedocumentsapi/domain/templates/letter/InternalDecideAnApplicationDecisionRefusedLetterTemplateTest.java @@ -0,0 +1,199 @@ +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.utils.DateUtils.formatDateForNotificationAttachmentDocument; + +import java.time.LocalDate; +import java.util.*; +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.junit.jupiter.params.provider.ValueSource; +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.UserDetailsProvider; +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.UserDetails; +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 InternalDecideAnApplicationDecisionRefusedLetterTemplateTest { + + @Mock + private CaseDetails caseDetails; + @Mock + private AsylumCase asylumCase; + @Mock + private DateProvider dateProvider; + @Mock + private CustomerServicesProvider customerServicesProvider; + @Mock + private MakeAnApplicationService makeAnApplicationService; + @Mock + UserDetailsProvider userDetailsProvider; + @Mock + UserDetails userDetails; + private final String judgeRole = "caseworker-ia-iacjudge"; + private final String legalOfficerRole = "caseworker-ia-caseofficer"; + private final String applicationRefusedAdaFormName = "IAFT-ADA4: Make an application – Accelerated detained appeal (ADA)"; + private final String applicationRefusedDetainedNonAdaFormName = "IAFT-DE4: Make an application – Detained appeal"; + 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 InternalDecideAnApplicationDecisionRefusedLetterTemplate internalDecideAnApplicationDecisionRefusedLetterTemplate; + + @BeforeEach + void setUp() { + internalDecideAnApplicationDecisionRefusedLetterTemplate = + new InternalDecideAnApplicationDecisionRefusedLetterTemplate( + templateName, + dateProvider, + customerServicesProvider, + makeAnApplicationService, + userDetailsProvider + ); + } + + 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()); + + when(userDetailsProvider.getUserDetails()).thenReturn(userDetails); + when(userDetails.getRoles()).thenReturn(List.of(judgeRole)); + + 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, internalDecideAnApplicationDecisionRefusedLetterTemplate.getName()); + } + + @ParameterizedTest + @ValueSource(strings = {judgeRole, legalOfficerRole}) + void should_map_case_data_to_template_field_values_and_map_decision_maker_field_correctly(String role) { + dataSetup(); + + when(userDetailsProvider.getUserDetails().getRoles()).thenReturn(List.of(role)); + + Map templateFieldValues = internalDecideAnApplicationDecisionRefusedLetterTemplate.mapFieldValues(caseDetails); + + assertEquals(12, 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")); + assertEquals(applicationRefusedDetainedNonAdaFormName, templateFieldValues.get("formName")); + + if (role.equals(judgeRole)) { + assertEquals("Judge", templateFieldValues.get("decisionMaker")); + } else if (role.equals(legalOfficerRole)) { + assertEquals("Legal Officer", templateFieldValues.get("decisionMaker")); + } + } + + @ParameterizedTest + @EnumSource(value = YesOrNo.class) + void should_map_case_data_to_template_field_values_and_map_decision_maker_field_correctly(YesOrNo yesOrNo) { + dataSetup(); + when(asylumCase.read(IS_ACCELERATED_DETAINED_APPEAL, YesOrNo.class)).thenReturn(Optional.of(yesOrNo)); + Map templateFieldValues = internalDecideAnApplicationDecisionRefusedLetterTemplate.mapFieldValues(caseDetails); + + assertEquals(12, 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")); + assertEquals("Judge", templateFieldValues.get("decisionMaker")); + + + if (yesOrNo.equals(YesOrNo.YES)) { + assertEquals(applicationRefusedAdaFormName, templateFieldValues.get("formName")); + } else { + assertEquals(applicationRefusedDetainedNonAdaFormName, templateFieldValues.get("formName")); + } + } + + @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(() -> internalDecideAnApplicationDecisionRefusedLetterTemplate.mapFieldValues(caseDetails)) + .hasMessage("Application type could not be parsed") + .isExactlyInstanceOf(IllegalStateException.class); + } +}