Skip to content

Commit

Permalink
Merge pull request #3348 from DFE-Digital/LUPEYALPHA-1172-ey-admin-ma…
Browse files Browse the repository at this point in the history
…tching-details

[LUPEYALPHA-1172] EY admin matching details
  • Loading branch information
rjlynch authored Nov 7, 2024
2 parents 641cdc7 + 806c202 commit 635bd4e
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 19 deletions.
4 changes: 4 additions & 0 deletions app/mailers/claim_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ def early_years_payment_provider_email(claim, one_time_password, email)
magic_link: @magic_link
}

if Rails.env.development?
Rails.logger.info("\n\nEmail verification code: #{one_time_password}\n")
end

send_mail(template_ids(claim)[:CLAIM_PROVIDER_EMAIL_TEMPLATE_ID], personalisation)
end

Expand Down
21 changes: 15 additions & 6 deletions app/models/claim/matching_attribute_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,24 @@ def matching_claims
end

# Eligibility attributes
eligibility_ids = eligibility_attributes_groups_to_match.map { |attributes|
eligibility_ids = eligibility_attributes_groups_to_match.flat_map do |attributes|
vals = values_for_attributes(@source_claim.eligibility, attributes)
next if vals.blank?

concatenated_columns = "CONCAT(#{attributes.join(",")})"
policies_to_find_matches.map { |policy|
policy::Eligibility.where("LOWER(#{concatenated_columns}) = LOWER(?)", vals.join)
}
}.compact.flatten.map(&:id)
policies_to_find_matches.map do |policy|
# Not all eligibility models have the same columns
attributes_to_check = attributes & policy::Eligibility.column_names

if attributes_to_check.any?
concatenated_columns = "CONCAT(#{attributes_to_check.join(",")})"

policy::Eligibility.where(
"LOWER(#{concatenated_columns}) = LOWER(?)",
vals
).select(:id)
end
end
end.compact_blank

eligibility_match_query = Claim.where(eligibility_id: eligibility_ids)
match_queries = match_queries.or(eligibility_match_query)
Expand Down
3 changes: 2 additions & 1 deletion app/models/policies/early_career_payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ module EarlyCareerPayments
OTHER_CLAIMABLE_POLICIES = [
LevellingUpPremiumPayments,
StudentLoans,
FurtherEducationPayments
FurtherEducationPayments,
EarlyYearsPayments
].freeze

ELIGIBILITY_MATCHING_ATTRIBUTES = [["teacher_reference_number"]].freeze
Expand Down
13 changes: 7 additions & 6 deletions app/models/policies/early_years_payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ module EarlyYearsPayments

RETENTION_PERIOD = 6.months

OTHER_CLAIMABLE_POLICIES = [
EarlyCareerPayments,
LevellingUpPremiumPayments,
StudentLoans,
FurtherEducationPayments
]

# Percentage of claims to QA
MIN_QA_THRESHOLD = 10

Expand Down Expand Up @@ -54,12 +61,6 @@ module EarlyYearsPayments
:other
]

OTHER_CLAIMABLE_POLICIES = [
EarlyCareerPayments,
StudentLoans,
LevellingUpPremiumPayments
]

# TODO: This is needed once the reply-to email address has been added to Gov Notify
def notify_reply_to_id
nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def applicable_task_names
tasks << "identity_confirmation"
tasks << "student_loan_plan" if claim.submitted_without_slc_data?
tasks << "employment"
tasks << "matching_details" if matching_claims.exists?

tasks
end
Expand Down
3 changes: 2 additions & 1 deletion app/models/policies/further_education_payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module FurtherEducationPayments
OTHER_CLAIMABLE_POLICIES = [
EarlyCareerPayments,
StudentLoans,
LevellingUpPremiumPayments
LevellingUpPremiumPayments,
EarlyYearsPayments
]

ELIGIBILITY_MATCHING_ATTRIBUTES = [["teacher_reference_number"]].freeze
Expand Down
3 changes: 2 additions & 1 deletion app/models/policies/levelling_up_premium_payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module LevellingUpPremiumPayments
OTHER_CLAIMABLE_POLICIES = [
EarlyCareerPayments,
StudentLoans,
FurtherEducationPayments
FurtherEducationPayments,
EarlyYearsPayments
].freeze

ELIGIBILITY_MATCHING_ATTRIBUTES = [["teacher_reference_number"]].freeze
Expand Down
3 changes: 2 additions & 1 deletion app/models/policies/student_loans.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ module StudentLoans
OTHER_CLAIMABLE_POLICIES = [
EarlyCareerPayments,
LevellingUpPremiumPayments,
FurtherEducationPayments
FurtherEducationPayments,
EarlyYearsPayments
]

