From ddecaaaf62336d9d94ef456a3368a7f76f3e186b Mon Sep 17 00:00:00 2001 From: Eric Tillberg Date: Wed, 27 Nov 2024 09:51:38 -0500 Subject: [PATCH 1/3] Use the callback_metadata key when we send an email to a user_account --- .../simple_forms_api/notification_email.rb | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) 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 10b0784eaf4..d62a29b0e5e 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 @@ -134,12 +134,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) From f37ed47f9f09397763691adb2684308fc1651385 Mon Sep 17 00:00:00 2001 From: Eric Tillberg Date: Wed, 27 Nov 2024 10:55:00 -0500 Subject: [PATCH 2/3] tests --- .../simple_forms_api/spec/services/notification_email_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4c804366f1f..db39339c802 100644 --- a/modules/simple_forms_api/spec/services/notification_email_spec.rb +++ b/modules/simple_forms_api/spec/services/notification_email_spec.rb @@ -127,7 +127,7 @@ subject.send(at: time) expect(VANotify::UserAccountJob).to have_received(:perform_at).with(time, user_account.id, anything, - anything) + anything, anything, anything) end end From 80cfd9de3656568f71ca3bb74b0053cbadde2a8b Mon Sep 17 00:00:00 2001 From: Eric Tillberg Date: Tue, 3 Dec 2024 15:15:55 -0500 Subject: [PATCH 3/3] replace 'anything' in spec --- .../spec/services/notification_email_spec.rb | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) 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 8c7ec6c455c..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, 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