mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Plugin instance method for push_notification_filters (#14787)
This commit is contained in:
committed by
GitHub
parent
836c0f5ffe
commit
67265a5045
@@ -721,12 +721,8 @@ describe PostAlerter do
|
||||
describe "push_notification" do
|
||||
let(:mention_post) { create_post_with_alerts(user: user, raw: 'Hello @eviltrout :heart:') }
|
||||
let(:topic) { mention_post.topic }
|
||||
|
||||
it "pushes nothing to suspended users" do
|
||||
before do
|
||||
SiteSetting.allowed_user_api_push_urls = "https://site.com/push|https://site2.com/push"
|
||||
|
||||
evil_trout.update_columns(suspended_till: 1.year.from_now)
|
||||
|
||||
2.times do |i|
|
||||
UserApiKey.create!(user_id: evil_trout.id,
|
||||
client_id: "xxx#{i}",
|
||||
@@ -734,20 +730,33 @@ describe PostAlerter do
|
||||
scopes: ['notifications'].map { |name| UserApiKeyScope.new(name: name) },
|
||||
push_url: "https://site2.com/push")
|
||||
end
|
||||
end
|
||||
|
||||
describe "DiscoursePluginRegistry#push_notification_filters" do
|
||||
it "sends push notifications when all filters pass" do
|
||||
Plugin::Instance.new.register_push_notification_filter do |user, payload|
|
||||
true
|
||||
end
|
||||
|
||||
expect { mention_post }.to change { Jobs::PushNotification.jobs.count }.by(1)
|
||||
DiscoursePluginRegistry.reset!
|
||||
end
|
||||
|
||||
it "does not send push notifications when a filters returns false" do
|
||||
Plugin::Instance.new.register_push_notification_filter do |user, payload|
|
||||
false
|
||||
end
|
||||
expect { mention_post }.not_to change { Jobs::PushNotification.jobs.count }
|
||||
DiscoursePluginRegistry.reset!
|
||||
end
|
||||
end
|
||||
|
||||
it "pushes nothing to suspended users" do
|
||||
evil_trout.update_columns(suspended_till: 1.year.from_now)
|
||||
expect { mention_post }.to_not change { Jobs::PushNotification.jobs.count }
|
||||
end
|
||||
|
||||
it "pushes nothing when the user is in 'do not disturb'" do
|
||||
SiteSetting.allowed_user_api_push_urls = "https://site.com/push|https://site2.com/push"
|
||||
2.times do |i|
|
||||
UserApiKey.create!(user_id: evil_trout.id,
|
||||
client_id: "xxx#{i}",
|
||||
application_name: "iPhone#{i}",
|
||||
scopes: ['notifications'].map { |name| UserApiKeyScope.new(name: name) },
|
||||
push_url: "https://site2.com/push")
|
||||
end
|
||||
|
||||
Fabricate(:do_not_disturb_timing, user: evil_trout, starts_at: Time.zone.now, ends_at: 1.day.from_now)
|
||||
|
||||
expect { mention_post }.to_not change { Jobs::PushNotification.jobs.count }
|
||||
@@ -755,16 +764,6 @@ describe PostAlerter do
|
||||
|
||||
it "correctly pushes notifications if configured correctly" do
|
||||
Jobs.run_immediately!
|
||||
SiteSetting.allowed_user_api_push_urls = "https://site.com/push|https://site2.com/push"
|
||||
|
||||
2.times do |i|
|
||||
UserApiKey.create!(user_id: evil_trout.id,
|
||||
client_id: "xxx#{i}",
|
||||
application_name: "iPhone#{i}",
|
||||
scopes: ['notifications'].map { |name| UserApiKeyScope.new(name: name) },
|
||||
push_url: "https://site2.com/push")
|
||||
end
|
||||
|
||||
body = nil
|
||||
headers = nil
|
||||
|
||||
|
||||
Reference in New Issue
Block a user