From 62c09101393d389adeff605cd1a8725575274db8 Mon Sep 17 00:00:00 2001 From: Richard Lynch Date: Wed, 18 Dec 2024 11:47:14 +0000 Subject: [PATCH] Remove policies_claimable This constant was introduced in e25c92f to handle policies not having a trn (part of the moving trn from claim to eligibility work). 806c202d8d introduced some logic to only compare eligibility attributes that both policies have in common and so the policies_claimable constant is redundant. We always want to show a matching claim alert in the admin area even if the policy combination is invalid (eg can't claim for both irp & fe), thus there is no need to limit the policies we look for matches against. --- app/models/base_policy.rb | 10 - app/models/claim/matching_attribute_finder.rb | 11 +- app/models/policies/early_career_payments.rb | 9 - app/models/policies/early_years_payments.rb | 7 - .../policies/further_education_payments.rb | 9 - .../international_relocation_payments.rb | 1 - .../policies/levelling_up_premium_payments.rb | 9 - app/models/policies/student_loans.rb | 9 - spec/models/base_policy_spec.rb | 29 --- .../claim/matching_attribute_finder_spec.rb | 226 ------------------ 10 files changed, 1 insertion(+), 319 deletions(-) diff --git a/app/models/base_policy.rb b/app/models/base_policy.rb index 760f08e92c..fde25a799e 100644 --- a/app/models/base_policy.rb +++ b/app/models/base_policy.rb @@ -25,16 +25,6 @@ def payroll_file_name to_s end - def policies_claimable - return [] unless const_defined?(:OTHER_CLAIMABLE_POLICIES) - - [self] + self::OTHER_CLAIMABLE_POLICIES - end - - def policy_eligibilities_claimable - policies_claimable.map { |p| p::Eligibility } - end - def eligibility_matching_attributes return [] unless const_defined?(:ELIGIBILITY_MATCHING_ATTRIBUTES) diff --git a/app/models/claim/matching_attribute_finder.rb b/app/models/claim/matching_attribute_finder.rb index 04ec51ee0c..352db6a044 100644 --- a/app/models/claim/matching_attribute_finder.rb +++ b/app/models/claim/matching_attribute_finder.rb @@ -41,7 +41,7 @@ def matching_claims vals = values_for_attributes(@source_claim.eligibility, attributes) next if vals.blank? - policies_to_find_matches.map do |policy| + Policies::POLICIES.map do |policy| # Not all eligibility models have the same columns attributes_to_check = attributes & policy::Eligibility.column_names @@ -76,22 +76,13 @@ def matching_attributes(other_claim) private - def policies_to_find_matches - @source_claim.policy.policies_claimable - end - def eligibility_attributes_groups_to_match @source_claim.policy.eligibility_matching_attributes end - def policies_to_find_matches_eligibility_types - policies_to_find_matches.map { |policy| policy::Eligibility.to_s } - end - def claims_to_compare Claim .by_academic_year(@source_claim.academic_year) - .by_policies(policies_to_find_matches) .where.not(id: @source_claim.id) end diff --git a/app/models/policies/early_career_payments.rb b/app/models/policies/early_career_payments.rb index bc5f165769..029c74c7d9 100644 --- a/app/models/policies/early_career_payments.rb +++ b/app/models/policies/early_career_payments.rb @@ -26,15 +26,6 @@ module EarlyCareerPayments POLICY_START_YEAR = AcademicYear.new(2021).freeze POLICY_END_YEAR = AcademicYear.new(2024).freeze - # Used in - # - matching claims with multiple policies: MatchingAttributeFinder - OTHER_CLAIMABLE_POLICIES = [ - LevellingUpPremiumPayments, - StudentLoans, - FurtherEducationPayments, - EarlyYearsPayments - ].freeze - ELIGIBILITY_MATCHING_ATTRIBUTES = [["teacher_reference_number"]].freeze SEARCHABLE_ELIGIBILITY_ATTRIBUTES = %w[teacher_reference_number].freeze diff --git a/app/models/policies/early_years_payments.rb b/app/models/policies/early_years_payments.rb index 379385bd7c..781fe636d6 100644 --- a/app/models/policies/early_years_payments.rb +++ b/app/models/policies/early_years_payments.rb @@ -6,13 +6,6 @@ module EarlyYearsPayments POLICY_START_DATE = Date.new(2024, 11, 11) RETENTION_PERIOD = 6.months - OTHER_CLAIMABLE_POLICIES = [ - EarlyCareerPayments, - LevellingUpPremiumPayments, - StudentLoans, - FurtherEducationPayments - ] - # Percentage of claims to QA MIN_QA_THRESHOLD = 10 diff --git a/app/models/policies/further_education_payments.rb b/app/models/policies/further_education_payments.rb index 323fdaa035..1bae275c9c 100644 --- a/app/models/policies/further_education_payments.rb +++ b/app/models/policies/further_education_payments.rb @@ -3,15 +3,6 @@ module FurtherEducationPayments include BasePolicy extend self - # Used in - # - matching claims with multiple policies: MatchingAttributeFinder - OTHER_CLAIMABLE_POLICIES = [ - EarlyCareerPayments, - StudentLoans, - LevellingUpPremiumPayments, - EarlyYearsPayments - ] - ELIGIBILITY_MATCHING_ATTRIBUTES = [["teacher_reference_number"]].freeze # Percentage of claims to QA diff --git a/app/models/policies/international_relocation_payments.rb b/app/models/policies/international_relocation_payments.rb index 963bb5d07d..a828aa6492 100644 --- a/app/models/policies/international_relocation_payments.rb +++ b/app/models/policies/international_relocation_payments.rb @@ -8,7 +8,6 @@ module InternationalRelocationPayments ].freeze ELIGIBILITY_MATCHING_ATTRIBUTES = [["passport_number"]].freeze - OTHER_CLAIMABLE_POLICIES = [] # Percentage of claims to QA MIN_QA_THRESHOLD = 100 diff --git a/app/models/policies/levelling_up_premium_payments.rb b/app/models/policies/levelling_up_premium_payments.rb index e2a41761a7..1a6f81f769 100644 --- a/app/models/policies/levelling_up_premium_payments.rb +++ b/app/models/policies/levelling_up_premium_payments.rb @@ -13,15 +13,6 @@ module LevellingUpPremiumPayments AutomatedChecks::ClaimVerifiers::FraudRisk ].freeze - # Used in - # - matching claims with multiple policies: MatchingAttributeFinder - OTHER_CLAIMABLE_POLICIES = [ - EarlyCareerPayments, - StudentLoans, - FurtherEducationPayments, - EarlyYearsPayments - ].freeze - ELIGIBILITY_MATCHING_ATTRIBUTES = [["teacher_reference_number"]].freeze SEARCHABLE_ELIGIBILITY_ATTRIBUTES = %w[teacher_reference_number].freeze diff --git a/app/models/policies/student_loans.rb b/app/models/policies/student_loans.rb index 16862dba0f..8aee4f0c2b 100644 --- a/app/models/policies/student_loans.rb +++ b/app/models/policies/student_loans.rb @@ -26,15 +26,6 @@ module StudentLoans POLICY_END_YEAR = AcademicYear.new(2020).freeze ACADEMIC_YEARS_QUALIFIED_TEACHERS_CAN_CLAIM_FOR = 11 - # Used in - # - matching claims with multiple policies: MatchingAttributeFinder - OTHER_CLAIMABLE_POLICIES = [ - EarlyCareerPayments, - LevellingUpPremiumPayments, - FurtherEducationPayments, - EarlyYearsPayments - ] - ELIGIBILITY_MATCHING_ATTRIBUTES = [["teacher_reference_number"]].freeze SEARCHABLE_ELIGIBILITY_ATTRIBUTES = %w[teacher_reference_number].freeze diff --git a/spec/models/base_policy_spec.rb b/spec/models/base_policy_spec.rb index f4ee6b97bd..6922521a4c 100644 --- a/spec/models/base_policy_spec.rb +++ b/spec/models/base_policy_spec.rb @@ -24,11 +24,6 @@ module TestPolicy extend self - OTHER_CLAIMABLE_POLICIES = [ - TestPolicyA, - TestPolicyB - ].freeze - ELIGIBILITY_MATCHING_ATTRIBUTES = [["some_reference"]].freeze SEARCHABLE_ELIGIBILITY_ATTRIBUTES = %w[some_searchable_reference].freeze @@ -69,30 +64,6 @@ class Eligibility end end - describe "::policies_claimable" do - it do - expect(Policies::TestPolicy.policies_claimable).to contain_exactly( - Policies::TestPolicy, Policies::TestPolicyA, Policies::TestPolicyB - ) - end - - it do - expect(Policies::TestPolicyA.policies_claimable).to be_empty - end - end - - describe "::policy_eligibilities_claimable" do - it do - expect(Policies::TestPolicy.policy_eligibilities_claimable).to contain_exactly( - Policies::TestPolicy::Eligibility, Policies::TestPolicyA::Eligibility, Policies::TestPolicyB::Eligibility - ) - end - - it do - expect(Policies::TestPolicyA.policy_eligibilities_claimable).to be_empty - end - end - describe "::eligibility_matching_attributes" do it do expect(Policies::TestPolicy.eligibility_matching_attributes).to contain_exactly(["some_reference"]) diff --git a/spec/models/claim/matching_attribute_finder_spec.rb b/spec/models/claim/matching_attribute_finder_spec.rb index 0749b7aa3a..79bb32c4ea 100644 --- a/spec/models/claim/matching_attribute_finder_spec.rb +++ b/spec/models/claim/matching_attribute_finder_spec.rb @@ -361,232 +361,6 @@ 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 - - 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 - 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 - - 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 - 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 - - 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 - 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 - - 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 - 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 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 } - - it { is_expected.to include(target_claim) } - end - end - end - describe "#matching_attributes" do it "returns the attributes that match" do source_claim = create(