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/app/models/policies/early_years_payments/claim_checking_tasks.rb b/app/models/policies/early_years_payments/claim_checking_tasks.rb deleted file mode 100644 index 3b6c104eeb..0000000000 --- a/app/models/policies/early_years_payments/claim_checking_tasks.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -module Policies - module EarlyYearsPayments - class ClaimCheckingTasks - attr_reader :claim - - def initialize(claim) - @claim = claim - end - - delegate :policy, to: :claim - - def applicable_task_names - tasks = [] - - tasks << "matching_details" if matching_claims.exists? - - tasks - end - - private - - def matching_claims - @matching_claims ||= Claim::MatchingAttributeFinder.new(claim).matching_claims - end - 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 }