Skip to content

Commit

Permalink
Pension submitted email (#20350)
Browse files Browse the repository at this point in the history
* Send Pensions submission in progress email

* Update tests

* Shrink line change count

* Fix typo
  • Loading branch information
TaiWilkin authored Jan 21, 2025
1 parent 051e4f3 commit 56a2453
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 12 deletions.
3 changes: 3 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,9 @@ features:
pension_error_email_notification:
actor_type: cookie_id
description: Toggle sending of the Action Needed email notification
pension_submitted_email_notification:
actor_type: cookie_id
description: Toggle sending of the Submission in Progress email notification
pension_received_email_notification:
actor_type: cookie_id
description: Toggle sending of the Received email notification
Expand Down
3 changes: 3 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,9 @@ vanotify:
error:
template_id: form527ez_error_email_template_id
flipper_id: pension_error_email_notification
submitted:
template_id: form527ez_submitted_email_template_id
flipper_id: pension_submitted_email_notification
received:
template_id: form527ez_received_email_template_id
flipper_id: pension_received_email_notification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ def perform(saved_claim_id, user_account_uuid = nil)

@pension_monitor.track_submission_success(@claim, @intake_service, @user_account_uuid)

send_confirmation_email
if Flipper.enabled?(:pension_submitted_email_notification)
send_submitted_email
else
send_confirmation_email
end

@intake_service.uuid
rescue => e
Expand Down Expand Up @@ -219,6 +223,15 @@ def send_confirmation_email
@pension_monitor.track_send_confirmation_email_failure(@claim, @intake_service, @user_account_uuid, e)
end

##
# VANotify job to send Submission in Progress email to veteran
#
def send_submitted_email
Pensions::NotificationEmail.new(@claim.id).deliver(:submitted)
rescue => e
@pension_monitor.track_send_submitted_email_failure(@claim, @intake_service, @user_account_uuid, e)
end

##
# Delete temporary stamped PDF files for this job instance
# catches any error, logs but does NOT re-raise - prevent job retry
Expand Down
24 changes: 24 additions & 0 deletions modules/pensions/lib/pensions/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,30 @@ def track_send_confirmation_email_failure(claim, lighthouse_service, user_accoun
call_location: caller_locations.first, **additional_context)
end

##
# Tracks the failure to send a Submission in Progress email for a claim.
# @see PensionBenefitIntakeJob
#
# @param claim [Pension::SavedClaim]
# @param lighthouse_service [LighthouseService]
# @param user_account_uuid [String]
# @param e [Exception]
#
def track_send_submitted_email_failure(claim, lighthouse_service, user_account_uuid, e)
additional_context = {
confirmation_number: claim&.confirmation_number,
user_account_uuid:,
claim_id: claim&.id,
benefits_intake_uuid: lighthouse_service&.uuid,
message: e&.message,
tags:
}

track_request('warn', 'Lighthouse::PensionBenefitIntakeJob send_submitted_email failed',
"#{SUBMISSION_STATS_KEY}.send_submitted_failed",
call_location: caller_locations.first, **additional_context)
end

##
# log Sidkiq job cleanup error occurred, this can occur post success or failure
# @see PensionBenefitIntakeJob
Expand Down
24 changes: 24 additions & 0 deletions modules/pensions/spec/lib/pensions/monitor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,30 @@
end
end

describe '#track_send_submitted_email_failure' do
it 'logs sidekiq job send_submitted_email error' do
log = 'Lighthouse::PensionBenefitIntakeJob send_submitted_email failed'
payload = {
claim_id: claim.id,
benefits_intake_uuid: lh_service.uuid,
confirmation_number: claim.confirmation_number,
user_account_uuid: current_user.uuid,
message: monitor_error.message,
tags: monitor.tags
}

expect(monitor).to receive(:track_request).with(
'warn',
log,
"#{submission_stats_key}.send_submitted_failed",
call_location: anything,
**payload
)

monitor.track_send_submitted_email_failure(claim, lh_service, current_user.uuid, monitor_error)
end
end

describe '#track_file_cleanup_error' do
it 'logs sidekiq job ensure file cleanup error' do
log = 'Lighthouse::PensionBenefitIntakeJob cleanup failed'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
let(:location) { 'test_location' }

before do
allow(Flipper).to receive(:enabled?).with(:validate_saved_claims_with_json_schemer).and_return(true)

job.instance_variable_set(:@claim, claim)
allow(Pensions::SavedClaim).to receive(:find).and_return(claim)
allow(claim).to receive_messages(to_pdf: pdf_path, persistent_attachments: [])
Expand All @@ -37,27 +39,57 @@
allow(monitor).to receive :track_submission_retry
end

it 'submits the saved claim successfully' do
allow(job).to receive_messages(process_document: pdf_path, form_submission_pending_or_success: false)
context 'Feature pension_submitted_email_notification=false' do
it 'submits the saved claim successfully' do
allow(Flipper).to receive(:enabled?).with(:pension_submitted_email_notification).and_return(false)
allow(job).to receive_messages(process_document: pdf_path, form_submission_pending_or_success: false)

expect(FormSubmission).to receive(:create)
expect(FormSubmissionAttempt).to receive(:create)
expect(Datadog::Tracing).to receive(:active_trace)
expect(UserAccount).to receive(:find)
expect(FormSubmission).to receive(:create)
expect(FormSubmissionAttempt).to receive(:create)
expect(Datadog::Tracing).to receive(:active_trace)
expect(UserAccount).to receive(:find)

expect(service).to receive(:perform_upload).with(
upload_url: 'test_location', document: pdf_path, metadata: anything, attachments: []
)
expect(job).to receive(:cleanup_file_paths)
expect(service).to receive(:perform_upload).with(
upload_url: 'test_location', document: pdf_path, metadata: anything, attachments: []
)

job.perform(claim.id, :user_uuid)
expect(job).to receive(:send_confirmation_email)
expect(job).not_to receive(:send_submitted_email)
expect(job).to receive(:cleanup_file_paths)

job.perform(claim.id, :user_uuid)
end
end

context 'Feature pension_submitted_email_notification=true' do
it 'submits the saved claim successfully' do
allow(Flipper).to receive(:enabled?).with(:pension_submitted_email_notification).and_return(true)
allow(job).to receive_messages(process_document: pdf_path, form_submission_pending_or_success: false)

expect(FormSubmission).to receive(:create)
expect(FormSubmissionAttempt).to receive(:create)
expect(Datadog::Tracing).to receive(:active_trace)
expect(UserAccount).to receive(:find)

expect(service).to receive(:perform_upload).with(
upload_url: 'test_location', document: pdf_path, metadata: anything, attachments: []
)

expect(job).not_to receive(:send_confirmation_email)
expect(job).to receive(:send_submitted_email)
expect(job).to receive(:cleanup_file_paths)

job.perform(claim.id, :user_uuid)
end
end

it 'is unable to find user_account' do
expect(Pensions::SavedClaim).not_to receive(:find)
expect(BenefitsIntake::Service).not_to receive(:new)
expect(claim).not_to receive(:to_pdf)

expect(job).not_to receive(:send_confirmation_email)
expect(job).not_to receive(:send_submitted_email)
expect(job).to receive(:cleanup_file_paths)

expect { job.perform(claim.id, :user_account_uuid) }.to raise_error(
Expand All @@ -74,6 +106,8 @@
expect(BenefitsIntake::Service).not_to receive(:new)
expect(claim).not_to receive(:to_pdf)

expect(job).not_to receive(:send_confirmation_email)
expect(job).not_to receive(:send_submitted_email)
expect(job).to receive(:cleanup_file_paths)

expect { job.perform(claim.id, :user_account_uuid) }.to raise_error(
Expand Down Expand Up @@ -202,6 +236,28 @@
end
end

describe '#send_submitted_email' do
let(:monitor_error) { create(:monitor_error) }
let(:notification) { double('notification') }

before do
job.instance_variable_set(:@claim, claim)

allow(Pensions::NotificationEmail).to receive(:new).and_return(notification)
allow(notification).to receive(:deliver).and_raise(monitor_error)

job.instance_variable_set(:@pension_monitor, monitor)
allow(monitor).to receive(:track_send_submitted_email_failure)
end

it 'errors and logs but does not reraise' do
expect(Pensions::NotificationEmail).to receive(:new).with(claim.id)
expect(notification).to receive(:deliver).with(:submitted)
expect(monitor).to receive(:track_send_submitted_email_failure)
job.send(:send_submitted_email)
end
end

describe 'sidekiq_retries_exhausted block' do
let(:exhaustion_msg) do
{ 'args' => [], 'class' => 'Pensions::PensionBenefitIntakeJob', 'error_message' => 'An error occured',
Expand Down

0 comments on commit 56a2453

Please sign in to comment.