mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 04:43:37 +08:00
6e161d3e75
The most common thing that we do with fab! is: fab!(:thing) { Fabricate(:thing) } This commit adds a shorthand for this which is just simply: fab!(:thing) i.e. If you omit the block, then, by default, you'll get a `Fabricate`d object using the fabricator of the same name.
33 lines
890 B
Ruby
33 lines
890 B
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe Jobs::SendPushNotification do
|
|
fab!(:user)
|
|
fab!(:subscription) { Fabricate(:push_subscription) }
|
|
let(:payload) { { notification_type: 1, excerpt: "Hello you" } }
|
|
|
|
before do
|
|
freeze_time
|
|
SiteSetting.push_notification_time_window_mins = 10
|
|
end
|
|
|
|
context "with active online user" do
|
|
it "does not send push notification" do
|
|
user.update!(last_seen_at: 5.minutes.ago)
|
|
|
|
PushNotificationPusher.expects(:push).with(user, payload).never
|
|
|
|
Jobs::SendPushNotification.new.execute(user_id: user, payload: payload)
|
|
end
|
|
end
|
|
|
|
context "with inactive offline user" do
|
|
it "sends push notification" do
|
|
user.update!(last_seen_at: 40.minutes.ago)
|
|
|
|
PushNotificationPusher.expects(:push).with(user, payload)
|
|
|
|
Jobs::SendPushNotification.new.execute(user_id: user, payload: payload)
|
|
end
|
|
end
|
|
end
|