2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-04-01 14:46:56 -04:00
|
|
|
describe Jobs::PendingReviewablesReminder do
|
2019-01-03 12:03:01 -05: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-03 14:34:21 -04:00
|
|
|
context "notify_about_flags_after is 0" do
|
2017-07-07 02:09:14 -04:00
|
|
|
before { SiteSetting.notify_about_flags_after = 0 }
|
2014-04-03 14:34:21 -04:00
|
|
|
|
2017-04-19 16:16:27 -04:00
|
|
|
it "never notifies" do
|
2019-01-03 12:03:01 -05:00
|
|
|
create_flag(50.hours.ago)
|
|
|
|
expect(execute.sent_reminder).to eq(false)
|
2014-04-03 14:34:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-04 12:19:43 -04: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-03 14:34:21 -04:00
|
|
|
context "notify_about_flags_after is 48" do
|
2017-04-19 16:16:27 -04:00
|
|
|
before do
|
|
|
|
SiteSetting.notify_about_flags_after = 48
|
2019-01-03 12:03:01 -05:00
|
|
|
described_class.clear_key
|
2017-04-19 16:16:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2019-01-03 12:03:01 -05:00
|
|
|
described_class.clear_key
|
2017-04-19 16:16:27 -04:00
|
|
|
end
|
2014-04-03 14:34:21 -04:00
|
|
|
|
2016-02-19 15:21:05 -05:00
|
|
|
it "doesn't send message when flags are less than 48 hours old" do
|
2019-01-03 12:03:01 -05:00
|
|
|
create_flag(47.hours.ago)
|
|
|
|
expect(execute.sent_reminder).to eq(false)
|
2014-04-03 14:34:21 -04:00
|
|
|
end
|
|
|
|
|
2017-04-19 16:16:27 -04:00
|
|
|
it "doesn't send a message if there are no new flags older than 48 hours old" do
|
2019-01-03 12:03:01 -05: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-19 16:16:27 -04:00
|
|
|
end
|
2019-01-22 11:01:18 -05:00
|
|
|
|
2019-01-25 11:25:30 -05:00
|
|
|
it "sends message when there is a flag older than 48 hours" do
|
2019-01-03 12:03:01 -05:00
|
|
|
create_flag(49.hours.ago)
|
|
|
|
expect(execute.sent_reminder).to eq(true)
|
2019-01-24 13:39:21 -05:00
|
|
|
end
|
|
|
|
|
2019-05-07 13:25:11 -04:00
|
|
|
context "reviewable_default_visibility" do
|
2019-01-03 12:03:01 -05:00
|
|
|
before do
|
|
|
|
create_flag(49.hours.ago)
|
|
|
|
create_flag(51.hours.ago)
|
2019-01-25 11:25:30 -05:00
|
|
|
end
|
|
|
|
|
2019-05-07 13:25:11 -04: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-03 12:03:01 -05:00
|
|
|
expect(execute.sent_reminder).to eq(false)
|
2019-01-25 11:25:30 -05:00
|
|
|
end
|
|
|
|
|
2019-05-07 13:25:11 -04: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-03 12:03:01 -05:00
|
|
|
expect(execute.sent_reminder).to eq(true)
|
2019-01-25 11:25:30 -05:00
|
|
|
end
|
2019-01-22 11:01:18 -05:00
|
|
|
end
|
2021-12-10 08:17:39 -05:00
|
|
|
|
|
|
|
it 'deletes previous messages' do
|
|
|
|
GroupMessage.create(
|
|
|
|
Group[:moderators].name, 'reviewables_reminder',
|
2021-12-20 15:35:51 -05:00
|
|
|
{ limit_once_per: false, message_params: { mentions: '', count: 1 } }
|
2021-12-10 08:17:39 -05: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-03 14:34:21 -04:00
|
|
|
end
|
|
|
|
end
|