2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-03-05 15:27:34 +08:00
discourse/spec/jobs/scheduled/notify_admins_of_problems_spec.rb
Ted Johansson 911502eb9e
DEV: Add back lost admin problem notification (#35146)
When we revamped the problem check system, we lost this job that creates admin notifications when there are lingering problems. This PR adds it back.

It is almost a line-for-line copy of the original job and its tests, except for the implementation of #persistent_problems?.
2025-10-03 16:14:28 +08:00

54 lines
1.6 KiB
Ruby

# frozen_string_literal: true
RSpec.describe ::Jobs::NotifyAdminsOfProblems do
fab!(:admin)
it "creates notification when problems persist for at least 2 days" do
ProblemCheckTracker.create!(
identifier: "bad_favicon_url",
last_success_at: 3.days.ago,
last_problem_at: 1.hour.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
ProblemCheckTracker.create!(
identifier: "bad_favicon_url",
last_success_at: 3.days.ago,
last_problem_at: 1.hour.ago,
)
old_notification =
Notification.create!(
notification_type: Notification.types[:admin_problems],
user_id: admin.id,
data: "{}",
)
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 "replaces old notification created more than 7 days ago" do
ProblemCheckTracker.create!(
identifier: "bad_favicon_url",
last_success_at: 3.days.ago,
last_problem_at: 1.hour.ago,
)
old_notification =
Notification.create!(
notification_type: Notification.types[:admin_problems],
user_id: admin.id,
data: "{}",
created_at: 2.weeks.ago,
)
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