From 988d0d55efaa1066604dee989665449f13ca3545 Mon Sep 17 00:00:00 2001 From: Alkesh Vaghmaria Date: Wed, 30 Oct 2024 10:31:53 +0000 Subject: [PATCH 1/4] make magic link otp code logging consistent with other otp logs --- app/mailers/claim_mailer.rb | 4 ++++ 1 file changed, 4 insertions(+) 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 From 1242562a52114522310d61e04c50e1458ad3f4f2 Mon Sep 17 00:00:00 2001 From: Alkesh Vaghmaria Date: Mon, 28 Oct 2024 12:33:35 +0000 Subject: [PATCH 2/4] EY matching claims task --- app/models/claim/matching_attribute_finder.rb | 4 +-- app/models/policies/early_career_payments.rb | 3 +- app/models/policies/early_years_payments.rb | 13 +++---- .../claim_checking_tasks.rb | 1 + .../policies/further_education_payments.rb | 3 +- .../policies/levelling_up_premium_payments.rb | 3 +- app/models/policies/student_loans.rb | 3 +- config/locales/en.yml | 2 ++ .../claim/matching_attribute_finder_spec.rb | 34 +++++++++++++++++-- 9 files changed, 52 insertions(+), 14 deletions(-) diff --git a/app/models/claim/matching_attribute_finder.rb b/app/models/claim/matching_attribute_finder.rb index 25f7005825..5ae00a4632 100644 --- a/app/models/claim/matching_attribute_finder.rb +++ b/app/models/claim/matching_attribute_finder.rb @@ -43,9 +43,9 @@ def matching_claims concatenated_columns = "CONCAT(#{attributes.join(",")})" policies_to_find_matches.map { |policy| - policy::Eligibility.where("LOWER(#{concatenated_columns}) = LOWER(?)", vals.join) + policy::Eligibility.where("LOWER(#{concatenated_columns}) = LOWER(?)", vals.join) if (attributes - policy::Eligibility.column_names).empty? } - }.compact.flatten.map(&:id) + }.flatten.compact.map(&:id) 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..d86a76d4be 100644 --- a/spec/models/claim/matching_attribute_finder_spec.rb +++ b/spec/models/claim/matching_attribute_finder_spec.rb @@ -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 From 3e5d8b77cd34d6491a746817aa2bb5e83e5de1aa Mon Sep 17 00:00:00 2001 From: Alkesh Vaghmaria Date: Wed, 30 Oct 2024 14:34:09 +0000 Subject: [PATCH 3/4] improve MatchingAttributeFinder and spec --- app/models/claim/matching_attribute_finder.rb | 8 ++- .../claim/matching_attribute_finder_spec.rb | 61 ++++++++++++++++++- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/app/models/claim/matching_attribute_finder.rb b/app/models/claim/matching_attribute_finder.rb index 5ae00a4632..410623c701 100644 --- a/app/models/claim/matching_attribute_finder.rb +++ b/app/models/claim/matching_attribute_finder.rb @@ -41,9 +41,9 @@ def matching_claims vals = values_for_attributes(@source_claim.eligibility, attributes) next if vals.blank? - concatenated_columns = "CONCAT(#{attributes.join(",")})" + concatenated_columns = "CONCAT(#{attributes.join(",")})" # current policies will only have a single value in attributes policies_to_find_matches.map { |policy| - policy::Eligibility.where("LOWER(#{concatenated_columns}) = LOWER(?)", vals.join) if (attributes - policy::Eligibility.column_names).empty? + policy::Eligibility.where("LOWER(#{concatenated_columns}) = LOWER(?)", vals.join) if all_attributes_exist_on_the_eligibility(attributes, policy::Eligibility) } }.flatten.compact.map(&:id) @@ -91,5 +91,9 @@ def values_for_attributes(object, attributes) object.read_attribute(attribute) }.reject(&:blank?) end + + def all_attributes_exist_on_the_eligibility(attributes, eligibility) + (attributes - eligibility.column_names).empty? + end end end diff --git a/spec/models/claim/matching_attribute_finder_spec.rb b/spec/models/claim/matching_attribute_finder_spec.rb index d86a76d4be..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", @@ -241,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 @@ -389,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 @@ -423,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 @@ -457,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 @@ -491,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 @@ -520,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 } From 806c202d8da06b38ab8d2eeb6bcfe85ceca8a9b8 Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Fri, 1 Nov 2024 12:06:56 +0000 Subject: [PATCH 4/4] Don't skip check if eligibility is missing attrs If the two eligibilities don't have all the same attributes, rather than skipping the comparison only compare the attributes they have in common. Also uses select rather than pluck so we don't need to run a query for each iteration of the loop --- app/models/claim/matching_attribute_finder.rb | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/app/models/claim/matching_attribute_finder.rb b/app/models/claim/matching_attribute_finder.rb index 410623c701..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(",")})" # current policies will only have a single value in attributes - policies_to_find_matches.map { |policy| - policy::Eligibility.where("LOWER(#{concatenated_columns}) = LOWER(?)", vals.join) if all_attributes_exist_on_the_eligibility(attributes, policy::Eligibility) - } - }.flatten.compact.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) @@ -91,9 +100,5 @@ def values_for_attributes(object, attributes) object.read_attribute(attribute) }.reject(&:blank?) end - - def all_attributes_exist_on_the_eligibility(attributes, eligibility) - (attributes - eligibility.column_names).empty? - end end end