diff --git a/app/controllers/v0/profile/direct_deposits_controller.rb b/app/controllers/v0/profile/direct_deposits_controller.rb index 4d4f6b92316..942a666f594 100644 --- a/app/controllers/v0/profile/direct_deposits_controller.rb +++ b/app/controllers/v0/profile/direct_deposits_controller.rb @@ -88,7 +88,7 @@ def control_info_params end def send_confirmation_email - VANotifyDdEmailJob.send_to_emails(current_user.all_emails, 'comp_and_pen') + VANotifyDdEmailJob.send_to_emails(current_user.all_emails) end end end diff --git a/app/sidekiq/va_notify_dd_email_job.rb b/app/sidekiq/va_notify_dd_email_job.rb index 6a1dcdc4121..1f8a81c0697 100644 --- a/app/sidekiq/va_notify_dd_email_job.rb +++ b/app/sidekiq/va_notify_dd_email_job.rb @@ -10,7 +10,7 @@ class VANotifyDdEmailJob STATSD_ERROR_NAME = 'worker.direct_deposit_confirmation_email.error' STATSD_SUCCESS_NAME = 'worker.direct_deposit_confirmation_email.success' - def self.send_to_emails(user_emails, dd_type) + def self.send_to_emails(user_emails, dd_type = nil) if user_emails.present? user_emails.each do |email| perform_async(email, dd_type) @@ -25,9 +25,9 @@ def self.send_to_emails(user_emails, dd_type) end end - def perform(email, dd_type) + def perform(email, dd_type = nil) notify_client = VaNotify::Service.new(Settings.vanotify.services.va_gov.api_key) - template_type = "direct_deposit_#{dd_type.to_sym == :ch33 ? 'edu' : 'comp_pen'}" + template_type = template_type(dd_type) template_id = Settings.vanotify.services.va_gov.template_id.public_send(template_type) notify_client.send_email( @@ -39,6 +39,13 @@ def perform(email, dd_type) handle_errors(e) end + def template_type(dd_type) + return 'direct_deposit_edu' if dd_type&.to_sym == :ch33 + return 'direct_deposit_comp_pen' if dd_type&.to_sym == :comp_pen + + 'direct_deposit' + end + def handle_errors(ex) VANotifyDdEmailJob.log_exception_to_sentry(ex) StatsD.increment(STATSD_ERROR_NAME) diff --git a/config/settings.yml b/config/settings.yml index c2aecf2c853..4ca4465d021 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -1281,6 +1281,7 @@ vanotify: in_progress_reminder_email_generic: fake_template_id covid_vaccine_registration: fake_template_id covid_vaccine_expanded_registration: fake_template_id + direct_deposit: direct_deposit_template_id direct_deposit_edu: edu_template_id direct_deposit_comp_pen: comp_pen_template_id login_reactivation_email: reactivation_email_test_b diff --git a/spec/controllers/v0/profile/direct_deposits_controller_spec.rb b/spec/controllers/v0/profile/direct_deposits_controller_spec.rb index 1e0af7acae2..3dd8abc3e91 100644 --- a/spec/controllers/v0/profile/direct_deposits_controller_spec.rb +++ b/spec/controllers/v0/profile/direct_deposits_controller_spec.rb @@ -181,7 +181,7 @@ context 'when the user does have an associated email address' do it 'sends an email through va notify' do expect(VANotifyDdEmailJob).to receive(:send_to_emails).with( - user.all_emails, 'comp_and_pen' + user.all_emails ) VCR.use_cassette('lighthouse/direct_deposit/update/200_valid') do diff --git a/spec/sidekiq/va_notify_dd_email_job_spec.rb b/spec/sidekiq/va_notify_dd_email_job_spec.rb index 10a5d528e74..406ee454aa7 100644 --- a/spec/sidekiq/va_notify_dd_email_job_spec.rb +++ b/spec/sidekiq/va_notify_dd_email_job_spec.rb @@ -38,19 +38,42 @@ describe '#perform' do let(:notification_client) { double('Notifications::Client') } - %w[ch33 comp_pen].each do |dd_type| - context "with a dd type of #{dd_type}" do - it 'sends a confirmation email' do - allow(VaNotify::Service).to receive(:new) - .with(Settings.vanotify.services.va_gov.api_key).and_return(notification_client) - - expect(notification_client).to receive(:send_email).with( - email_address: email, - template_id: dd_type == 'ch33' ? 'edu_template_id' : 'comp_pen_template_id' - ) - - described_class.new.perform(email, dd_type) - end + context 'with a dd type of ch33' do + it 'sends a confirmation email using the edu template' do + allow(VaNotify::Service).to receive(:new) + .with(Settings.vanotify.services.va_gov.api_key).and_return(notification_client) + + expect(notification_client).to receive(:send_email).with( + email_address: email, template_id: 'edu_template_id' + ) + + described_class.new.perform(email, 'ch33') + end + end + + context 'with a dd type of comp_pen' do + it 'sends a confirmation email using the comp and pen template' do + allow(VaNotify::Service).to receive(:new) + .with(Settings.vanotify.services.va_gov.api_key).and_return(notification_client) + + expect(notification_client).to receive(:send_email).with( + email_address: email, template_id: 'comp_pen_template_id' + ) + + described_class.new.perform(email, 'comp_pen') + end + end + + context 'without a dd type' do + it 'sends a confirmation email using the direct_deposit template' do + allow(VaNotify::Service).to receive(:new) + .with(Settings.vanotify.services.va_gov.api_key).and_return(notification_client) + + expect(notification_client).to receive(:send_email).with( + email_address: email, template_id: 'direct_deposit_template_id' + ) + + described_class.new.perform(email, nil) end end @@ -89,4 +112,26 @@ .and trigger_statsd_increment('worker.direct_deposit_confirmation_email.error') end end + + describe '#get_template' do + let(:job) { VANotifyDdEmailJob.new } + + context 'when dd_type is nil' do + it 'returns the direct_deposit template' do + expect(job.template_type(nil)).to eq('direct_deposit') + end + end + + context 'when dd_type is comp_pen' do + it 'returns the direct_deposit template' do + expect(job.template_type('comp_pen')).to eq('direct_deposit_comp_pen') + end + end + + context 'when dd_type is edu' do + it 'returns the direct_deposit template' do + expect(job.template_type('edu')).to eq('direct_deposit') + end + end + end end