Skip to content

Commit

Permalink
Updates va_notify files and spec_files to be forward-compatible w/ ne…
Browse files Browse the repository at this point in the history
…w fields (#19503)

* Uses new field of callback_klass on va_notify_notifications

* lint
  • Loading branch information
MarchandMD authored Nov 22, 2024
1 parent c4846e5 commit 4738869
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions modules/va_notify/app/services/va_notify/status_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def delegate(notification_callback)

return if callback_info_missing?

klass = constantized_class(notification.callback)
klass = constantized_class(notification.callback_klass)
if klass.respond_to?(:call)
begin
klass.call(notification)
Expand All @@ -35,7 +35,7 @@ def constantized_class(class_name)
end

def callback_info_missing?
if notification.callback.blank?
if notification.callback_klass.blank?
Rails.logger.info(message: "VANotify - no callback provided for notification: #{notification.id}")
true
else
Expand Down
2 changes: 1 addition & 1 deletion modules/va_notify/lib/va_notify/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def create_notification(response)
notification = VANotify::Notification.new(
notification_id: response.id,
source_location: find_caller_locations,
callback: callback_options[:callback],
callback_klass: callback_options[:callback],
callback_metadata: callback_options[:callback_metadata]
)

Expand Down
10 changes: 5 additions & 5 deletions modules/va_notify/spec/lib/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@
expect(VANotify::Notification.count).to eq(1)
notification = VANotify::Notification.first
expect(notification.source_location).to include('modules/va_notify/spec/lib/service_spec.rb')
expect(notification.callback).to eq(nil)
expect(notification.metadata).to eq(nil)
expect(notification.callback_klass).to eq(nil)
expect(notification.callback_metadata).to eq(nil)
end
end

Expand All @@ -139,8 +139,8 @@
expect(VANotify::Notification.count).to eq(1)
notification = VANotify::Notification.first
expect(notification.source_location).to include('modules/va_notify/spec/lib/service_spec.rb')
expect(notification.callback).to eq(nil)
expect(notification.metadata).to eq(nil)
expect(notification.callback_klass).to eq(nil)
expect(notification.callback_metadata).to eq(nil)
end
end

Expand All @@ -154,7 +154,7 @@
expect(VANotify::Notification.count).to eq(1)
notification = VANotify::Notification.first
expect(notification.source_location).to include('modules/va_notify/spec/lib/service_spec.rb')
expect(notification.callback).to eq('TestCallback')
expect(notification.callback_klass).to eq('TestCallback')
expect(notification.callback_metadata).to eq('optional_metadata')
end
end
Expand Down
11 changes: 6 additions & 5 deletions modules/va_notify/spec/services/status_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
context 'notification with callback' do
it 'invokes callback class #call' do
notification_id = SecureRandom.uuid
create(:notification, notification_id:, callback: 'VANotify::OtherTeam::OtherForm')
create(:notification, notification_id:, callback_klass: 'VANotify::OtherTeam::OtherForm')
allow(VANotify::OtherTeam::OtherForm).to receive(:call)

provider_callback = {
Expand All @@ -24,13 +24,14 @@

it 'logs error message if #call fails' do
notification_id = SecureRandom.uuid
notification = create(:notification, notification_id:, callback: 'VANotify::OtherTeam::OtherForm')
notification = create(:notification, notification_id:, callback_klass: 'VANotify::OtherTeam::OtherForm')
provider_callback = {
id: notification_id
}

allow(notification.callback.constantize).to receive(:call).with(notification).and_raise(StandardError,
'Something went wrong')
allow(notification.callback_klass.constantize).to receive(:call)
.with(notification).and_raise(StandardError,
'Something went wrong')

expect(Rails.logger).to receive(:info).with('Something went wrong')

Expand All @@ -40,7 +41,7 @@
it 'logs a message and source location if callback klass does not implement #call' do
notification_id = SecureRandom.uuid
notification = create(:notification, notification_id:,
callback: 'VANotify::NonCompliantModule::NonCompliantClass')
callback_klass: 'VANotify::NonCompliantModule::NonCompliantClass')
provider_callback = {
id: notification_id
}
Expand Down

0 comments on commit 4738869

Please sign in to comment.