Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.
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
5 changes: 5 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3060,6 +3060,11 @@ features:
description: >-
If enabled, EducationCareerCounselingClaim#send_failure_email will use
VANotify::V2::QueueEmailJob instead of VANotify::EmailJob
va_notify_v2_next_steps_email:
actor_type: user
description: >-
If enabled, RepresentationManagement::V0::NextStepsEmailController will use
VANotify::V2::QueueEmailJob instead of VANotify::EmailJob
va_notify_v2_preneeds_burial_form_job:
actor_type: user
description: >-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,36 @@ class NextStepsEmailController < ApplicationController
def create
data = RepresentationManagement::NextStepsEmailData.new(next_steps_email_params)
if data.valid?
enqueue_email(data)
render json: { message: 'Email enqueued' }, status: :ok
else
render json: { errors: data.errors.full_messages }, status: :unprocessable_entity
end
end

private

def enqueue_email(data)
if Flipper.enabled?(:va_notify_v2_next_steps_email)
api_key_path = 'Settings.vanotify.services.va_gov.api_key'
VANotify::V2::QueueEmailJob.enqueue(
data.email_address,
template_id,
email_personalisation(data),
api_key_path,
email_delivery_callback(data)
Comment thread
nathanbwright marked this conversation as resolved.
)
else
VANotify::EmailJob.perform_async(
data.email_address,
template_id,
email_personalisation(data),
Settings.vanotify.services.va_gov.api_key,
email_delivery_callback(data)
Comment thread
nathanbwright marked this conversation as resolved.
)
render json: { message: 'Email enqueued' }, status: :ok
else
render json: { errors: data.errors.full_messages }, status: :unprocessable_entity
end
end

private

def email_personalisation(data)
{
'first_name' => data.first_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
end

context 'When submitting all fields with valid data' do
before do
allow(Flipper).to receive(:enabled?).with(:va_notify_v2_next_steps_email).and_return(false)
end

it 'responds with a ok status' do
post(base_path, params:)
expect(response).to have_http_status(:ok)
Expand All @@ -35,7 +39,12 @@
end

it 'enqueues the email' do
expect(VANotify::EmailJob).to receive(:perform_async).with(
allow(VANotify::EmailJob).to receive(:perform_async)
allow(VANotify::V2::QueueEmailJob).to receive(:enqueue)

post(base_path, params:)

expect(VANotify::EmailJob).to have_received(:perform_async).with(
params[:next_steps_email][:email_address],
'appoint_a_representative_confirmation_email_template_id', # This is the actual value from the settings file
{
Expand All @@ -59,7 +68,73 @@
}
} }
)
post(base_path, params:)
end
Comment thread
nathanbwright marked this conversation as resolved.

context 'when va_notify_v2_next_steps_email is disabled' do
before do
allow(VANotify::EmailJob).to receive(:perform_async)
end

it 'sends email via V1 EmailJob' do
post(base_path, params:)

expect(VANotify::EmailJob).to have_received(:perform_async).with(
params[:next_steps_email][:email_address],
'appoint_a_representative_confirmation_email_template_id',
{
'first_name' => 'First',
'form name' => 'Form Name',
'form number' => 'Form Number',
'representative type' => 'attorney',
'representative name' => 'Bob Law',
'representative address' => '123 Fake St Bldg 2 Suite 3 Portland, OR 97214 USA'
},
'fake_secret',
{ callback_klass: 'AccreditedRepresentativePortal::EmailDeliveryStatusCallback',
callback_metadata: {
form_number: 'Form Number',
statsd_tags: {
service: 'representation-management',
function: 'appoint_a_representative_confirmation_email'
}
} }
)
end
Comment thread
nathanbwright marked this conversation as resolved.
end

context 'when va_notify_v2_next_steps_email is enabled' do
before do
allow(Flipper).to receive(:enabled?).with(:va_notify_v2_next_steps_email).and_return(true)
allow(VANotify::V2::QueueEmailJob).to receive(:enqueue)
allow(VANotify::EmailJob).to receive(:perform_async)
end

it 'sends email via V2 QueueEmailJob' do
post(base_path, params:)

expect(VANotify::V2::QueueEmailJob).to have_received(:enqueue).with(
params[:next_steps_email][:email_address],
'appoint_a_representative_confirmation_email_template_id',
{
'first_name' => 'First',
'form name' => 'Form Name',
'form number' => 'Form Number',
'representative type' => 'attorney',
'representative name' => 'Bob Law',
'representative address' => '123 Fake St Bldg 2 Suite 3 Portland, OR 97214 USA'
},
'Settings.vanotify.services.va_gov.api_key',
{ callback_klass: 'AccreditedRepresentativePortal::EmailDeliveryStatusCallback',
callback_metadata: {
form_number: 'Form Number',
statsd_tags: {
service: 'representation-management',
function: 'appoint_a_representative_confirmation_email'
}
} }
)
expect(VANotify::EmailJob).not_to have_received(:perform_async)
end
end
end

Expand Down
Loading