Skip to content

Commit

Permalink
Fixes missing reference for claim
Browse files Browse the repository at this point in the history
If the form is invalid, say the journey session has already been
submitted and the user double clicks the submit button, we need to
return early from the child `save` method to avoid calling the mailer
with a claim that hasn't been saved (which triggeres an error as the
claim has no reference number).
  • Loading branch information
rjlynch committed Oct 14, 2024
1 parent 0f1bd2e commit 03c8941
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/forms/claim_submission_base_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def save

ClaimMailer.submitted(claim).deliver_later
ClaimVerifierJob.perform_later(claim)

true
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Journeys
module FurtherEducationPayments
class ClaimSubmissionForm < ::ClaimSubmissionBaseForm
def save
super
return false unless super

if Policies::FurtherEducationPayments.duplicate_claim?(claim)
claim.eligibility.update!(flagged_as_duplicate: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@
).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

journey_session.update! claim: nil
second_claim_form = described_class.new(journey_session: journey_session)

second_claim_form.save

expect(ClaimMailer).to(
Expand Down

0 comments on commit 03c8941

Please sign in to comment.