forked from discourse/discourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
topic_reminder_spec.rb
61 lines (46 loc) · 1.59 KB
/
topic_reminder_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'rails_helper'
describe Jobs::TopicReminder do
let(:admin) { Fabricate(:admin) }
let(:topic) do
Fabricate(:topic_timer,
user: admin,
status_type: TopicTimer.types[:reminder]
).topic
end
before do
SiteSetting.queue_jobs = true
end
it "should be able to create a reminder" do
topic_timer = topic.topic_timers.first
freeze_time 1.day.from_now
expect {
described_class.new.execute(topic_timer_id: topic_timer.id)
}.to change { Notification.count }.by(1)
expect(admin.notifications.where(notification_type: Notification.types[:topic_reminder]).first&.topic_id).to eq(topic.id)
expect(TopicTimer.where(id: topic_timer.id).first).to be_nil
end
it "does nothing if it was trashed before the scheduled time" do
topic_timer = topic.topic_timers.first
topic_timer.trash!(Discourse.system_user)
freeze_time(1.day.from_now)
expect {
described_class.new.execute(topic_timer_id: topic_timer.id)
}.to_not change { Notification.count }
end
it "does nothing if job runs too early" do
topic_timer = topic.topic_timers.first
topic_timer.update_attribute(:execute_at, 8.hours.from_now)
freeze_time(6.hours.from_now)
expect {
described_class.new.execute(topic_timer_id: topic_timer.id)
}.to_not change { Notification.count }
end
it "does nothing if topic was deleted" do
topic_timer = topic.topic_timers.first
topic.trash!
freeze_time(1.day.from_now)
expect {
described_class.new.execute(topic_timer_id: topic_timer.id)
}.to_not change { Notification.count }
end
end