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

VaNotify - Update InProgress1880FormReminder error logic #19070

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ class InProgress1880FormReminder

FORM_NAME = '26-1880'

class MissingICN < StandardError; end

def perform(form_id)
return unless Flipper.enabled?(:in_progress_1880_form_reminder)

in_progress_form = InProgressForm.find(form_id)

veteran = VANotify::Veteran.new(in_progress_form)

return if veteran.first_name.blank?
raise MissingICN, "ICN not found for InProgressForm: #{in_progress_form.id}" if veteran.icn.blank?
return if veteran.icn.blank?

template_id = Settings.vanotify.services.va_gov.template_id.form1880_reminder_email
personalisation_details = {
Expand All @@ -28,6 +27,8 @@ def perform(form_id)
}
OneTimeInProgressReminder.perform_async(in_progress_form.user_account_id, FORM_NAME, template_id,
personalisation_details)
rescue VANotify::Veteran::MPINameError, VANotify::Veteran::MPIError
nil
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
let(:in_progress_form) { create(:in_progress_1880_form, user_uuid: user.uuid) }

describe '#perform' do
it 'fails if ICN is not present' do
it 'skips sending if ICN is not present' do
user_without_icn = double('VANotify::Veteran')
allow(VANotify::Veteran).to receive(:new).and_return(user_without_icn)
allow(user_without_icn).to receive_messages(first_name: 'first_name', icn: nil)
allow(VANotify::Veteran).to receive(:new).and_return(user_without_icn)

allow(VANotify::OneTimeInProgressReminder).to receive(:perform_async)

expect do
Sidekiq::Testing.inline! do
described_class.new.perform(in_progress_form.id)
end.to raise_error(VANotify::InProgress1880FormReminder::MissingICN,
"ICN not found for InProgressForm: #{in_progress_form.id}")
end

expect(VANotify::OneTimeInProgressReminder).not_to have_received(:perform_async)
end

it 'skips sending reminder email if there is no first name' do
Expand All @@ -33,6 +36,30 @@
expect(VANotify::OneTimeInProgressReminder).not_to have_received(:perform_async)
end

it 'rescues VANotify::Veteran::MPIError and returns nil' do
allow(VANotify::OneTimeInProgressReminder).to receive(:perform_async)
allow(VANotify::Veteran).to receive(:new).and_raise(VANotify::Veteran::MPIError)

result = Sidekiq::Testing.inline! do
described_class.new.perform(in_progress_form.id)
end

expect(result).to eq(nil)
expect(VANotify::OneTimeInProgressReminder).not_to have_received(:perform_async)
end

it 'rescues VANotify::Veteran::MPINameError and returns nil' do
allow(VANotify::OneTimeInProgressReminder).to receive(:perform_async)
allow(VANotify::Veteran).to receive(:new).and_raise(VANotify::Veteran::MPINameError)

result = Sidekiq::Testing.inline! do
described_class.new.perform(in_progress_form.id)
end

expect(result).to eq(nil)
expect(VANotify::OneTimeInProgressReminder).not_to have_received(:perform_async)
end

it 'delegates to VANotify::UserAccountJob' do
user_with_icn = double('VANotify::Veteran', icn: 'icn', first_name: 'first_name')
allow(VANotify::Veteran).to receive(:new).and_return(user_with_icn)
Expand Down
Loading