mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -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
|
if subscription.first_error_at || subscription.error_count != 0
|
||||||
subscription.update_columns(error_count: 0, first_error_at: nil)
|
subscription.update_columns(error_count: 0, first_error_at: nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
DiscourseEvent.trigger(:push_notification_sent, user, message)
|
||||||
rescue WebPush::ExpiredSubscription
|
rescue WebPush::ExpiredSubscription
|
||||||
subscription.destroy!
|
subscription.destroy!
|
||||||
rescue WebPush::ResponseError => e
|
rescue WebPush::ResponseError => e
|
||||||
|
@ -15,6 +15,7 @@ RSpec.describe PushNotificationPusher do
|
|||||||
context "with user" do
|
context "with user" do
|
||||||
fab!(:user)
|
fab!(:user)
|
||||||
let(:topic_title) { "Topic" }
|
let(:topic_title) { "Topic" }
|
||||||
|
let(:post_url) { "https://example.com/t/1/2" }
|
||||||
let(:username) { "system" }
|
let(:username) { "system" }
|
||||||
|
|
||||||
def create_subscription
|
def create_subscription
|
||||||
@ -38,7 +39,7 @@ RSpec.describe PushNotificationPusher do
|
|||||||
username: username,
|
username: username,
|
||||||
excerpt: "description",
|
excerpt: "description",
|
||||||
topic_id: 1,
|
topic_id: 1,
|
||||||
post_url: "https://example.com/t/1/2",
|
post_url: post_url,
|
||||||
notification_type: notification_type,
|
notification_type: notification_type,
|
||||||
post_number: post_number,
|
post_number: post_number,
|
||||||
},
|
},
|
||||||
@ -74,6 +75,16 @@ RSpec.describe PushNotificationPusher do
|
|||||||
execute_push
|
execute_push
|
||||||
end
|
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
|
it "deletes subscriptions which are erroring regularly" do
|
||||||
start = freeze_time
|
start = freeze_time
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user