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 58c87eeddd5..cb2a600b152 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 @@ -143,12 +143,23 @@ def async_job_with_user_account(user_account, at, template_id) first_name_from_user_account = get_first_name_from_user_account return unless first_name_from_user_account - VANotify::UserAccountJob.perform_at( - at, - user_account.id, - template_id, - get_personalization(first_name_from_user_account) - ) + if Flipper.enabled?(:simple_forms_notification_callbacks) + VANotify::UserAccountJob.perform_at( + at, + user_account.id, + template_id, + get_personalization(first_name_from_user_account), + Settings.vanotify.services.va_gov.api_key, + { callback_metadata: { notification_type:, form_number:, statsd_tags: } } + ) + else + VANotify::UserAccountJob.perform_at( + at, + user_account.id, + template_id, + get_personalization(first_name_from_user_account) + ) + end end def send_email_now(template_id) 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 f8aae6aeb10..0eb4d3b6274 100644 --- a/modules/simple_forms_api/spec/services/notification_email_spec.rb +++ b/modules/simple_forms_api/spec/services/notification_email_spec.rb @@ -117,7 +117,7 @@ let(:user_account) { create(:user_account) } it 'sends the email at the specified time' do - time = double + time = Time.zone.now profile = double(given_names: ['Bob']) mpi_profile = double(profile:, error: nil) allow(VANotify::UserAccountJob).to receive(:perform_at) @@ -126,8 +126,27 @@ subject.send(at: time) - expect(VANotify::UserAccountJob).to have_received(:perform_at).with(time, user_account.id, anything, - anything) + expect(VANotify::UserAccountJob).to have_received(:perform_at).with( + time, + user_account.id, + "form21_10210_#{notification_type}_email_template_id", + { + 'confirmation_number' => 'confirmation_number', + 'date_submitted' => time.strftime('%B %d, %Y'), + 'first_name' => 'Bob', + 'lighthouse_updated_at' => nil + }, + 'fake_secret', + { + callback_metadata: { + form_number: 'vba_21_10210', + notification_type:, + statsd_tags: { + 'function' => 'vba_21_10210 form submission to Lighthouse', 'service' => 'veteran-facing-forms' + } + } + } + ) end end