A platform for community discussion. Free, open, simple.
DEV: Trigger DiscourseEvent on push notification send (#25375)
Mark VanLandingham7bad0b1d8aad
diff --git a/app/services/push_notification_pusher.rb b/app/services/push_notification_pusher.rbindex aafc6d4786b..d3f396cc358 100644--- a/app/services/push_notification_pusher.rb+++ b/app/services/push_notification_pusher.rb@@ -161,6 +161,8 @@ class PushNotificationPusherif subscription.first_error_at || subscription.error_count != 0subscription.update_columns(error_count: 0, first_error_at: nil)end++ DiscourseEvent.trigger(:push_notification_sent, user, message)rescue WebPush::ExpiredSubscriptionsubscription.destroy!rescue WebPush::ResponseError => ediff --git a/spec/services/push_notification_pusher_spec.rb b/spec/services/push_notification_pusher_spec.rbindex ac8ee637439..97263e58702 100644--- a/spec/services/push_notification_pusher_spec.rb+++ b/spec/services/push_notification_pusher_spec.rb@@ -15,6 +15,7 @@ RSpec.describe PushNotificationPusher docontext "with user" dofab!(:user)let(:topic_title) { "Topic" }+ let(:post_url) { "https://example.com/t/1/2" }let(:username) { "system" }def create_subscription@@ -38,7 +39,7 @@ RSpec.describe PushNotificationPusher dousername: username,excerpt: "description",topic_id: 1,- post_url: "https://example.com/t/1/2",+ post_url: post_url,notification_type: notification_type,post_number: post_number,},@@ -74,6 +75,16 @@ RSpec.describe PushNotificationPusher doexecute_pushend+ it "triggers a DiscourseEvent with user and message arguments" do+ WebPush.expects(:payload_send)+ create_subscription+ pn_sent_event = DiscourseEvent.track_events { message = execute_push }.first++ expect(pn_sent_event[:event_name]).to eq(:push_notification_sent)+ expect(pn_sent_event[:params].first).to eq(user)+ expect(pn_sent_event[:params].second[:url]).to eq(post_url)+ end+it "deletes subscriptions which are erroring regularly" dostart = freeze_time