mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06:00
DEV: Trigger DiscourseEvent on push notification send (#25375)
This commit is contained in:
parent
4074763efb
commit
7bad0b1d8a
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user