diff --git a/app/models/saved_claim/education_benefits/va_1995.rb b/app/models/saved_claim/education_benefits/va_1995.rb index 437be35ae1f..5218dcaf893 100644 --- a/app/models/saved_claim/education_benefits/va_1995.rb +++ b/app/models/saved_claim/education_benefits/va_1995.rb @@ -2,4 +2,46 @@ class SavedClaim::EducationBenefits::VA1995 < SavedClaim::EducationBenefits add_form_and_validation('22-1995') + + # Pulled from https://github.com/department-of-veterans-affairs/vets-website/src/applications/edu-benefits/utils/helpers.jsx#L100 + # & https://github.com/department-of-veterans-affairs/vets-website/blob/main/src/applications/edu-benefits/utils/labels.jsx + BENEFIT_TITLE_FOR_1995 = { + 'chapter30' => 'Montgomery GI Bill (MGIB, Chapter 30)', + 'chapter33Post911' => 'Post-9/11 GI Bill (Chapter 33)', + 'chapter33FryScholarship' => 'Fry Scholarship (Chapter 33)', + 'chapter1606' => 'Montgomery GI Bill Selected Reserve (MGIB-SR, Chapter 1606)', + 'chapter32' => 'Post-Vietnam Era Veterans’ Educational Assistance Program (VEAP, chapter 32)', + 'transferOfEntitlement' => 'Transfer of Entitlement Program (TOE)' + }.freeze + + def after_submit(_user) + return unless Flipper.enabled?(:form1995_confirmation_email) + + parsed_form_data ||= JSON.parse(form) + email = parsed_form_data['email'] + return if email.blank? + + send_confirmation_email(parsed_form_data, email) + end + + private + + def send_confirmation_email(parsed_form_data, email) + VANotify::EmailJob.perform_async( + email, + Settings.vanotify.services.va_gov.template_id.form1995_confirmation_email, + { + 'first_name' => parsed_form.dig('veteranFullName', 'first')&.upcase.presence, + 'benefit' => benefit_claimed(parsed_form_data), + 'date_submitted' => Time.zone.today.strftime('%B %d, %Y'), + 'confirmation_number' => education_benefits_claim.confirmation_number, + 'regional_office_address' => regional_office_address + } + ) + end + + def benefit_claimed(parsed_form_data) + benefit ||= parsed_form_data['benefit'] + BENEFIT_TITLE_FOR_1995[benefit] + end end diff --git a/config/features.yml b/config/features.yml index 8671f2a574c..9086bd943af 100644 --- a/config/features.yml +++ b/config/features.yml @@ -362,6 +362,10 @@ features: actor_type: user description: Enables form 1990 email submission confirmation (VaNotify) enable_in_development: true + form1995_confirmation_email: + actor_type: user + description: Enables form 1995 email submission confirmation (VaNotify) + enable_in_development: true form1990e_confirmation_email: actor_type: user description: Enables form 1990e email submission confirmation (VaNotify) diff --git a/config/settings.yml b/config/settings.yml index a6ecbfb84ba..91e2aadbb10 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -1276,6 +1276,7 @@ vanotify: contact_info_change: fake_template_id form1990_confirmation_email: form1990_confirmation_email_template_id form1990e_confirmation_email: form1990e_confirmation_email_template_id + form1995_confirmation_email: form1995_confirmation_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/spec/models/saved_claim/education_benefits/va1995_spec.rb b/spec/models/saved_claim/education_benefits/va1995_spec.rb index 0c443a3d14c..4d52fa2c9e1 100644 --- a/spec/models/saved_claim/education_benefits/va1995_spec.rb +++ b/spec/models/saved_claim/education_benefits/va1995_spec.rb @@ -9,4 +9,31 @@ it_behaves_like 'saved_claim' validate_inclusion(:form_id, '22-1995') + + describe '#after_submit' do + let(:user) { create(:user) } + + describe 'sends confirmation email for the 1995' do + it 'successfully submits' do + allow(VANotify::EmailJob).to receive(:perform_async) + + subject = create(:va1995_full_form) + confirmation_number = subject.education_benefits_claim.confirmation_number + + subject.after_submit(user) + + expect(VANotify::EmailJob).to have_received(:perform_async).with( + 'test@sample.com', + 'form1995_confirmation_email_template_id', + { + 'first_name' => 'FIRST', + 'benefit' => 'Transfer of Entitlement Program (TOE)', + 'date_submitted' => Time.zone.today.strftime('%B %d, %Y'), + 'confirmation_number' => confirmation_number, + 'regional_office_address' => "P.O. Box 4616\nBuffalo, NY 14240-4616" + } + ) + end + end + end end