Skip to content

Commit

Permalink
Don't email provider for duplicate claims
Browse files Browse the repository at this point in the history
If a claimant submits multiple claims we don't want to email the
provider to verify these duplicates.
  • Loading branch information
rjlynch committed Sep 4, 2024
1 parent 790f32c commit d8a92b7
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ class ClaimSubmissionForm < ::ClaimSubmissionBaseForm
def save
super

ClaimMailer.further_education_payment_provider_verification_email(claim).deliver_later
unless Policies::FurtherEducationPayments.duplicate_claim?(claim)
ClaimMailer.further_education_payment_provider_verification_email(claim).deliver_later
end

true
end

private
Expand Down
15 changes: 15 additions & 0 deletions app/models/policies/further_education_payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,20 @@ def notify_reply_to_id
def verification_due_date_for_claim(claim)
(claim.created_at + 2.weeks).to_date
end

def duplicate_claim?(claim)
Eligibility
.joins(:claim)
.where(school_id: claim.eligibility.school_id)
.merge(
Claim.where(
first_name: claim.first_name,
surname: claim.surname,
email_address: claim.email_address
)
.where.not(id: claim.id)
)
.exists?
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,20 @@
)
)
end

it "doesn't email the provider if the claim is a duplicate" do
allow(ClaimVerifierJob).to receive(:perform_later)

allow(ClaimMailer).to(
receive(:further_education_payment_provider_verification_email)
).and_return(double(deliver_later: nil))

2.times { described_class.new(journey_session: journey_session).save }

expect(ClaimMailer).to(
have_received(:further_education_payment_provider_verification_email)
.exactly(1).times
)
end
end
end
88 changes: 88 additions & 0 deletions spec/models/policies/further_education_payments_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
require "rails_helper"

RSpec.describe Policies::FurtherEducationPayments do
describe ".duplicate_claim?" do
subject { described_class.duplicate_claim?(candidate_claim) }

let(:existing_claim) do
create(
:claim,
policy: Policies::FurtherEducationPayments,
eligibility: eligibility_1,
first_name: "Edna",
surname: "Krabappel",
email_address: "[email protected]"
)
end

let(:eligibility_1) do
create(
:further_education_payments_eligibility,
school: create(:school)
)
end

let(:eligibility_2) do
create(
:further_education_payments_eligibility,
school: school
)
end

let(:candidate_claim) do
create(
:claim,
policy: Policies::FurtherEducationPayments,
eligibility: eligibility_2,
first_name: first_name,
surname: surname,
email_address: email_address
)
end

context "when the schools are different" do
let(:first_name) { existing_claim.first_name }
let(:surname) { existing_claim.surname }
let(:email_address) { existing_claim.email_address }
let(:school) { create(:school) }

it { is_expected.to be false }
end

context "when the first names are different" do
let(:first_name) { existing_claim.first_name + "different" }
let(:surname) { existing_claim.surname }
let(:email_address) { existing_claim.email_address }
let(:school) { existing_claim.eligibility.school }

it { is_expected.to be false }
end

context "when the last names are different" do
let(:first_name) { existing_claim.first_name }
let(:surname) { existing_claim.surname + "different" }
let(:email_address) { existing_claim.email_address }
let(:school) { existing_claim.eligibility.school }

it { is_expected.to be false }
end

context "when the email_address addresses are different" do
let(:first_name) { existing_claim.first_name }
let(:surname) { existing_claim.surname }
let(:email_address) { "different" + existing_claim.email_address }
let(:school) { existing_claim.eligibility.school }

it { is_expected.to be false }
end

context "when the details match" do
let(:first_name) { existing_claim.first_name }
let(:surname) { existing_claim.surname }
let(:email_address) { existing_claim.email_address }
let(:school) { existing_claim.eligibility.school }

it { is_expected.to be true }
end
end
end

0 comments on commit d8a92b7

Please sign in to comment.