Skip to content

Commit

Permalink
MBMS-77352 Added NCA error emails to email notifications (#19092)
Browse files Browse the repository at this point in the history
* MBMS-77352 Added NCA error emails to email notifications

* MBMS-77352 Added email notifications spec

* MBMS-77352 fixed linting
  • Loading branch information
ksantiagoBAH authored Oct 30, 2024
1 parent 270e3ba commit 995b7c3
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 4 deletions.
2 changes: 2 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,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'
form40_10007_first_name
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 Expand Up @@ -331,5 +342,14 @@ def form21_0966_personalization
end
{ 'intent_to_file_benefits' => intent_to_file_benefits }
end

def form40_10007_first_name
applicant_relationship = form_data.dig('application', 'applicant', 'applicant_relationship_to_claimant')
if applicant_relationship == 'self'
form_data.dig('application', 'veteran', 'current_name', 'first')
else
form_data.dig('application', 'claimant', 'name', 'first')
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
"postal_code": "23432"
},
"phone_number": "3125555678",
"email": "test@test.com",
"name": {
"first": "Freddy",
"middle": "John",
Expand Down
133 changes: 131 additions & 2 deletions modules/simple_forms_api/spec/services/notification_email_spec.rb
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,136 @@
end
end

describe '40_10007 email' 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['application']['claimant']['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 '40-10007 first name' do
subject { described_class.new(config) }

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

context 'when the applicant is the claimant ("self")' do
let(:form_data) do
{
'application' => {
'applicant' => {
'applicant_relationship_to_claimant' => 'self'
},
'veteran' => {
'current_name' => {
'first' => 'Freddy'
}
}
}
}
end

it 'returns the veteran first name' do
expect(subject.instance_eval { form40_10007_first_name }).to eq('Freddy')
end
end

context 'when the applicant is not the claimant' do
let(:form_data) do
{
'application' => {
'applicant' => {
'applicant_relationship_to_claimant' => 'other'
},
'claimant' => {
'name' => {
'first' => 'Jason'
}
}
}
}
end

it 'returns the claimant first name' do
expect(subject.instance_eval { form40_10007_first_name }).to eq('Jason')
end
end
end

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

0 comments on commit 995b7c3

Please sign in to comment.