2019-05-13 09:55:44 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe Jobs::ReviewablePriorities do
|
2021-04-24 02:34:24 +08:00
|
|
|
fab!(:user_0) { Fabricate(:user) }
|
|
|
|
fab!(:user_1) { Fabricate(:user) }
|
2019-09-20 02:07:56 +08:00
|
|
|
|
2021-05-11 01:09:04 +08:00
|
|
|
def create_with_score(score, status: :approved)
|
|
|
|
Fabricate(:reviewable_flagged_post, status: Reviewable.statuses[status]).tap do |reviewable|
|
2021-04-24 02:34:24 +08:00
|
|
|
reviewable.add_score(user_0, PostActionType.types[:off_topic])
|
|
|
|
reviewable.add_score(user_1, PostActionType.types[:off_topic])
|
|
|
|
reviewable.update!(score: score)
|
2019-09-20 02:07:56 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-08-30 12:47:29 +08:00
|
|
|
it "needs returns 0s with no existing reviewables" do
|
2019-05-08 01:25:11 +08:00
|
|
|
Jobs::ReviewablePriorities.new.execute({})
|
2021-04-24 02:34:24 +08:00
|
|
|
|
|
|
|
expect_min_score(:low, 0.0)
|
|
|
|
expect_min_score(:medium, 0.0)
|
|
|
|
expect_min_score(:high, 0.0)
|
2019-09-20 01:42:50 +08:00
|
|
|
expect(Reviewable.score_required_to_hide_post).to eq(8.33)
|
|
|
|
end
|
|
|
|
|
2024-08-30 12:47:29 +08:00
|
|
|
context "with reviewables" do
|
|
|
|
# Generate all reviewables first because they take a lot of time
|
|
|
|
fab!(:reviewables) do
|
|
|
|
(1..Jobs::ReviewablePriorities.min_reviewables).map do |i|
|
|
|
|
create_with_score(SiteSetting.reviewable_low_priority_threshold + i)
|
|
|
|
end
|
|
|
|
end
|
2021-04-24 02:34:24 +08:00
|
|
|
|
2024-08-30 12:47:29 +08:00
|
|
|
# This reviewable will be ignored in most tests
|
|
|
|
fab!(:other_reviewable) { create_with_score(0) }
|
|
|
|
|
|
|
|
it "needs a minimum amount of reviewables before it calculates anything" do
|
|
|
|
reviewables[0].destroy!
|
|
|
|
other_reviewable.destroy!
|
2021-04-24 02:34:24 +08:00
|
|
|
|
2021-05-27 00:16:16 +08:00
|
|
|
Jobs::ReviewablePriorities.new.execute({})
|
2021-04-24 02:34:24 +08:00
|
|
|
|
2024-08-30 12:47:29 +08:00
|
|
|
expect_min_score(:low, 0.0)
|
|
|
|
expect_min_score(:medium, 0.0)
|
|
|
|
expect_min_score(:high, 0.0)
|
|
|
|
expect(Reviewable.score_required_to_hide_post).to eq(8.33)
|
2021-05-27 00:16:16 +08:00
|
|
|
end
|
2021-04-24 02:34:24 +08:00
|
|
|
|
2024-08-30 12:47:29 +08:00
|
|
|
context "when there are enough reviewables" do
|
|
|
|
let(:medium_threshold) { 8.0 }
|
|
|
|
let(:high_threshold) { 13.0 }
|
|
|
|
let(:score_to_hide_post) { 8.66 }
|
2019-09-20 01:42:50 +08:00
|
|
|
|
2024-08-30 12:47:29 +08:00
|
|
|
it "will set priorities based on the maximum score" do
|
|
|
|
other_reviewable.destroy!
|
|
|
|
Jobs::ReviewablePriorities.new.execute({})
|
2021-05-11 01:09:04 +08:00
|
|
|
|
2024-08-30 12:47:29 +08:00
|
|
|
expect_min_score(:low, SiteSetting.reviewable_low_priority_threshold)
|
|
|
|
expect_min_score(:medium, medium_threshold)
|
|
|
|
expect_min_score(:high, high_threshold)
|
|
|
|
expect(Reviewable.score_required_to_hide_post).to eq(score_to_hide_post)
|
|
|
|
end
|
2021-05-11 01:09:04 +08:00
|
|
|
|
2024-08-30 12:47:29 +08:00
|
|
|
it "ignore negative scores when calculating priorities" do
|
|
|
|
negative_score = -9
|
|
|
|
other_reviewable.update!(score: negative_score)
|
2021-05-11 01:09:04 +08:00
|
|
|
|
2024-08-30 12:47:29 +08:00
|
|
|
Jobs::ReviewablePriorities.new.execute({})
|
|
|
|
|
|
|
|
expect_min_score(:low, SiteSetting.reviewable_low_priority_threshold)
|
|
|
|
expect_min_score(:medium, medium_threshold)
|
|
|
|
expect_min_score(:high, high_threshold)
|
|
|
|
expect(Reviewable.score_required_to_hide_post).to eq(score_to_hide_post)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "ignores non-approved reviewables" do
|
|
|
|
low_score = 2
|
|
|
|
other_reviewable.update!(score: low_score, status: Reviewable.statuses[:pending])
|
|
|
|
|
|
|
|
Jobs::ReviewablePriorities.new.execute({})
|
2021-05-27 00:16:16 +08:00
|
|
|
|
2024-08-30 12:47:29 +08:00
|
|
|
expect_min_score(:low, SiteSetting.reviewable_low_priority_threshold)
|
|
|
|
expect_min_score(:medium, medium_threshold)
|
|
|
|
expect_min_score(:high, high_threshold)
|
|
|
|
expect(Reviewable.score_required_to_hide_post).to eq(score_to_hide_post)
|
|
|
|
end
|
2021-05-27 00:16:16 +08:00
|
|
|
end
|
2019-05-08 01:25:11 +08:00
|
|
|
end
|
2019-09-20 01:42:50 +08:00
|
|
|
|
2021-04-24 02:34:24 +08:00
|
|
|
def expect_min_score(priority, score)
|
|
|
|
expect(Reviewable.min_score_for_priority(priority)).to eq(score)
|
|
|
|
end
|
2019-05-08 01:25:11 +08:00
|
|
|
end
|