2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-11 04:41:23 -05:00
|
|
|
require 'rails_helper'
|
2014-04-03 13:34:21 -05:00
|
|
|
|
2019-04-01 13:46:56 -05:00
|
|
|
describe Jobs::PendingReviewablesReminder do
|
2019-01-03 11:03:01 -06: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 13:34:21 -05:00
|
|
|
context "notify_about_flags_after is 0" do
|
2017-07-07 01:09:14 -05:00
|
|
|
before { SiteSetting.notify_about_flags_after = 0 }
|
2014-04-03 13:34:21 -05:00
|
|
|
|
2017-04-19 15:16:27 -05:00
|
|
|
it "never notifies" do
|
2019-01-03 11:03:01 -06:00
|
|
|
create_flag(50.hours.ago)
|
|
|
|
expect(execute.sent_reminder).to eq(false)
|
2014-04-03 13:34:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "notify_about_flags_after is 48" do
|
2017-04-19 15:16:27 -05:00
|
|
|
before do
|
|
|
|
SiteSetting.notify_about_flags_after = 48
|
2019-01-03 11:03:01 -06:00
|
|
|
described_class.clear_key
|
2017-04-19 15:16:27 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2019-01-03 11:03:01 -06:00
|
|
|
described_class.clear_key
|
2017-04-19 15:16:27 -05:00
|
|
|
end
|
2014-04-03 13:34:21 -05:00
|
|
|
|
2016-02-19 14:21:05 -06:00
|
|
|
it "doesn't send message when flags are less than 48 hours old" do
|
2019-01-03 11:03:01 -06:00
|
|
|
create_flag(47.hours.ago)
|
|
|
|
expect(execute.sent_reminder).to eq(false)
|
2014-04-03 13:34:21 -05:00
|
|
|
end
|
|
|
|
|
2017-04-19 15:16:27 -05:00
|
|
|
it "doesn't send a message if there are no new flags older than 48 hours old" do
|
2019-01-03 11:03:01 -06: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 15:16:27 -05:00
|
|
|
end
|
2019-01-22 10:01:18 -06:00
|
|
|
|
2019-01-25 10:25:30 -06:00
|
|
|
it "sends message when there is a flag older than 48 hours" do
|
2019-01-03 11:03:01 -06:00
|
|
|
create_flag(49.hours.ago)
|
|
|
|
expect(execute.sent_reminder).to eq(true)
|
2019-01-24 12:39:21 -06:00
|
|
|
end
|
|
|
|
|
2019-05-07 12:25:11 -05:00
|
|
|
context "reviewable_default_visibility" do
|
2019-01-03 11:03:01 -06:00
|
|
|
before do
|
|
|
|
create_flag(49.hours.ago)
|
|
|
|
create_flag(51.hours.ago)
|
2019-01-25 10:25:30 -06:00
|
|
|
end
|
|
|
|
|
2019-05-07 12:25:11 -05: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 11:03:01 -06:00
|
|
|
expect(execute.sent_reminder).to eq(false)
|
2019-01-25 10:25:30 -06:00
|
|
|
end
|
|
|
|
|
2019-05-07 12:25:11 -05: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 11:03:01 -06:00
|
|
|
expect(execute.sent_reminder).to eq(true)
|
2019-01-25 10:25:30 -06:00
|
|
|
end
|
2019-01-22 10:01:18 -06:00
|
|
|
end
|
2014-04-03 13:34:21 -05:00
|
|
|
end
|
|
|
|
end
|