From d21b0c6b0f044b5f2ed417079fce6998bc8798e3 Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Thu, 19 Sep 2024 16:33:44 +0100 Subject: [PATCH 1/2] Match across all policies Requirement is to check for matching claims across all policies, except for IRP, which should only flag matches with other IRP policies. At the minute the only attribute we use on eligibility when checking for matches is TRN, which is present in all the eligibilities we compare, if however we start checking other attributes the db will throw an error as the column may not be present on all eligibilities, hence having to update the "matching_claims - blank trn" test. --- app/models/policies/early_career_payments.rb | 3 +- .../policies/further_education_payments.rb | 10 +- .../policies/levelling_up_premium_payments.rb | 3 +- app/models/policies/student_loans.rb | 3 +- .../claim/matching_attribute_finder_spec.rb | 212 +++++++++++++++++- 5 files changed, 218 insertions(+), 13 deletions(-) diff --git a/app/models/policies/early_career_payments.rb b/app/models/policies/early_career_payments.rb index 9c5f3ffdc3..4985b9e33a 100644 --- a/app/models/policies/early_career_payments.rb +++ b/app/models/policies/early_career_payments.rb @@ -30,7 +30,8 @@ module EarlyCareerPayments # - matching claims with multiple policies: MatchingAttributeFinder OTHER_CLAIMABLE_POLICIES = [ LevellingUpPremiumPayments, - StudentLoans + StudentLoans, + FurtherEducationPayments ].freeze ELIGIBILITY_MATCHING_ATTRIBUTES = [["teacher_reference_number"]].freeze diff --git a/app/models/policies/further_education_payments.rb b/app/models/policies/further_education_payments.rb index 60c3695ef2..8e196eaab8 100644 --- a/app/models/policies/further_education_payments.rb +++ b/app/models/policies/further_education_payments.rb @@ -3,7 +3,15 @@ module FurtherEducationPayments include BasePolicy extend self - OTHER_CLAIMABLE_POLICIES = [] + # Used in + # - checking payments with multiple policies: ClaimsPreventingPaymentFinder + # - matching claims with multiple policies: MatchingAttributeFinder + OTHER_CLAIMABLE_POLICIES = [ + EarlyCareerPayments, + StudentLoans, + LevellingUpPremiumPayments + ] + ELIGIBILITY_MATCHING_ATTRIBUTES = [["teacher_reference_number"]].freeze # Percentage of claims to QA diff --git a/app/models/policies/levelling_up_premium_payments.rb b/app/models/policies/levelling_up_premium_payments.rb index a3f6f8ee1f..cde043421c 100644 --- a/app/models/policies/levelling_up_premium_payments.rb +++ b/app/models/policies/levelling_up_premium_payments.rb @@ -17,7 +17,8 @@ module LevellingUpPremiumPayments # - matching claims with multiple policies: MatchingAttributeFinder OTHER_CLAIMABLE_POLICIES = [ EarlyCareerPayments, - StudentLoans + StudentLoans, + FurtherEducationPayments ].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 881ef113ce..cd967f93c6 100644 --- a/app/models/policies/student_loans.rb +++ b/app/models/policies/student_loans.rb @@ -30,7 +30,8 @@ module StudentLoans # - matching claims with multiple policies: MatchingAttributeFinder OTHER_CLAIMABLE_POLICIES = [ EarlyCareerPayments, - LevellingUpPremiumPayments + LevellingUpPremiumPayments, + FurtherEducationPayments ] ELIGIBILITY_MATCHING_ATTRIBUTES = [["teacher_reference_number"]].freeze diff --git a/spec/models/claim/matching_attribute_finder_spec.rb b/spec/models/claim/matching_attribute_finder_spec.rb index 494ebbc0fa..9b7a76703f 100644 --- a/spec/models/claim/matching_attribute_finder_spec.rb +++ b/spec/models/claim/matching_attribute_finder_spec.rb @@ -277,31 +277,29 @@ it { is_expected.to eq [other_claim] } end - describe "matching_claims - blank trn, another field group with same contract type, blank provision_search" do - before do - stub_const("Policies::FurtherEducationPayments::ELIGIBILITY_MATCHING_ATTRIBUTES", [["teacher_reference_number"], ["provision_search", "contract_type"]]) - end - + describe "matching_claims - blank trn, matching email addresses" do let(:policy) { Policies::FurtherEducationPayments } let!(:source_claim) { - eligibility = create(:further_education_payments_eligibility, :eligible, contract_type: "permanent", provision_search: nil) + eligibility = create(:further_education_payments_eligibility, :eligible) create( :claim, :submitted, policy: policy, - eligibility: eligibility + eligibility: eligibility, + email_address: "match@example.com" ) } let!(:other_claim) { - eligibility = create(:further_education_payments_eligibility, :eligible, contract_type: "permanent", provision_search: nil) + eligibility = create(:further_education_payments_eligibility, :eligible) create( :claim, :submitted, policy: policy, eligibility: eligibility, - surname: Faker::Name.last_name + surname: Faker::Name.last_name, + email_address: "match@example.com" ) } @@ -310,6 +308,202 @@ it { is_expected.to eq [other_claim] } end + describe "matching claims across policies" do + subject(:matching_claims) do + Claim::MatchingAttributeFinder.new(source_claim).matching_claims + end + + let(:source_claim) do + create( + :claim, + :submitted, + policy: source_policy, + email_address: "match@example.com", + academic_year: AcademicYear.current + ) + end + + let!(:target_claim) do + create( + :claim, + :submitted, + policy: target_policy, + email_address: "match@example.com", + academic_year: AcademicYear.current + ) + end + + context "with an ECP claim" do + let(:source_policy) { Policies::EarlyCareerPayments } + + context "when compared with ECP" do + let(:target_policy) { Policies::EarlyCareerPayments } + + it { is_expected.to include(target_claim) } + end + + context "when compared with LUP" do + let(:target_policy) { Policies::LevellingUpPremiumPayments } + + it { is_expected.to include(target_claim) } + end + + context "when compared with TSLR" do + let(:target_policy) { Policies::StudentLoans } + + it { is_expected.to include(target_claim) } + end + + context "when compared with FE" do + let(:target_policy) { Policies::FurtherEducationPayments } + + it { is_expected.to include(target_claim) } + end + + context "when compared with IRP" do + let(:target_policy) { Policies::InternationalRelocationPayments } + + it { is_expected.not_to include(target_claim) } + end + end + + context "with an LUP claim" do + let(:source_policy) { Policies::LevellingUpPremiumPayments } + + context "when compared with ECP" do + let(:target_policy) { Policies::EarlyCareerPayments } + + it { is_expected.to include(target_claim) } + end + + context "when compared with LUP" do + let(:target_policy) { Policies::LevellingUpPremiumPayments } + + it { is_expected.to include(target_claim) } + end + + context "when compared with TSLR" do + let(:target_policy) { Policies::StudentLoans } + + it { is_expected.to include(target_claim) } + end + + context "when compared with FE" do + let(:target_policy) { Policies::FurtherEducationPayments } + + it { is_expected.to include(target_claim) } + end + + context "when compared with IRP" do + let(:target_policy) { Policies::InternationalRelocationPayments } + + it { is_expected.not_to include(target_claim) } + end + end + + context "with a TSLR claim" do + let(:source_policy) { Policies::StudentLoans } + + context "when compared with ECP" do + let(:target_policy) { Policies::EarlyCareerPayments } + + it { is_expected.to include(target_claim) } + end + + context "when compared with LUP" do + let(:target_policy) { Policies::LevellingUpPremiumPayments } + + it { is_expected.to include(target_claim) } + end + + context "when compared with TSLR" do + let(:target_policy) { Policies::StudentLoans } + + it { is_expected.to include(target_claim) } + end + + context "when compared with FE" do + let(:target_policy) { Policies::FurtherEducationPayments } + + it { is_expected.to include(target_claim) } + end + + context "when compared with IRP" do + let(:target_policy) { Policies::InternationalRelocationPayments } + + it { is_expected.not_to include(target_claim) } + end + end + + context "with an FE claim" do + let(:source_policy) { Policies::FurtherEducationPayments } + + context "when compared with ECP" do + let(:target_policy) { Policies::EarlyCareerPayments } + + it { is_expected.to include(target_claim) } + end + + context "when compared with LUP" do + let(:target_policy) { Policies::LevellingUpPremiumPayments } + + it { is_expected.to include(target_claim) } + end + + context "when compared with TSLR" do + let(:target_policy) { Policies::StudentLoans } + + it { is_expected.to include(target_claim) } + end + + context "when compared with FE" do + let(:target_policy) { Policies::FurtherEducationPayments } + + it { is_expected.to include(target_claim) } + end + + context "when compared with IRP" do + let(:target_policy) { Policies::InternationalRelocationPayments } + + it { is_expected.not_to include(target_claim) } + end + end + + context "with an IRP claim" do + let(:source_policy) { Policies::InternationalRelocationPayments } + + context "when compared with ECP" do + let(:target_policy) { Policies::EarlyCareerPayments } + + it { is_expected.not_to include(target_claim) } + end + + context "when compared with LUP" do + let(:target_policy) { Policies::LevellingUpPremiumPayments } + + it { is_expected.not_to include(target_claim) } + end + + context "when compared with TSLR" do + let(:target_policy) { Policies::StudentLoans } + + it { is_expected.not_to include(target_claim) } + end + + context "when compared with FE" do + let(:target_policy) { Policies::FurtherEducationPayments } + + it { is_expected.not_to include(target_claim) } + end + + context "when compared with IRP" do + let(:target_policy) { Policies::InternationalRelocationPayments } + + it { is_expected.to include(target_claim) } + end + end + end + describe "#matching_attributes" do it "returns the attributes that match" do source_claim = create( From 1d48645ffee4ff09f91ba2b84d508ae938757d92 Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Fri, 20 Sep 2024 10:53:24 +0100 Subject: [PATCH 2/2] Remove out of date comment `OTHER_CLAIMABLE_POLICIES` is only used for matching policies, as of `b6c6b4275c` this constant is not used when detecting claims that prevent payments. --- app/models/policies/early_career_payments.rb | 1 - app/models/policies/further_education_payments.rb | 1 - app/models/policies/levelling_up_premium_payments.rb | 1 - app/models/policies/student_loans.rb | 1 - 4 files changed, 4 deletions(-) diff --git a/app/models/policies/early_career_payments.rb b/app/models/policies/early_career_payments.rb index 4985b9e33a..2248580d05 100644 --- a/app/models/policies/early_career_payments.rb +++ b/app/models/policies/early_career_payments.rb @@ -26,7 +26,6 @@ module EarlyCareerPayments POLICY_END_YEAR = AcademicYear.new(2024).freeze # Used in - # - checking payments with multiple policies: ClaimsPreventingPaymentFinder # - matching claims with multiple policies: MatchingAttributeFinder OTHER_CLAIMABLE_POLICIES = [ LevellingUpPremiumPayments, diff --git a/app/models/policies/further_education_payments.rb b/app/models/policies/further_education_payments.rb index 8e196eaab8..1c4e3baa35 100644 --- a/app/models/policies/further_education_payments.rb +++ b/app/models/policies/further_education_payments.rb @@ -4,7 +4,6 @@ module FurtherEducationPayments extend self # Used in - # - checking payments with multiple policies: ClaimsPreventingPaymentFinder # - matching claims with multiple policies: MatchingAttributeFinder OTHER_CLAIMABLE_POLICIES = [ EarlyCareerPayments, diff --git a/app/models/policies/levelling_up_premium_payments.rb b/app/models/policies/levelling_up_premium_payments.rb index cde043421c..827a46e72b 100644 --- a/app/models/policies/levelling_up_premium_payments.rb +++ b/app/models/policies/levelling_up_premium_payments.rb @@ -13,7 +13,6 @@ module LevellingUpPremiumPayments ].freeze # Used in - # - checking payments with multiple policies: ClaimsPreventingPaymentFinder # - matching claims with multiple policies: MatchingAttributeFinder OTHER_CLAIMABLE_POLICIES = [ EarlyCareerPayments, diff --git a/app/models/policies/student_loans.rb b/app/models/policies/student_loans.rb index cd967f93c6..9edd71f051 100644 --- a/app/models/policies/student_loans.rb +++ b/app/models/policies/student_loans.rb @@ -26,7 +26,6 @@ module StudentLoans ACADEMIC_YEARS_QUALIFIED_TEACHERS_CAN_CLAIM_FOR = 11 # Used in - # - checking payments with multiple policies: ClaimsPreventingPaymentFinder # - matching claims with multiple policies: MatchingAttributeFinder OTHER_CLAIMABLE_POLICIES = [ EarlyCareerPayments,