Skip to content

Commit

Permalink
improve MatchingAttributeFinder and spec
Browse files Browse the repository at this point in the history
  • Loading branch information
alkesh committed Oct 30, 2024
1 parent a73661f commit ed5dc73
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
8 changes: 6 additions & 2 deletions app/models/claim/matching_attribute_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
61 changes: 60 additions & 1 deletion spec/models/claim/matching_attribute_finder_spec.rb
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }

Expand Down

0 comments on commit ed5dc73

Please sign in to comment.