Skip to content

Commit 16fdba5

Browse files
Add template_id, source_location, callback_metadata, and delivery status to callback logging (#20035)
1 parent 42d1400 commit 16fdba5

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

modules/va_notify/app/controllers/va_notify/callbacks_controller.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@ def create
1717
notification_id = params[:id]
1818

1919
if (notification = VANotify::Notification.find_by(notification_id: notification_id))
20-
Rails.logger.info("va_notify callbacks - Updating notification #{notification.id}")
2120
notification.update(notification_params)
21+
Rails.logger.info("va_notify callbacks - Updating notification: #{notification.id}",
22+
{
23+
source_location: notification.source_location,
24+
template_id: notification.template_id,
25+
callback_metadata: notification.callback_metadata,
26+
status: notification.status
27+
})
28+
2229
VANotify::DefaultCallback.new(notification).call
2330
VANotify::StatusUpdate.new.delegate(notification_params.merge(id: notification_id))
2431
else

modules/va_notify/spec/requests/callbacks_spec.rb

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'rails_helper'
4+
require 'va_notify/default_callback'
45

56
RSpec.describe 'VANotify Callbacks', type: :request do
67
let(:valid_token) { Settings.vanotify.status_callback.bearer_token }
@@ -18,13 +19,26 @@
1819

1920
describe 'POST #notifications' do
2021
it 'with found notification' do
21-
notification = VANotify::Notification.create(notification_id: notification_id)
22+
template_id = SecureRandom.uuid
23+
notification = VANotify::Notification.create(notification_id: notification_id,
24+
source_location: 'some_location',
25+
callback_metadata: 'some_callback_metadata',
26+
template_id: template_id)
2227
expect(notification.status).to eq(nil)
28+
allow(Rails.logger).to receive(:info)
29+
callback_obj = double('VANotify::DefaultCallback')
30+
allow(VANotify::DefaultCallback).to receive(:new).and_return(callback_obj)
31+
allow(callback_obj).to receive(:call)
2332

2433
post(callback_route,
2534
params: callback_params.to_json,
2635
headers: { 'Authorization' => "Bearer #{valid_token}", 'Content-Type' => 'application/json' })
2736

37+
expect(Rails.logger).to have_received(:info).with(
38+
"va_notify callbacks - Updating notification: #{notification.id}",
39+
{ source_location: 'some_location', template_id: template_id, callback_metadata: 'some_callback_metadata',
40+
status: 'delivered' }
41+
)
2842
expect(response.body).to include('success')
2943
notification.reload
3044
expect(notification.status).to eq('delivered')

0 commit comments

Comments
 (0)