DEV: Trigger DiscourseEvent on push notification send (#25375)

This commit is contained in:
Mark VanLandingham 2024-01-22 15:30:35 -06:00 committed by GitHub
parent 4074763efb
commit 7bad0b1d8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -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

View File

@ -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