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

migrate usage if IcnJob to UserAccountJob, with Flipper #18538

Merged
merged 14 commits into from
Sep 24, 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
4 changes: 4 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,10 @@ features:
actor_type: user
description: Enable/disable 526ez in progress form reminders (sent via VaNotify)
enable_in_development: true
va_notify_user_account_job:
actor_type: user
description: Enable/disable UserAccountJob in VANotify (replacement for IcnJob)
enable_in_development: true
letters_check_discrepancies:
actor_type: user
description: Enables ability to log letter discrepancies between evss and lighthouse
Expand Down
2 changes: 1 addition & 1 deletion modules/va_notify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Please note the spelling of the `personalisation` param.

### Using the wrapper sidekiq class (async sending)

Example usage to send an email using the `VANotify::EmailJob` (there is also a `VANotify::IcnJob` for sending via an ICN).
Example usage to send an email using the `VANotify::EmailJob` (there is also a `VANotify::UserAccountJob` for sending via an ICN, [without persisting or logging the ICN](#misc)).
This class defaults to using the va.gov service's api key but you can provide your own service's api key as show below.

```ruby
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class InProgressFormReminder

class MissingICN < StandardError; end

# rubocop:disable Metrics/MethodLength
def perform(form_id)
@in_progress_form = InProgressForm.find(form_id)
return unless enabled?
Expand All @@ -20,14 +21,27 @@ def perform(form_id)

if only_one_supported_in_progress_form?
template_id = VANotify::InProgressFormHelper::TEMPLATE_ID.fetch(in_progress_form.form_id)
IcnJob.perform_async(veteran.icn, template_id, personalisation_details_single)
if Flipper.enabled?(:va_notify_user_account_job)
UserAccountJob.perform_async(veteran.uuid,
template_id,
personalisation_details_single)
else
IcnJob.perform_async(veteran.icn, template_id, personalisation_details_single)
end
elsif oldest_in_progress_form?
template_id = VANotify::InProgressFormHelper::TEMPLATE_ID.fetch('generic')
IcnJob.perform_async(veteran.icn, template_id, personalisation_details_multiple)
if Flipper.enabled?(:va_notify_user_account_job)
UserAccountJob.perform_async(veteran.uuid,
template_id,
personalisation_details_multiple)
else
IcnJob.perform_async(veteran.icn, template_id, personalisation_details_single)
end
end
rescue VANotify::Veteran::MPINameError, VANotify::Veteran::MPIError
nil
end
# rubocop:enable Metrics/MethodLength

private

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ def perform(user_account_id, form_name, template_id, personalisation)
user_account = UserAccount.find(user_account_id)

InProgressRemindersSent.create!(user_account_id:, form_id: form_name)
VANotify::IcnJob.perform_async(user_account.icn, template_id, personalisation)
if Flipper.enabled?(:va_notify_user_account_job)
VANotify::UserAccountJob.perform_async(user_account.id, template_id, personalisation)
else
VANotify::IcnJob.perform_async(user_account.icn, template_id, personalisation)
end
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def perform(
args: { recipient_identifier: { id_value: user_account.id, id_type: 'UserAccountId' },
template_id:, personalisation: }
},
{ error: :va_notify_icn_job }
{ error: :va_notify_user_account_job }
)
else
raise e
Expand Down
55 changes: 27 additions & 28 deletions modules/va_notify/spec/services/in_progress_form_reminder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,71 +13,71 @@
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::IcnJob).to receive(:perform_async)
allow(VANotify::UserAccountJob).to receive(:perform_async)

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

expect(VANotify::IcnJob).not_to have_received(:perform_async)
expect(VANotify::UserAccountJob).not_to have_received(:perform_async)
end

it 'skips sending reminder email if there is no first name' do
veteran_double = double('VaNotify::Veteran')
allow(veteran_double).to receive_messages(icn: 'icn', first_name: nil)
allow(VANotify::Veteran).to receive(:new).and_return(veteran_double)

allow(VANotify::IcnJob).to receive(:perform_async)
allow(VANotify::UserAccountJob).to receive(:perform_async)

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

expect(VANotify::IcnJob).not_to have_received(:perform_async)
expect(VANotify::UserAccountJob).not_to have_received(:perform_async)
end

it 'rescues VANotify::Veteran::MPIError and returns nil' do
allow(VANotify::IcnJob).to receive(:perform_async)
allow(VANotify::UserAccountJob).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::IcnJob).not_to have_received(:perform_async)
expect(VANotify::UserAccountJob).not_to have_received(:perform_async)
end

it 'rescues VANotify::Veteran::MPINameError and returns nil' do
allow(VANotify::IcnJob).to receive(:perform_async)
allow(VANotify::UserAccountJob).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::IcnJob).not_to have_received(:perform_async)
expect(VANotify::UserAccountJob).not_to have_received(:perform_async)
end

describe 'single relevant in_progress_form' do
it 'delegates to VANotify::IcnJob' do
user_with_icn = double('VANotify::Veteran', icn: 'icn', first_name: 'first_name')
it 'delegates to VANotify::UserAccountJob' do
user_with_icn = double('VANotify::Veteran', icn: 'icn', first_name: 'first_name', uuid: 'uuid')
allow(VANotify::Veteran).to receive(:new).and_return(user_with_icn)

allow(VANotify::IcnJob).to receive(:perform_async)
allow(VANotify::UserAccountJob).to receive(:perform_async)
expiration_date = in_progress_form.expires_at.strftime('%B %d, %Y')

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

expect(VANotify::IcnJob).to have_received(:perform_async).with('icn', 'fake_template_id',
{
'first_name' => 'FIRST_NAME',
'date' => expiration_date,
'form_age' => ''
})
expect(VANotify::UserAccountJob).to have_received(:perform_async).with('uuid', 'fake_template_id',
{
'first_name' => 'FIRST_NAME',
'date' => expiration_date,
'form_age' => ''
})
end
end

Expand All @@ -102,21 +102,21 @@
allow(veteran_double).to receive_messages(icn: 'icn', first_name: 'first_name')
allow(VANotify::Veteran).to receive(:new).and_return(veteran_double)

allow(VANotify::IcnJob).to receive(:perform_async)
allow(VANotify::UserAccountJob).to receive(:perform_async)
stub_const('VANotify::FindInProgressForms::RELEVANT_FORMS', %w[686C-674 form_2_id form_3_id])

Sidekiq::Testing.inline! do
described_class.new.perform(in_progress_form_3.id)
end

expect(VANotify::IcnJob).not_to have_received(:perform_async)
expect(VANotify::UserAccountJob).not_to have_received(:perform_async)
end

it 'delegates to VANotify::IcnJob if its the oldest in_progress_form' do
user_with_icn = double('VANotify::Veteran', icn: 'icn', first_name: 'first_name')
it 'delegates to VANotify::UserAccountJob if its the oldest in_progress_form' do
user_with_icn = double('VANotify::Veteran', icn: 'icn', first_name: 'first_name', uuid: 'uuid')
allow(VANotify::Veteran).to receive(:new).and_return(user_with_icn)

allow(VANotify::IcnJob).to receive(:perform_async)
allow(VANotify::UserAccountJob).to receive(:perform_async)
stub_const('VANotify::FindInProgressForms::RELEVANT_FORMS', %w[686C-674 form_2_id form_3_id])
stub_const('VANotify::InProgressFormHelper::FRIENDLY_FORM_SUMMARY', {
'686C-674' => '686c something',
Expand All @@ -139,12 +139,11 @@
end

# rubocop:disable Layout/LineLength
expect(VANotify::IcnJob).to have_received(:perform_async).with('icn', 'fake_template_id',
{
'first_name' => 'FIRST_NAME',

'formatted_form_data' => "\n^ FORM 686C-674\n^\n^__686c something__\n^\n^_Application expires on:_ #{form_1_date}\n\n\n^---\n\n^ FORM form_3_example_id\n^\n^__form_3 something__\n^\n^_Application expires on:_ #{form_3_date}\n\n\n^---\n\n^ FORM form_2_example_id\n^\n^__form_2 something__\n^\n^_Application expires on:_ #{form_2_date}\n\n"
})
expect(VANotify::UserAccountJob).to have_received(:perform_async).with('uuid', 'fake_template_id',
{
'first_name' => 'FIRST_NAME',
'formatted_form_data' => "\n^ FORM 686C-674\n^\n^__686c something__\n^\n^_Application expires on:_ #{form_1_date}\n\n\n^---\n\n^ FORM form_3_example_id\n^\n^__form_3 something__\n^\n^_Application expires on:_ #{form_3_date}\n\n\n^---\n\n^ FORM form_2_example_id\n^\n^__form_2 something__\n^\n^_Application expires on:_ #{form_2_date}\n\n"
})
# rubocop:enable Layout/LineLength
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
expect(VANotify::OneTimeInProgressReminder).not_to have_received(:perform_async)
end

it 'delegates to VANotify::IcnJob' do
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
51 changes: 25 additions & 26 deletions modules/va_notify/spec/sidekiq/in_progress_form_reminder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,47 @@
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::IcnJob).to receive(:perform_async)
allow(VANotify::UserAccountJob).to receive(:perform_async)

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

expect(VANotify::IcnJob).not_to have_received(:perform_async)
expect(VANotify::UserAccountJob).not_to have_received(:perform_async)
end

it 'skips sending reminder email if there is no first name' do
veteran_double = double('VaNotify::Veteran')
allow(veteran_double).to receive_messages(icn: 'icn', first_name: nil)
allow(VANotify::Veteran).to receive(:new).and_return(veteran_double)

allow(VANotify::IcnJob).to receive(:perform_async)
allow(VANotify::UserAccountJob).to receive(:perform_async)

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

expect(VANotify::IcnJob).not_to have_received(:perform_async)
expect(VANotify::UserAccountJob).not_to have_received(:perform_async)
end

describe 'single relevant in_progress_form' do
it 'delegates to VANotify::IcnJob' do
user_with_icn = double('VANotify::Veteran', icn: 'icn', first_name: 'first_name')
allow(VANotify::Veteran).to receive(:new).and_return(user_with_icn)
it 'delegates to VANotify::UserAccountJob' do
user_with_uuid = double('VANotify::Veteran', icn: 'icn', first_name: 'first_name', uuid: 'uuid')
allow(VANotify::Veteran).to receive(:new).and_return(user_with_uuid)

allow(VANotify::IcnJob).to receive(:perform_async)
allow(VANotify::UserAccountJob).to receive(:perform_async)
expiration_date = in_progress_form.expires_at.strftime('%B %d, %Y')

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

expect(VANotify::IcnJob).to have_received(:perform_async).with('icn', 'fake_template_id',
{
'first_name' => 'FIRST_NAME',
'date' => expiration_date,
'form_age' => ''
})
expect(VANotify::UserAccountJob).to have_received(:perform_async).with('uuid', 'fake_template_id',
{
'first_name' => 'FIRST_NAME',
'date' => expiration_date,
'form_age' => ''
})
end
end

Expand All @@ -78,23 +78,23 @@
allow(veteran_double).to receive_messages(icn: 'icn', first_name: 'first_name')
allow(VANotify::Veteran).to receive(:new).and_return(veteran_double)

allow(VANotify::IcnJob).to receive(:perform_async)
allow(VANotify::UserAccountJob).to receive(:perform_async)
stub_const('VANotify::FindInProgressForms::RELEVANT_FORMS', %w[686C-674 form_2_id form_3_id])

Sidekiq::Testing.inline! do
described_class.new.perform(in_progress_form_3.id)
end

expect(VANotify::IcnJob).not_to have_received(:perform_async)
expect(VANotify::UserAccountJob).not_to have_received(:perform_async)
end

it 'delegates to VANotify::IcnJob if its the oldest in_progress_form' do
it 'delegates to VANotify::UserAccountJob if its the oldest in_progress_form' do
Flipper.disable(:in_progress_generic_multiple_template)

user_with_icn = double('VANotify::Veteran', icn: 'icn', first_name: 'first_name')
allow(VANotify::Veteran).to receive(:new).and_return(user_with_icn)
user_with_uuid = double('VANotify::Veteran', icn: 'icn', first_name: 'first_name', uuid: 'uuid')
allow(VANotify::Veteran).to receive(:new).and_return(user_with_uuid)

allow(VANotify::IcnJob).to receive(:perform_async)
allow(VANotify::UserAccountJob).to receive(:perform_async)
stub_const('VANotify::FindInProgressForms::RELEVANT_FORMS', %w[686C-674 form_2_id form_3_id])
stub_const('VANotify::InProgressFormHelper::FRIENDLY_FORM_SUMMARY', {
'686C-674' => '686c something',
Expand All @@ -117,12 +117,11 @@
end

# rubocop:disable Layout/LineLength
expect(VANotify::IcnJob).to have_received(:perform_async).with('icn', 'fake_template_id',
{
'first_name' => 'FIRST_NAME',

'formatted_form_data' => "\n^ FORM 686C-674\n^\n^__686c something__\n^\n^_Application expires on:_ #{form_1_date}\n\n\n^---\n\n^ FORM form_3_example_id\n^\n^__form_3 something__\n^\n^_Application expires on:_ #{form_3_date}\n\n\n^---\n\n^ FORM form_2_example_id\n^\n^__form_2 something__\n^\n^_Application expires on:_ #{form_2_date}\n\n"
})
expect(VANotify::UserAccountJob).to have_received(:perform_async).with('uuid', 'fake_template_id',
{
'first_name' => 'FIRST_NAME',
'formatted_form_data' => "\n^ FORM 686C-674\n^\n^__686c something__\n^\n^_Application expires on:_ #{form_1_date}\n\n\n^---\n\n^ FORM form_3_example_id\n^\n^__form_3 something__\n^\n^_Application expires on:_ #{form_3_date}\n\n\n^---\n\n^ FORM form_2_example_id\n^\n^__form_2 something__\n^\n^_Application expires on:_ #{form_2_date}\n\n"
})
# rubocop:enable Layout/LineLength
end
end
Expand Down
Loading
Loading