diff --git a/app/services/push_notification_pusher.rb b/app/services/push_notification_pusher.rb index aafc6d4786b..d3f396cc358 100644 --- a/app/services/push_notification_pusher.rb +++ b/app/services/push_notification_pusher.rb @@ -161,6 +161,8 @@ class PushNotificationPusher if subscription.first_error_at || subscription.error_count != 0 subscription.update_columns(error_count: 0, first_error_at: nil) end + + DiscourseEvent.trigger(:push_notification_sent, user, message) rescue WebPush::ExpiredSubscription subscription.destroy! rescue WebPush::ResponseError => e diff --git a/spec/services/push_notification_pusher_spec.rb b/spec/services/push_notification_pusher_spec.rb index 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 do context "with user" do fab!(: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 do username: 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 do execute_push end + 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" do start = freeze_time