From 14ccb3c8e539445fa21abc15386277b5c05b45f9 Mon Sep 17 00:00:00 2001 From: Ian Perera Date: Thu, 24 Oct 2024 12:22:41 -0400 Subject: [PATCH 1/3] 1389: Update InProgress1880FormReminder error logic --- .../in_progress_1880_form_reminder.rb | 7 ++-- .../in_progress_1880_form_reminder_spec.rb | 37 ++++++++++++++++--- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/modules/va_notify/app/sidekiq/va_notify/in_progress_1880_form_reminder.rb b/modules/va_notify/app/sidekiq/va_notify/in_progress_1880_form_reminder.rb index c3adc4666f5..1c57259acf4 100644 --- a/modules/va_notify/app/sidekiq/va_notify/in_progress_1880_form_reminder.rb +++ b/modules/va_notify/app/sidekiq/va_notify/in_progress_1880_form_reminder.rb @@ -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 = { @@ -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 diff --git a/modules/va_notify/spec/sidekiq/in_progress_1880_form_reminder_spec.rb b/modules/va_notify/spec/sidekiq/in_progress_1880_form_reminder_spec.rb index 6ffd161de8a..29f94675a0f 100644 --- a/modules/va_notify/spec/sidekiq/in_progress_1880_form_reminder_spec.rb +++ b/modules/va_notify/spec/sidekiq/in_progress_1880_form_reminder_spec.rb @@ -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 @@ -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) From 4873dfbc4870231b4e90303a441bfe0837b5ccd0 Mon Sep 17 00:00:00 2001 From: Ian Perera Date: Thu, 24 Oct 2024 21:10:36 -0400 Subject: [PATCH 2/3] fix lint --- .../app/sidekiq/va_notify/in_progress_1880_form_reminder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/va_notify/app/sidekiq/va_notify/in_progress_1880_form_reminder.rb b/modules/va_notify/app/sidekiq/va_notify/in_progress_1880_form_reminder.rb index 1c57259acf4..9ea874f65d6 100644 --- a/modules/va_notify/app/sidekiq/va_notify/in_progress_1880_form_reminder.rb +++ b/modules/va_notify/app/sidekiq/va_notify/in_progress_1880_form_reminder.rb @@ -14,7 +14,7 @@ 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? From a5de7840b8d324ba46d32ce9c24914446fd7b49f Mon Sep 17 00:00:00 2001 From: Ian Perera Date: Thu, 24 Oct 2024 21:13:23 -0400 Subject: [PATCH 3/3] fix lint --- .../spec/sidekiq/in_progress_1880_form_reminder_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/va_notify/spec/sidekiq/in_progress_1880_form_reminder_spec.rb b/modules/va_notify/spec/sidekiq/in_progress_1880_form_reminder_spec.rb index 29f94675a0f..3059a72b02e 100644 --- a/modules/va_notify/spec/sidekiq/in_progress_1880_form_reminder_spec.rb +++ b/modules/va_notify/spec/sidekiq/in_progress_1880_form_reminder_spec.rb @@ -47,15 +47,15 @@ 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