diff --git a/config/settings.yml b/config/settings.yml index c8ecedf8253..a8623cabe5d 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -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 diff --git a/modules/simple_forms_api/app/services/simple_forms_api/notification_email.rb b/modules/simple_forms_api/app/services/simple_forms_api/notification_email.rb index 066470ae7df..52748b458ef 100644 --- a/modules/simple_forms_api/app/services/simple_forms_api/notification_email.rb +++ b/modules/simple_forms_api/app/services/simple_forms_api/notification_email.rb @@ -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 @@ -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' @@ -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) diff --git a/modules/simple_forms_api/spec/services/notification_email_spec.rb b/modules/simple_forms_api/spec/services/notification_email_spec.rb index d5f3168f6fc..eb8db07618b 100644 --- a/modules/simple_forms_api/spec/services/notification_email_spec.rb +++ b/modules/simple_forms_api/spec/services/notification_email_spec.rb @@ -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( @@ -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' @@ -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