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

MBMS-77352 Added NCA error emails to email notifications #19092

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,8 @@ vanotify:
form21_4142_error_email: form21_4142_error_email_template_id
form21_4142_received_email: form21_4142_received_email_template_id
form40_0247_confirmation_email: form40_0247_confirmation_email_template_id
form40_0247_error_email: form40_0247_error_email_template_id
form40_10007_error_email: form40_10007_error_email_template_id
form526_confirmation_email: fake_template_id
form526_submission_failed_email: fake_template_id
form5490_confirmation_email: form5490_confirmation_email_template_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ class NotificationEmail
},
'vba_40_0247' => {
confirmation: Settings.vanotify.services.va_gov.template_id.form40_0247_confirmation_email,
error: nil,
error: Settings.vanotify.services.va_gov.template_id.form40_0247_error_email,
received: nil
},
'vba_40_10007' => {
confirmation: nil,
error: Settings.vanotify.services.va_gov.template_id.form40_10007_error_email,
received: nil
}
}.freeze
Expand Down Expand Up @@ -160,9 +165,12 @@ def get_email_address_from_form_data
form20_10207_contact_info[0]
when 'vba_40_0247'
form_data['applicant_email']
when 'vba_40_10007'
form_data.dig('application', 'claimant', 'email')
end
end

# rubocop:disable Metrics/MethodLength
def get_first_name_from_form_data
case @form_number
when 'vba_21_0845'
Expand All @@ -183,8 +191,11 @@ def get_first_name_from_form_data
form20_10207_contact_info[1]
when 'vba_40_0247'
form_data.dig('applicant_full_name', 'first')
when 'vba_40_10007'
form_data.dig('application', 'claimant', 'name', 'first')
end
end
# rubocop:enable Metrics/MethodLength

def get_first_name_from_user_account
mpi_response = MPI::Service.new.find_profile_by_identifier(identifier_type: 'ICN', identifier: user_account.icn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@
data['claimant_type'] = 'non-veteran'

subject = described_class.new(config, notification_type:)

subject.send

expect(VANotify::EmailJob).to have_received(:perform_async).with(
Expand Down Expand Up @@ -426,7 +425,7 @@
end
end

context 'template_id is missing', if: notification_type != :confirmation do
context 'template_id is missing', if: notification_type == :received do
let(:data) do
fixture_path = Rails.root.join(
'modules', 'simple_forms_api', 'spec', 'fixtures', 'form_json', 'vba_40_0247.json'
Expand All @@ -446,6 +445,81 @@
end
end

describe '40_10007' do
let(:date_submitted) { Time.zone.today.strftime('%B %d, %Y') }
let(:config) do
{ form_data: data, form_number: 'vba_40_10007',
confirmation_number: 'confirmation_number', date_submitted: }
end

context 'template_id is provided', if: notification_type == :error do
context 'when email is entered' do
let(:data) do
fixture_path = Rails.root.join(
'modules', 'simple_forms_api', 'spec', 'fixtures', 'form_json', 'vba_40_10007.json'
)
JSON.parse(fixture_path.read)
end
end

context 'when email is omitted' do
let(:data) do
fixture_path = Rails.root.join(
'modules', 'simple_forms_api', 'spec', 'fixtures', 'form_json', 'vba_40_10007-min.json'
)
JSON.parse(fixture_path.read)
end

context 'when user is signed in' do
let(:user) { create(:user, :loa3) }

it 'does not send the confirmation email' do
allow(VANotify::EmailJob).to receive(:perform_async)
expect(data['applicant_email']).to be_nil

subject = described_class.new(config, notification_type:)

subject.send

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

context 'when user is not signed in' do
it 'does not send the confirmation email' do
allow(VANotify::EmailJob).to receive(:perform_async)
expect(data['applicant_email']).to be_nil

subject = described_class.new(config)

subject.send

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

context 'template_id is missing', if: notification_type != :error do
let(:data) do
fixture_path = Rails.root.join(
'modules', 'simple_forms_api', 'spec', 'fixtures', 'form_json', 'vba_40_10007.json'
)
JSON.parse(fixture_path.read)
end
let(:user) { create(:user, :loa3) }

it 'sends nothing' do
allow(VANotify::EmailJob).to receive(:perform_async)
subject = described_class.new(config, notification_type:, user:)

subject.send

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

describe '21_0845' do
let(:date_submitted) { Time.zone.today.strftime('%B %d, %Y') }
let(:data) do
Expand Down
Loading