From b5f0f721bdf0e8597c75d09e37edc4d3c415a5b7 Mon Sep 17 00:00:00 2001 From: Kenneth Lee Date: Fri, 20 Sep 2024 16:30:36 +0100 Subject: [PATCH] CAPT-1818 - IRP add rejection reason for claimed last year --- app/helpers/claim_mailer_helper.rb | 6 ++++ app/mailers/claim_mailer.rb | 1 + .../international_relocation_payments.rb | 3 +- config/locales/en.yml | 1 + spec/factories/claims.rb | 9 ++++-- spec/mailers/claim_mailer_spec.rb | 32 +++++++++++++++++-- 6 files changed, 47 insertions(+), 5 deletions(-) diff --git a/app/helpers/claim_mailer_helper.rb b/app/helpers/claim_mailer_helper.rb index 3cd6dab39c..ad297b4f19 100644 --- a/app/helpers/claim_mailer_helper.rb +++ b/app/helpers/claim_mailer_helper.rb @@ -5,6 +5,12 @@ def rejected_reasons_personalisation(reasons) rejected_reasons_with_answers(reasons) end + def rejected_reason_claimed_last_year? + return false unless @claim.policy == Policies::InternationalRelocationPayments + + @claim.latest_decision&.rejected_reasons_hash&.[](:reason_claimed_last_year) == "1" + end + private def rejected_reasons_with_answers(reasons) diff --git a/app/mailers/claim_mailer.rb b/app/mailers/claim_mailer.rb index ee00fc7970..dc234f8e1c 100644 --- a/app/mailers/claim_mailer.rb +++ b/app/mailers/claim_mailer.rb @@ -35,6 +35,7 @@ def rejected(claim) ref_number: @claim.reference, support_email_address: @support_email_address, current_financial_year: (claim.policy == Policies::StudentLoans) ? Policies::StudentLoans.current_financial_year : "", + last_academic_year: rejected_reason_claimed_last_year? ? (AcademicYear.current - 1).to_s : "", **rejected_reasons_personalisation(@claim.latest_decision&.rejected_reasons_hash) } diff --git a/app/models/policies/international_relocation_payments.rb b/app/models/policies/international_relocation_payments.rb index 1fab9ff267..71b6bc465b 100644 --- a/app/models/policies/international_relocation_payments.rb +++ b/app/models/policies/international_relocation_payments.rb @@ -19,7 +19,8 @@ module InternationalRelocationPayments :no_response_from_school, :suspected_fraud, :information_mismatch_new_details_needed, - :ineligible_previous_residency + :ineligible_previous_residency, + :claimed_last_year ] # Attributes to delete from claims submitted before the current academic diff --git a/config/locales/en.yml b/config/locales/en.yml index 30875ddd66..c0e041b482 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -810,6 +810,7 @@ en: suspected_fraud: Suspected fraud information_mismatch_new_details_needed: "Information mismatch - new details needed" ineligible_previous_residency: Ineligible previous residency + claimed_last_year: "Claimed last year" eligibility_answers: nationality: "Nationality" passport_number: "Passport number" diff --git a/spec/factories/claims.rb b/spec/factories/claims.rb index becd4f94d1..9fb5c21bab 100644 --- a/spec/factories/claims.rb +++ b/spec/factories/claims.rb @@ -10,6 +10,7 @@ eligibility_trait { nil } eligibility_attributes { nil } decision_creator { nil } + rejected_reasons { nil } using_mobile_number_from_tid { false } end @@ -153,9 +154,13 @@ trait :rejected do submitted - after(:build) do |claim| + after(:build) do |claim, evaluator| claim.save - create(:decision, :rejected, claim: claim) + if evaluator.rejected_reasons + create(:decision, :rejected, claim: claim, rejected_reasons: evaluator.rejected_reasons) + else + create(:decision, :rejected, claim: claim) + end end end diff --git a/spec/mailers/claim_mailer_spec.rb b/spec/mailers/claim_mailer_spec.rb index e5a7064d3e..56f577f893 100644 --- a/spec/mailers/claim_mailer_spec.rb +++ b/spec/mailers/claim_mailer_spec.rb @@ -126,6 +126,7 @@ class SomePolicy; end describe "#rejected" do let(:claim) { build(:claim, :rejected, policy: policy) } let(:mail) { ClaimMailer.rejected(claim) } + let(:expected_last_academic_year) { "" } it_behaves_like "an email related to a claim using GOVUK Notify templates", policy @@ -135,7 +136,8 @@ class SomePolicy; end first_name: claim.first_name, ref_number: claim.reference, support_email_address: I18n.t("#{claim.policy.locale_key}.support_email_address"), - current_financial_year: (policy == Policies::StudentLoans) ? Policies::StudentLoans.current_financial_year : "" + current_financial_year: (policy == Policies::StudentLoans) ? Policies::StudentLoans.current_financial_year : "", + last_academic_year: expected_last_academic_year } end let(:all_expected_keys) { expected_common_keys.merge(expected_rejected_reasons_keys) } @@ -228,7 +230,33 @@ class SomePolicy; end reason_no_response_from_school: "no", reason_suspected_fraud: "no", reason_information_mismatch_new_details_needed: "no", - reason_ineligible_previous_residency: "no" + reason_ineligible_previous_residency: "no", + reason_claimed_last_year: "no" + } + end + + include_examples "template id and personalisation keys" + end + + context "when InternationalRelocationPayments, rejected with claimed_last_year", if: policy == Policies::InternationalRelocationPayments do + let(:claim) { build(:claim, :rejected, policy: policy, rejected_reasons: {claimed_last_year: "1"}) } + + let(:expected_last_academic_year) { (journey_configuration.current_academic_year - 1).to_s } + + let(:expected_template_id) { "1edc468c-a1bf-4bea-bb79-042740cd8547" } + + let(:expected_rejected_reasons_keys) do + { + reason_duplicate: "no", + reason_ineligible_school: "no", + reason_invalid_bank_details: "no", + reason_ineligible_visa_or_entry_date: "no", + reason_ineligible_employment_terms: "no", + reason_no_response_from_school: "no", + reason_suspected_fraud: "no", + reason_information_mismatch_new_details_needed: "no", + reason_ineligible_previous_residency: "no", + reason_claimed_last_year: "yes" } end