forked from discourse/discourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_problems_spec.rb
37 lines (28 loc) · 1.51 KB
/
admin_problems_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
# frozen_string_literal: true
RSpec.describe ::Jobs::AdminProblems do
fab!(:admin)
it "creates notification when problems persist for at least 2 days" do
Discourse.redis.setex(AdminDashboardData.problems_started_key, 14.days.to_i, Time.zone.now.to_s)
expect { described_class.new.execute({}) }.not_to change { Notification.count }
Discourse.redis.setex(AdminDashboardData.problems_started_key, 14.days.to_i, 3.days.ago)
expect { described_class.new.execute({}) }.to change { Notification.count }.by(1)
end
it "does not replace old notification created in last 7 days" do
Discourse.redis.setex(AdminDashboardData.problems_started_key, 14.days.to_i, 3.days.ago)
expect { described_class.new.execute({}) }.to change { Notification.count }.by(1)
old_notification = Notification.last
expect { described_class.new.execute({}) }.not_to change { Notification.count }
new_notification = Notification.last
expect(old_notification.id).to equal(new_notification.id)
end
it "replace old notification created more than 7 days ago" do
Discourse.redis.setex(AdminDashboardData.problems_started_key, 14.days.to_i, 13.days.ago)
freeze_time 10.days.ago do
expect { described_class.new.execute({}) }.to change { Notification.count }.by(1)
end
old_notification = Notification.last
expect { described_class.new.execute({}) }.not_to change { Notification.count }
new_notification = Notification.last
expect(old_notification.id).not_to equal(new_notification.id)
end
end