diff --git a/app/forms/journeys/further_education_payments/claim_submission_form.rb b/app/forms/journeys/further_education_payments/claim_submission_form.rb index 6feeb5b2bf..83e6eb5582 100644 --- a/app/forms/journeys/further_education_payments/claim_submission_form.rb +++ b/app/forms/journeys/further_education_payments/claim_submission_form.rb @@ -4,7 +4,13 @@ class ClaimSubmissionForm < ::ClaimSubmissionBaseForm def save super - ClaimMailer.further_education_payment_provider_verification_email(claim).deliver_later + if Policies::FurtherEducationPayments.duplicate_claim?(claim) + claim.eligibility.update!(flagged_as_duplicate: true) + else + ClaimMailer.further_education_payment_provider_verification_email(claim).deliver_later + end + + true end private diff --git a/app/models/policies/further_education_payments.rb b/app/models/policies/further_education_payments.rb index ff6d8e82e0..ef1e8ff046 100644 --- a/app/models/policies/further_education_payments.rb +++ b/app/models/policies/further_education_payments.rb @@ -32,5 +32,9 @@ def notify_reply_to_id def verification_due_date_for_claim(claim) (claim.created_at + 2.weeks).to_date end + + def duplicate_claim?(claim) + Claim::MatchingAttributeFinder.new(claim).matching_claims.exists? + end end end diff --git a/config/analytics.yml b/config/analytics.yml index 071d906938..f46111dadd 100644 --- a/config/analytics.yml +++ b/config/analytics.yml @@ -296,6 +296,7 @@ shared: - subject_to_formal_performance_action - subject_to_disciplinary_action - half_teaching_hours + - flagged_as_duplicate :eligible_fe_providers: - id - ukprn diff --git a/db/migrate/20240904105917_add_flagged_as_duplicate_to_further_education_payments_eligibilities.rb b/db/migrate/20240904105917_add_flagged_as_duplicate_to_further_education_payments_eligibilities.rb new file mode 100644 index 0000000000..39e4241b4a --- /dev/null +++ b/db/migrate/20240904105917_add_flagged_as_duplicate_to_further_education_payments_eligibilities.rb @@ -0,0 +1,8 @@ +class AddFlaggedAsDuplicateToFurtherEducationPaymentsEligibilities < ActiveRecord::Migration[7.0] + def change + add_column :further_education_payments_eligibilities, + :flagged_as_duplicate, + :boolean, + default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 4ed500a64b..9e6740d5c2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_08_21_121253) do +ActiveRecord::Schema[7.0].define(version: 2024_09_04_105917) do # These are extensions that must be enabled in order to support this database enable_extension "citext" enable_extension "pg_trgm" @@ -254,6 +254,7 @@ t.boolean "subject_to_disciplinary_action" t.boolean "half_teaching_hours" t.jsonb "verification", default: {} + t.boolean "flagged_as_duplicate", default: false t.index ["possible_school_id"], name: "index_fe_payments_eligibilities_on_possible_school_id" t.index ["school_id"], name: "index_fe_payments_eligibilities_on_school_id" end diff --git a/spec/forms/journeys/further_education_payments/claim_submission_form_spec.rb b/spec/forms/journeys/further_education_payments/claim_submission_form_spec.rb index 526165d6fd..eb1f96d6da 100644 --- a/spec/forms/journeys/further_education_payments/claim_submission_form_spec.rb +++ b/spec/forms/journeys/further_education_payments/claim_submission_form_spec.rb @@ -83,5 +83,30 @@ ) ) 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)) + + first_claim_form = described_class.new(journey_session: journey_session) + second_claim_form = described_class.new(journey_session: journey_session) + + first_claim_form.save + second_claim_form.save + + expect(ClaimMailer).to( + have_received(:further_education_payment_provider_verification_email) + .exactly(1).times + ) + + original_claim = first_claim_form.claim + duplicate_claim = second_claim_form.claim + + expect(original_claim.eligibility.flagged_as_duplicate).to eq(false) + expect(duplicate_claim.eligibility.flagged_as_duplicate).to eq(true) + end end end