Skip to content

Commit

Permalink
Merge pull request #3212 from DFE-Digital/irp-rejected-reason-claimed…
Browse files Browse the repository at this point in the history
…-last-year

CAPT-1818 - IRP add rejection reason for claimed last year
  • Loading branch information
kenfodder authored Sep 24, 2024
2 parents a5461c0 + b5f0f72 commit 178ffac
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
6 changes: 6 additions & 0 deletions app/helpers/claim_mailer_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions app/mailers/claim_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion app/models/policies/international_relocation_payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 7 additions & 2 deletions spec/factories/claims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
eligibility_trait { nil }
eligibility_attributes { nil }
decision_creator { nil }
rejected_reasons { nil }
using_mobile_number_from_tid { false }
end

Expand Down Expand Up @@ -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

Expand Down
32 changes: 30 additions & 2 deletions spec/mailers/claim_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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) }
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 178ffac

Please sign in to comment.