Skip to content

Commit

Permalink
Handle nil in form_data properly for Form Submission Attempts (#18774)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thrillberg authored Oct 7, 2024
1 parent 3990518 commit 741a2f2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/models/form_submission_attempt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ def log_status_change
private

def enqueue_result_email(notification_type)
raw_form_data = form_submission.form_data || '{}'
form_data = JSON.parse(raw_form_data)
config = {
form_data: JSON.parse(form_submission.form_data),
form_data:,
form_number: form_submission.form_type,
confirmation_number: form_submission.benefits_intake_uuid,
date_submitted: created_at.strftime('%B %d, %Y'),
Expand Down
28 changes: 28 additions & 0 deletions spec/models/form_submission_attempt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,34 @@

expect(notification_email).to have_received(:send)
end

context 'form_data is nil' do
let(:config) do
{
form_data: nil,
form_number: anything,
date_submitted: anything,
lighthouse_updated_at: anything,
confirmation_number: anything
}
end

it 'gracefully handles the nil form_data' do
notification_email = double
allow(JSON).to receive(:parse)
allow(SimpleFormsApi::NotificationEmail).to receive(:new).with(
config,
notification_type:,
user_account: anything
).and_return(notification_email)
allow(notification_email).to receive(:send)
form_submission_attempt = create(:form_submission_attempt)

form_submission_attempt.vbms!

expect(JSON).to have_received(:parse).with('{}')
end
end
end
end

Expand Down

0 comments on commit 741a2f2

Please sign in to comment.