Skip to content
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

Add direct deposit email notification template #16357

Merged
merged 5 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/v0/profile/direct_deposits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions app/sidekiq/va_notify_dd_email_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
71 changes: 58 additions & 13 deletions spec/sidekiq/va_notify_dd_email_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Loading