Skip to content

Commit

Permalink
Add note on csv upload
Browse files Browse the repository at this point in the history
When the fraud risk csv is uploaded add notes to any claims with
matching details.
  • Loading branch information
rjlynch committed Oct 29, 2024
1 parent c0d68d1 commit 476b4ff
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/forms/admin/fraud_risk_csv_upload_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def save
RiskIndicator.where.not(id: records.map(&:id)).destroy_all

records.each(&:save!)

claims_to_note.each do |claim|
AutomatedChecks::ClaimVerifiers::FraudRisk.new(claim: claim).perform
end
end

true
Expand Down Expand Up @@ -53,5 +57,21 @@ def csv_has_required_headers
def csv_has_required_headers?
csv.headers.include?("field") && csv.headers.include?("value")
end

def claims_to_note
flagged_eligibility_claim_ids = Policies.with_attribute(:teacher_reference_number).flat_map do |policy|
policy::Eligibility
.where(teacher_reference_number: RiskIndicator.teacher_reference_number.select(:value))
.joins(:claim)
.select("claims.id")
end

Claim
.where(
"LOWER(national_insurance_number) IN (?)",
RiskIndicator.national_insurance_number.select("LOWER(value)")
)
.or(Claim.where(id: flagged_eligibility_claim_ids))
end
end
end
4 changes: 4 additions & 0 deletions app/models/policies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ def self.[](policy_type)
def self.constantize(policy)
"Policies::#{policy}".constantize
end

def self.with_attribute(attr)
POLICIES.select { |policy| policy::Eligibility.has_attribute?(attr) }
end
end
2 changes: 2 additions & 0 deletions app/models/risk_indicator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class RiskIndicator < ApplicationRecord
national_insurance_number
].freeze

enum field: SUPPORTED_FIELDS.index_by(&:itself)

validates :field, presence: {
message: "'field' can't be blank"
}
Expand Down
28 changes: 28 additions & 0 deletions spec/features/admin/admin_fraud_prevention_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,34 @@
"This claim cannot be approved because the national insurance number " \
"and teacher reference number are included on the fraud prevention list."
)

visit admin_claim_notes_path(flagged_claim_trn)

within(".hmcts-timeline:first-of-type") do
expect(page).to have_content(
"This claim has been flagged as the " \
"teacher reference number is included on the fraud prevention list."
)
end

visit admin_claim_notes_path(flagged_claim_nino)

within(".hmcts-timeline:first-of-type") do
expect(page).to have_content(
"This claim has been flagged as the " \
"national insurance number is included on the fraud prevention list."
)
end

visit admin_claim_notes_path(flagged_claim_trn_and_nino)

within(".hmcts-timeline:first-of-type") do
expect(page).to have_content(
"This claim has been flagged as the " \
"national insurance number and teacher reference number are included " \
"on the fraud prevention list."
)
end
end
end

Expand Down
42 changes: 42 additions & 0 deletions spec/forms/admin/fraud_risk_csv_upload_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,47 @@
)
).to exist
end

it "adds a note to claims that are flagged" do
claim_1 = create(:claim, national_insurance_number: "qq123456c")

claim_2 = create(
:claim,
eligibility_attributes: {teacher_reference_number: "1234567"}
)

claim_3 = create(
:claim,
national_insurance_number: "qq123456c",
eligibility_attributes: {teacher_reference_number: "1234567"}
)

form.save

expect(claim_1.notes.by_label("fraud_risk").last.body).to eq(
"This claim has been flagged as the national insurance number is " \
"included on the fraud prevention list."
)

expect(claim_2.notes.by_label("fraud_risk").last.body).to eq(
"This claim has been flagged as the teacher reference number is " \
"included on the fraud prevention list."
)

expect(claim_3.notes.by_label("fraud_risk").last.body).to eq(
"This claim has been flagged as the national insurance number and " \
"teacher reference number are included on the fraud prevention list."
)
end

it "doesn't add a note to claims that aren't flagged" do
claim = create(
:claim,
national_insurance_number: "qq123456d",
eligibility_attributes: {teacher_reference_number: "1234568"}
)

expect { form.save }.not_to change { claim.notes.count }
end
end
end

0 comments on commit 476b4ff

Please sign in to comment.