Skip to content
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
12 changes: 12 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3058,6 +3058,18 @@ features:
description: >-
If enabled, BurialFormsController will use VANotify::V2::QueueEmailJob instead of
VANotify::EmailJob for confirmation emails
va_notify_v2_simple_forms_email:
actor_type: user
description: >-
If enabled, SimpleFormsApi::Notification::Email will use
VANotify::V2::QueueEmailJob instead of VANotify::EmailJob for both
immediate sends (#send_email_now) and scheduled sends (#enqueue_email)
va_notify_v2_simple_forms_upload_email:
actor_type: user
description: >-
If enabled, SimpleFormsApi::Notification::FormUploadEmail will use
VANotify::V2::QueueEmailJob instead of VANotify::EmailJob for both
immediate sends (#send_email_now) and scheduled sends (#enqueue_email)
va_notify_delivery_status_update_job:
actor_type: user
description: If enabled, VANotify::DelieveryStatusUpdateJob will be used to query VANotify::Notifications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,25 @@ def enqueue_email(at, template_id)
end

def async_job_with_form_data(email, at, template_id)
VANotify::EmailJob.perform_at(
at,
email,
template_id,
get_personalization,
*email_args
)
if Flipper.enabled?(:va_notify_v2_simple_forms_email)
callback_options = email_args.last
VANotify::V2::QueueEmailJob.enqueue_at(
at,
email,
template_id,
get_personalization,
'Settings.vanotify.services.va_gov.api_key',
callback_options
)
else
VANotify::EmailJob.perform_at(
at,
email,
template_id,
get_personalization,
*email_args
)
end
end

def async_job_with_user_account(user_account, at, template_id)
Expand All @@ -137,8 +149,18 @@ def async_job_with_user_account(user_account, at, template_id)
def send_email_now(template_id)
email_address = resolve_notification_email || user&.email
personalization = get_personalization
return unless email_address && personalization

if email_address && personalization
if Flipper.enabled?(:va_notify_v2_simple_forms_email)
callback_options = email_args.last
VANotify::V2::QueueEmailJob.enqueue(
email_address,
template_id,
personalization,
'Settings.vanotify.services.va_gov.api_key',
callback_options
)
Comment thread
rmtolmach marked this conversation as resolved.
else
VANotify::EmailJob.perform_async(
email_address,
template_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,43 @@ def check_if_form_is_supported(config)
end

def send_email_now
VANotify::EmailJob.perform_async(
form_data['email'],
template_id,
get_personalization,
*email_args
)
if Flipper.enabled?(:va_notify_v2_simple_forms_upload_email)
VANotify::V2::QueueEmailJob.enqueue(
form_data['email'],
template_id,
get_personalization,
'Settings.vanotify.services.va_gov.api_key',
{ callback_metadata: { notification_type:, form_number:, confirmation_number:, statsd_tags: } }
)
else
VANotify::EmailJob.perform_async(
form_data['email'],
template_id,
get_personalization,
*email_args
)
end
end

def enqueue_email(at)
VANotify::EmailJob.perform_at(
at,
form_data['email'],
template_id,
get_personalization,
*email_args
)
if Flipper.enabled?(:va_notify_v2_simple_forms_upload_email)
VANotify::V2::QueueEmailJob.enqueue_at(
at,
form_data['email'],
template_id,
get_personalization,
'Settings.vanotify.services.va_gov.api_key',
{ callback_metadata: { notification_type:, form_number:, confirmation_number:, statsd_tags: } }
)
Comment thread
rmtolmach marked this conversation as resolved.
else
VANotify::EmailJob.perform_at(
at,
form_data['email'],
template_id,
get_personalization,
*email_args
)
end
end

def email_args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@
before do
sign_in(user)
allow(Flipper).to receive(:enabled?).with(:simple_forms_email_delivery_callback).and_return(true)
allow(Flipper).to receive(:enabled?).with(:va_notify_v2_simple_forms_email).and_return(false)
end

describe '21_4142' do
Expand Down
130 changes: 117 additions & 13 deletions modules/simple_forms_api/spec/services/notification/email_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
describe SimpleFormsApi::Notification::Email do
let(:lighthouse_updated_at) { Time.current }

before do
allow(Flipper).to receive(:enabled?).with(:va_notify_v2_simple_forms_email).and_return(false)
end

%i[confirmation error received].each do |notification_type|
describe '#initialize' do
context 'when all required arguments are passed in' do
Expand Down Expand Up @@ -220,6 +224,7 @@
context 'flipper is on' do
before do
allow(Flipper).to receive(:enabled?).and_return true
allow(Flipper).to receive(:enabled?).with(:va_notify_v2_simple_forms_email).and_return(false)
end

context 'fetching the template id' do
Expand Down Expand Up @@ -393,6 +398,70 @@
end
end

context 'when va_notify_v2_simple_forms_email is enabled' do
before do
allow(Flipper).to receive(:enabled?).with(:form21_10210_confirmation_email).and_return(true)
allow(Flipper).to receive(:enabled?).with(:va_notify_v2_simple_forms_email).and_return(true)
allow(Flipper).to receive(:enabled?).with(:simple_forms_email_delivery_callback).and_return(false)
allow(VANotify::V2::QueueEmailJob).to receive(:enqueue)
end

it 'sends email via V2 QueueEmailJob' do
subject = described_class.new(config, notification_type:)

subject.send

expect(VANotify::V2::QueueEmailJob).to have_received(:enqueue).with(
a_string_matching(/@/),
a_string_matching(/\S+/),
a_hash_including('confirmation_number'),
'Settings.vanotify.services.va_gov.api_key',
a_hash_including(:callback_metadata)
)
end

it 'does not call V1 EmailJob' do
allow(VANotify::EmailJob).to receive(:perform_async)
subject = described_class.new(config, notification_type:)

subject.send

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

context 'when va_notify_v2_simple_forms_email is disabled' do
before do
allow(Flipper).to receive(:enabled?).with(:form21_10210_confirmation_email).and_return(true)
allow(Flipper).to receive(:enabled?).with(:va_notify_v2_simple_forms_email).and_return(false)
allow(Flipper).to receive(:enabled?).with(:simple_forms_email_delivery_callback).and_return(false)
allow(VANotify::EmailJob).to receive(:perform_async)
end

it 'sends email via V1 EmailJob' do
subject = described_class.new(config, notification_type:)

subject.send

expect(VANotify::EmailJob).to have_received(:perform_async).with(
a_string_matching(/@/),
a_string_matching(/\S+/),
a_hash_including('confirmation_number'),
a_string_matching(/\S+/),
a_hash_including(:callback_metadata)
)
end

it 'does not call V2 QueueEmailJob' do
allow(VANotify::V2::QueueEmailJob).to receive(:enqueue)
subject = described_class.new(config, notification_type:)

subject.send

expect(VANotify::V2::QueueEmailJob).not_to have_received(:enqueue)
end
end

context 'send at time is specified' do
context 'user_account is passed in' do
let(:confirmation_number) { 'confirmation_number' }
Expand Down Expand Up @@ -431,21 +500,56 @@
end

context 'user and user_account are not passed in' do
it 'sends the email at the specified time' do
time = double
allow(VANotify::EmailJob).to receive(:perform_at)
subject = described_class.new(config, notification_type:)
context 'when va_notify_v2_simple_forms_email is disabled' do
it 'sends the email at the specified time via V1' do
time = double
allow(VANotify::EmailJob).to receive(:perform_at)
subject = described_class.new(config, notification_type:)

subject.send(at: time)
subject.send(at: time)

expect(VANotify::EmailJob).to have_received(:perform_at).with(
time,
a_string_matching(/@/),
a_string_matching(/\S+/),
a_hash_including('confirmation_number'),
a_string_matching(/\S+/),
a_hash_including(:callback_metadata)
)
expect(VANotify::EmailJob).to have_received(:perform_at).with(
time,
a_string_matching(/@/),
a_string_matching(/\S+/),
a_hash_including('confirmation_number'),
a_string_matching(/\S+/),
a_hash_including(:callback_metadata)
)
end
end

context 'when va_notify_v2_simple_forms_email is enabled' do
before do
allow(Flipper).to receive(:enabled?).with(:va_notify_v2_simple_forms_email).and_return(true)
allow(VANotify::V2::QueueEmailJob).to receive(:enqueue_at)
end

it 'sends the email at the specified time via V2' do
time = double
subject = described_class.new(config, notification_type:)

subject.send(at: time)

expect(VANotify::V2::QueueEmailJob).to have_received(:enqueue_at).with(
time,
a_string_matching(/@/),
a_string_matching(/\S+/),
a_hash_including('confirmation_number'),
'Settings.vanotify.services.va_gov.api_key',
a_hash_including(:callback_metadata)
)
end

it 'does not call V1 EmailJob' do
time = double
allow(VANotify::EmailJob).to receive(:perform_at)
subject = described_class.new(config, notification_type:)

subject.send(at: time)

expect(VANotify::EmailJob).not_to have_received(:perform_at)
end
end
end
end
Expand Down
Loading
Loading