-
Notifications
You must be signed in to change notification settings - Fork 94
VANotify: 2026 migrate hca to queue email job #27595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
66a861b
b8a746a
6b1a429
09146a4
216bf5b
0554256
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -311,19 +311,19 @@ def log_submission_failure_details | |
| def send_failure_email | ||
| first_name = parsed_form.dig('veteranFullName', 'first') | ||
| template_id = Settings.vanotify.services.health_apps_1010.template_id.form1010_ez_failure_email | ||
| api_key = Settings.vanotify.services.health_apps_1010.api_key | ||
| personalisation = { 'salutation' => first_name ? "Dear #{first_name}," : '' } | ||
| metadata = { callback_metadata: { notification_type: 'error', form_number: FORM_ID, statsd_tags: DD_ZSF_TAGS } } | ||
|
|
||
| salutation = first_name ? "Dear #{first_name}," : '' | ||
| metadata = | ||
| { | ||
| callback_metadata: { | ||
| notification_type: 'error', | ||
| form_number: FORM_ID, | ||
| statsd_tags: DD_ZSF_TAGS | ||
| } | ||
| } | ||
| if Flipper.enabled?(:va_notify_v2_health_care_application_model_send_failure_email) | ||
| VANotify::V2::QueueEmailJob.enqueue( | ||
| email, template_id, personalisation, | ||
| 'Settings.vanotify.services.health_apps_1010.api_key', metadata | ||
| ) | ||
| else | ||
| api_key = Settings.vanotify.services.health_apps_1010.api_key | ||
| VANotify::EmailJob.perform_async(email, template_id, personalisation, api_key, metadata) | ||
| end | ||
|
Comment on lines
312
to
+325
|
||
|
|
||
| VANotify::EmailJob.perform_async(email, template_id, { 'salutation' => salutation }, api_key, metadata) | ||
| StatsD.increment("#{HCA::Service::STATSD_KEY_PREFIX}.submission_failure_email_sent") | ||
| rescue => e | ||
| Rails.logger.error('[10-10EZ] - Failure sending Submission Failure Email', { exception: e }) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -727,6 +727,7 @@ def self.expect_job_submission(job) | |
|
|
||
| before do | ||
| allow(VANotify::EmailJob).to receive(:perform_async) | ||
| allow(VANotify::V2::QueueEmailJob).to receive(:enqueue) | ||
| allow_any_instance_of(MPI::Service).to receive( | ||
| :find_profile_by_attributes | ||
| ).and_return( | ||
|
|
@@ -738,7 +739,6 @@ def self.expect_job_submission(job) | |
| context 'has form' do | ||
| context 'with email address' do | ||
| let(:email_address) { health_care_application.parsed_form['email'] } | ||
| let(:api_key) { Settings.vanotify.services.health_apps_1010.api_key } | ||
| let(:template_id) { Settings.vanotify.services.health_apps_1010.template_id.form1010_ez_failure_email } | ||
| let(:callback_metadata) do | ||
| { | ||
|
|
@@ -749,71 +749,79 @@ def self.expect_job_submission(job) | |
| } | ||
| } | ||
| end | ||
| let(:standard_error) { StandardError.new('Test error') } | ||
|
|
||
| let(:template_params) do | ||
| [ | ||
| email_address, | ||
| template_id, | ||
| { | ||
| 'salutation' => "Dear #{health_care_application.parsed_form['veteranFullName']['first']}," | ||
| }, | ||
| api_key, | ||
| callback_metadata | ||
| ] | ||
| end | ||
| context 'when va_notify_v2_health_care_application_model_send_failure_email is enabled' do | ||
| before do | ||
| allow(Flipper).to receive(:enabled?) | ||
| .with(:va_notify_v2_health_care_application_model_send_failure_email).and_return(true) | ||
| end | ||
|
|
||
| let(:standard_error) { StandardError.new('Test error') } | ||
| it 'sends a failure email using V2 QueueEmailJob' do | ||
| subject | ||
| expect(VANotify::V2::QueueEmailJob).to have_received(:enqueue).with( | ||
| email_address, | ||
| template_id, | ||
| { 'salutation' => "Dear #{health_care_application.parsed_form['veteranFullName']['first']}," }, | ||
| 'Settings.vanotify.services.health_apps_1010.api_key', | ||
| callback_metadata | ||
| ) | ||
| end | ||
|
|
||
| it 'sends a failure email to the email address provided on the form' do | ||
| subject | ||
| expect(VANotify::EmailJob).to have_received(:perform_async).with(*template_params) | ||
| end | ||
| it 'increments statsd' do | ||
| expect { subject }.to trigger_statsd_increment("#{statsd_key_prefix}.submission_failure_email_sent") | ||
| end | ||
|
|
||
| it 'logs error if email job throws error' do | ||
| allow(VANotify::EmailJob).to receive(:perform_async).and_raise(standard_error) | ||
| allow(Rails.logger).to receive(:error) | ||
| expect(Rails.logger).to receive(:error).with( | ||
| '[10-10EZ] - Failure sending Submission Failure Email', | ||
| { exception: standard_error } | ||
| ) | ||
| expect(Rails.logger).to receive(:info).with( | ||
| '[10-10EZ] - HCA total failure', | ||
| { | ||
| first_initial: 'F', | ||
| middle_initial: 'M', | ||
| last_initial: 'Z' | ||
| } | ||
| ) | ||
| expect { subject }.not_to raise_error | ||
| end | ||
| it 'logs error if email job throws error' do | ||
| allow(VANotify::V2::QueueEmailJob).to receive(:enqueue).and_raise(standard_error) | ||
| allow(Rails.logger).to receive(:error) | ||
| expect(Rails.logger).to receive(:error).with( | ||
| '[10-10EZ] - Failure sending Submission Failure Email', | ||
| { exception: standard_error } | ||
| ) | ||
| expect { subject }.not_to raise_error | ||
| end | ||
|
|
||
| it 'increments statsd' do | ||
| expect { subject }.to trigger_statsd_increment("#{statsd_key_prefix}.submission_failure_email_sent") | ||
| context 'without first name' do | ||
| subject do | ||
| health_care_application.parsed_form['veteranFullName'] = nil | ||
| super() | ||
| end | ||
|
|
||
| it 'sends a failure email with empty salutation' do | ||
| subject | ||
| expect(VANotify::V2::QueueEmailJob).to have_received(:enqueue).with( | ||
| email_address, | ||
| template_id, | ||
| { 'salutation' => '' }, | ||
| 'Settings.vanotify.services.health_apps_1010.api_key', | ||
| callback_metadata | ||
| ) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'without first name' do | ||
| subject do | ||
| health_care_application.parsed_form['veteranFullName'] = nil | ||
| super() | ||
| context 'when va_notify_v2_health_care_application_model_send_failure_email is disabled' do | ||
| before do | ||
| allow(Flipper).to receive(:enabled?) | ||
| .with(:va_notify_v2_health_care_application_model_send_failure_email).and_return(false) | ||
| end | ||
|
|
||
| let(:template_params_no_name) do | ||
| [ | ||
| let(:api_key) { Settings.vanotify.services.health_apps_1010.api_key } | ||
|
|
||
| it 'sends a failure email using V1 EmailJob' do | ||
| subject | ||
| expect(VANotify::EmailJob).to have_received(:perform_async).with( | ||
| email_address, | ||
| template_id, | ||
| { | ||
| 'salutation' => '' | ||
| }, | ||
| { 'salutation' => "Dear #{health_care_application.parsed_form['veteranFullName']['first']}," }, | ||
| api_key, | ||
| callback_metadata | ||
| ] | ||
| ) | ||
|
Comment on lines
+760
to
+820
|
||
| end | ||
|
|
||
| let(:standard_error) { StandardError.new('Test error') } | ||
|
|
||
| it 'sends a failure email without personalisations to the email address provided on the form' do | ||
| subject | ||
| expect(VANotify::EmailJob).to have_received(:perform_async).with(*template_params_no_name) | ||
| it 'increments statsd' do | ||
| expect { subject }.to trigger_statsd_increment("#{statsd_key_prefix}.submission_failure_email_sent") | ||
| end | ||
|
|
||
| it 'logs error if email job throws error' do | ||
|
|
@@ -823,16 +831,26 @@ def self.expect_job_submission(job) | |
| '[10-10EZ] - Failure sending Submission Failure Email', | ||
| { exception: standard_error } | ||
| ) | ||
| expect(Rails.logger).to receive(:info).with( | ||
| '[10-10EZ] - HCA total failure', | ||
| { | ||
| first_initial: 'no initial provided', | ||
| middle_initial: 'no initial provided', | ||
| last_initial: 'no initial provided' | ||
| } | ||
| ) | ||
| expect { subject }.not_to raise_error | ||
| end | ||
|
|
||
| context 'without first name' do | ||
| subject do | ||
| health_care_application.parsed_form['veteranFullName'] = nil | ||
| super() | ||
| end | ||
|
|
||
| it 'sends a failure email with empty salutation' do | ||
| subject | ||
| expect(VANotify::EmailJob).to have_received(:perform_async).with( | ||
| email_address, | ||
| template_id, | ||
| { 'salutation' => '' }, | ||
| api_key, | ||
| callback_metadata | ||
| ) | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
send_failure_emailhard-codes the API key path string ('Settings.vanotify.services.health_apps_1010.api_key') inline for the V2 job. Elsewhere the codebase uses anAPI_KEY_PATHconstant for this (e.g.,app/sidekiq/hca/ezr_submission_job.rbandapp/sidekiq/form1010cg/submission_job.rb), which avoids typos and makes future refactors safer. Consider defining a constant onHealthCareApplication(or reusing an existing constant) and using it for the V2 enqueue call (and potentially the V1 path too).