diff --git a/app/mailers/claim_mailer.rb b/app/mailers/claim_mailer.rb index 777ab1f385..e0d248bcb4 100644 --- a/app/mailers/claim_mailer.rb +++ b/app/mailers/claim_mailer.rb @@ -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 diff --git a/app/models/claim/matching_attribute_finder.rb b/app/models/claim/matching_attribute_finder.rb index 25f7005825..04ec51ee0c 100644 --- a/app/models/claim/matching_attribute_finder.rb +++ b/app/models/claim/matching_attribute_finder.rb @@ -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) diff --git a/app/models/policies/early_career_payments.rb b/app/models/policies/early_career_payments.rb index 3495cd8e56..203b3475e4 100644 --- a/app/models/policies/early_career_payments.rb +++ b/app/models/policies/early_career_payments.rb @@ -31,7 +31,8 @@ module EarlyCareerPayments OTHER_CLAIMABLE_POLICIES = [ LevellingUpPremiumPayments, StudentLoans, - FurtherEducationPayments + FurtherEducationPayments, + EarlyYearsPayments ].freeze ELIGIBILITY_MATCHING_ATTRIBUTES = [["teacher_reference_number"]].freeze diff --git a/app/models/policies/early_years_payments.rb b/app/models/policies/early_years_payments.rb index 5912eb9914..eda56863aa 100644 --- a/app/models/policies/early_years_payments.rb +++ b/app/models/policies/early_years_payments.rb @@ -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 @@ -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 diff --git a/app/models/policies/early_years_payments/claim_checking_tasks.rb b/app/models/policies/early_years_payments/claim_checking_tasks.rb index 80c8c9ec49..09b14daf1f 100644 --- a/app/models/policies/early_years_payments/claim_checking_tasks.rb +++ b/app/models/policies/early_years_payments/claim_checking_tasks.rb @@ -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 diff --git a/app/models/policies/further_education_payments.rb b/app/models/policies/further_education_payments.rb index 02d032c6d1..323fdaa035 100644 --- a/app/models/policies/further_education_payments.rb +++ b/app/models/policies/further_education_payments.rb @@ -8,7 +8,8 @@ module FurtherEducationPayments OTHER_CLAIMABLE_POLICIES = [ EarlyCareerPayments, StudentLoans, - LevellingUpPremiumPayments + LevellingUpPremiumPayments, + EarlyYearsPayments ] ELIGIBILITY_MATCHING_ATTRIBUTES = [["teacher_reference_number"]].freeze diff --git a/app/models/policies/levelling_up_premium_payments.rb b/app/models/policies/levelling_up_premium_payments.rb index 2ecc3a79b0..6926875a2f 100644 --- a/app/models/policies/levelling_up_premium_payments.rb +++ b/app/models/policies/levelling_up_premium_payments.rb @@ -18,7 +18,8 @@ module LevellingUpPremiumPayments OTHER_CLAIMABLE_POLICIES = [ EarlyCareerPayments, StudentLoans, - FurtherEducationPayments + FurtherEducationPayments, + EarlyYearsPayments ].freeze ELIGIBILITY_MATCHING_ATTRIBUTES = [["teacher_reference_number"]].freeze diff --git a/app/models/policies/student_loans.rb b/app/models/policies/student_loans.rb index 54687727ff..83454eaaa4 100644 --- a/app/models/policies/student_loans.rb +++ b/app/models/policies/student_loans.rb @@ -31,7 +31,8 @@ module StudentLoans OTHER_CLAIMABLE_POLICIES = [ EarlyCareerPayments, LevellingUpPremiumPayments, - FurtherEducationPayments + FurtherEducationPayments, + EarlyYearsPayments ] ELIGIBILITY_MATCHING_ATTRIBUTES = [["teacher_reference_number"]].freeze diff --git a/config/locales/en.yml b/config/locales/en.yml index 2b73a0a22e..3d42549d03 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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: diff --git a/spec/models/claim/matching_attribute_finder_spec.rb b/spec/models/claim/matching_attribute_finder_spec.rb index bcebac7e54..0749b7aa3a 100644 --- a/spec/models/claim/matching_attribute_finder_spec.rb +++ b/spec/models/claim/matching_attribute_finder_spec.rb @@ -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", @@ -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: "genghis.khan@mongol-empire.com", + 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: "genghis.khan@mongol-empire.com", + 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 }