2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-04-02 02:46:56 +08:00
|
|
|
describe Jobs::PendingReviewablesReminder do
|
2019-01-04 01:03:01 +08:00
|
|
|
let(:job) { described_class.new }
|
|
|
|
|
|
|
|
def create_flag(created_at)
|
|
|
|
PostActionCreator.create(Fabricate(:user), Fabricate(:post), :spam, created_at: created_at).reviewable
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
job.tap { job.execute({}) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't notify when there are no flags" do
|
|
|
|
expect(execute.sent_reminder).to eq(false)
|
|
|
|
end
|
|
|
|
|
2014-04-04 02:34:21 +08:00
|
|
|
context "notify_about_flags_after is 0" do
|
2017-07-07 14:09:14 +08:00
|
|
|
before { SiteSetting.notify_about_flags_after = 0 }
|
2014-04-04 02:34:21 +08:00
|
|
|
|
2017-04-20 04:16:27 +08:00
|
|
|
it "never notifies" do
|
2019-01-04 01:03:01 +08:00
|
|
|
create_flag(50.hours.ago)
|
|
|
|
expect(execute.sent_reminder).to eq(false)
|
2014-04-04 02:34:21 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-05 00:19:43 +08:00
|
|
|
context "notify_about_flags_after accepts a float" do
|
|
|
|
before { SiteSetting.notify_about_flags_after = 0.25 }
|
|
|
|
|
|
|
|
it "doesn't send message when flags are less than 15 minutes old" do
|
|
|
|
create_flag(14.minutes.ago)
|
|
|
|
expect(execute.sent_reminder).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sends message when there is a flag older than 15 minutes" do
|
|
|
|
create_flag(16.minutes.ago)
|
|
|
|
expect(execute.sent_reminder).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-04 02:34:21 +08:00
|
|
|
context "notify_about_flags_after is 48" do
|
2017-04-20 04:16:27 +08:00
|
|
|
before do
|
|
|
|
SiteSetting.notify_about_flags_after = 48
|
2019-01-04 01:03:01 +08:00
|
|
|
described_class.clear_key
|
2017-04-20 04:16:27 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2019-01-04 01:03:01 +08:00
|
|
|
described_class.clear_key
|
2017-04-20 04:16:27 +08:00
|
|
|
end
|
2014-04-04 02:34:21 +08:00
|
|
|
|
2016-02-20 04:21:05 +08:00
|
|
|
it "doesn't send message when flags are less than 48 hours old" do
|
2019-01-04 01:03:01 +08:00
|
|
|
create_flag(47.hours.ago)
|
|
|
|
expect(execute.sent_reminder).to eq(false)
|
2014-04-04 02:34:21 +08:00
|
|
|
end
|
|
|
|
|
2017-04-20 04:16:27 +08:00
|
|
|
it "doesn't send a message if there are no new flags older than 48 hours old" do
|
2019-01-04 01:03:01 +08:00
|
|
|
old_reviewable = create_flag(50.hours.ago)
|
|
|
|
create_flag(47.hours.ago)
|
|
|
|
|
|
|
|
described_class.last_notified_id = old_reviewable.id
|
|
|
|
execute
|
|
|
|
expect(job.sent_reminder).to eq(false)
|
|
|
|
expect(described_class.last_notified_id).to eq(old_reviewable.id)
|
2017-04-20 04:16:27 +08:00
|
|
|
end
|
2019-01-23 00:01:18 +08:00
|
|
|
|
2019-01-26 00:25:30 +08:00
|
|
|
it "sends message when there is a flag older than 48 hours" do
|
2019-01-04 01:03:01 +08:00
|
|
|
create_flag(49.hours.ago)
|
|
|
|
expect(execute.sent_reminder).to eq(true)
|
2019-01-25 02:39:21 +08:00
|
|
|
end
|
|
|
|
|
2019-05-08 01:25:11 +08:00
|
|
|
context "reviewable_default_visibility" do
|
2019-01-04 01:03:01 +08:00
|
|
|
before do
|
|
|
|
create_flag(49.hours.ago)
|
|
|
|
create_flag(51.hours.ago)
|
2019-01-26 00:25:30 +08:00
|
|
|
end
|
|
|
|
|
2019-05-08 01:25:11 +08:00
|
|
|
it "doesn't send a message when `reviewable_default_visibility` is not met" do
|
|
|
|
Reviewable.set_priorities(medium: 3.0)
|
|
|
|
SiteSetting.reviewable_default_visibility = 'medium'
|
2019-01-04 01:03:01 +08:00
|
|
|
expect(execute.sent_reminder).to eq(false)
|
2019-01-26 00:25:30 +08:00
|
|
|
end
|
|
|
|
|
2019-05-08 01:25:11 +08:00
|
|
|
it "sends a message when `reviewable_default_visibility` is met" do
|
|
|
|
Reviewable.set_priorities(medium: 2.0)
|
|
|
|
SiteSetting.reviewable_default_visibility = 'medium'
|
2019-01-04 01:03:01 +08:00
|
|
|
expect(execute.sent_reminder).to eq(true)
|
2019-01-26 00:25:30 +08:00
|
|
|
end
|
2019-01-23 00:01:18 +08:00
|
|
|
end
|
2021-12-10 21:17:39 +08:00
|
|
|
|
|
|
|
it 'deletes previous messages' do
|
|
|
|
GroupMessage.create(
|
|
|
|
Group[:moderators].name, 'reviewables_reminder',
|
2021-12-21 04:35:51 +08:00
|
|
|
{ limit_once_per: false, message_params: { mentions: '', count: 1 } }
|
2021-12-10 21:17:39 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
create_flag(49.hours.ago)
|
|
|
|
execute
|
|
|
|
|
|
|
|
expect(Topic.where(title: I18n.t("system_messages.reviewables_reminder.subject_template")).count).to eq(1)
|
|
|
|
end
|
2014-04-04 02:34:21 +08:00
|
|
|
end
|
|
|
|
end
|