ELIGIBILITY_MATCHING_ATTRIBUTES = [["teacher_reference_number"]].freeze
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,8 @@ en:
no_response: No response
other: Other
task_questions:
matching_details:
title: Is this claim still valid despite having matching details with other claims?
employment:
title: Is the claimant still working at the current nursery above?
identity_confirmation:
Expand Down
95 changes: 92 additions & 3 deletions spec/models/claim/matching_attribute_finder_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rails_helper"

RSpec.describe Claim::MatchingAttributeFinder do
describe "#matching_claims for ECP/LUP claims" do
describe "#matching_claims" do
let!(:source_claim) {
create(:claim,
first_name: "Genghis",
Expand Down Expand Up @@ -49,10 +49,40 @@
eligibility_attributes: {teacher_reference_number: "0902344"})
}

let!(:fe_claim) {
create(:claim,
:submitted,
first_name: "Genghis",
surname: "Khan",
date_of_birth: Date.new(1162, 5, 31),
national_insurance_number: "QQ891011C",
email_address: "[email protected]",
bank_account_number: "34682151",
bank_sort_code: "972654",
academic_year: AcademicYear.new("2019"),
building_society_roll_number: "123456789/ABCD",
policy: Policies::FurtherEducationPayments,
eligibility_attributes: {teacher_reference_number: "0902344"})
}

let!(:ey_claim) {
create(:claim,
:submitted,
first_name: "Genghis",
surname: "Khan",
date_of_birth: Date.new(1162, 5, 31),
national_insurance_number: "QQ891011C",
email_address: "[email protected]",
bank_account_number: "34682151",
bank_sort_code: "972654",
academic_year: AcademicYear.new("2019"),
policy: Policies::EarlyYearsPayments)
}

subject(:matching_claims) { Claim::MatchingAttributeFinder.new(source_claim).matching_claims }

it "includes only claims for ECP or LUP claims" do
expect(matching_claims).to contain_exactly(lup_claim, student_loans_claim)
it "includes claims for ECP, LUP, FE and EY claims" do
expect(matching_claims).to contain_exactly(lup_claim, student_loans_claim, fe_claim, ey_claim)
end
end

Expand Down Expand Up @@ -211,6 +241,35 @@

expect(matching_claims).to eq([claim_with_matching_attributes])
end

context "when the policy has an array of attributes in ELIGIBILITY_MATCHING_ATTRIBUTES" do # current policies don't do this
before do
allow(Policies::StudentLoans).to receive(:eligibility_matching_attributes) { [["teacher_reference_number", "current_school_id"]] }
end

it "does not include a claim that only partially matches eligibility_matching_attributes" do
create(
:claim,
:submitted,
eligibility_attributes: {teacher_reference_number: "0902344"}
)

expect(matching_claims).to be_empty
end

context "when matching with a claim that has one but not all of the eligibility_matching_attributes" do
it "does not include" do
create(
:claim,
:submitted,
policy: Policies::FurtherEducationPayments,
eligibility_attributes: {teacher_reference_number: "0902344"}
)

expect(matching_claims).to be_empty
end
end
end
end

describe "matching_claims - blank trn" do
Expand Down Expand Up @@ -359,6 +418,12 @@

it { is_expected.not_to include(target_claim) }
end

context "when compared with EY" do
let(:target_policy) { Policies::EarlyYearsPayments }

it { is_expected.to include(target_claim) }
end
end

context "with an LUP claim" do
Expand Down Expand Up @@ -393,6 +458,12 @@

it { is_expected.not_to include(target_claim) }
end

context "when compared with EY" do
let(:target_policy) { Policies::EarlyYearsPayments }

it { is_expected.to include(target_claim) }
end
end

context "with a TSLR claim" do
Expand Down Expand Up @@ -427,6 +498,12 @@

it { is_expected.not_to include(target_claim) }
end

context "when compared with EY" do
let(:target_policy) { Policies::EarlyYearsPayments }

it { is_expected.to include(target_claim) }
end
end

context "with an FE claim" do
Expand Down Expand Up @@ -461,6 +538,12 @@

it { is_expected.not_to include(target_claim) }
end

context "when compared with EY" do
let(:target_policy) { Policies::EarlyYearsPayments }

it { is_expected.to include(target_claim) }
end
end

context "with an IRP claim" do
Expand Down Expand Up @@ -490,6 +573,12 @@
it { is_expected.not_to include(target_claim) }
end

context "when compared with EY" do
let(:target_policy) { Policies::EarlyYearsPayments }

it { is_expected.not_to include(target_claim) }
end

context "when compared with IRP" do
let(:target_policy) { Policies::InternationalRelocationPayments }

Expand Down

0 comments on commit 635bd4e

Please sign in to comment.