mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 04:59:22 -06:00
0954ae70a6
This change ensures native push notifications respect the site setting for push_notification_time_window_mins. Previously only web push notifications would account for the delay, now we can bring more consistency between Discourse in browser vs Hub, by applying the same delay strategy to both forms of push notifications.
50 lines
1.1 KiB
Ruby
50 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "excon"
|
|
|
|
RSpec.describe Jobs::PushNotification do
|
|
fab!(:user)
|
|
fab!(:post)
|
|
let(:data) do
|
|
{
|
|
"user_id" => user.id,
|
|
"payload" => {
|
|
"notification_type" => 1,
|
|
"post_url" => "/t/#{post.topic_id}/#{post.post_number}",
|
|
"excerpt" => "Hello you",
|
|
},
|
|
"clients" => [[user.id, "http://test.localhost"]],
|
|
}
|
|
end
|
|
|
|
before { SiteSetting.push_notification_time_window_mins = 5 }
|
|
|
|
context "with valid user" do
|
|
it "does not send push notification when user is online" do
|
|
user.update!(last_seen_at: 1.minute.ago)
|
|
|
|
Excon.expects(:post).never
|
|
|
|
Jobs::PushNotification.new.execute(data)
|
|
end
|
|
|
|
it "sends push notification when user is offline" do
|
|
user.update!(last_seen_at: 10.minutes.ago)
|
|
|
|
Excon.expects(:post).once
|
|
|
|
Jobs::PushNotification.new.execute(data)
|
|
end
|
|
end
|
|
|
|
context "with invalid user" do
|
|
it "does not send push notification" do
|
|
data["user_id"] = -999
|
|
|
|
Excon.expects(:post).never
|
|
|
|
Jobs::PushNotification.new.execute(data)
|
|
end
|
|
end
|
|
end
|