Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates va_notify files and spec_files to be forward-compatible w/ new fields #19503

Merged
merged 6 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading