2019-05-13 09:55:44 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-05-08 01:25:11 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Jobs::ReviewablePriorities do
|
|
|
|
|
2019-09-20 01:42:50 +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)
|
2019-05-08 01:25:11 +08:00
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
|
|
def create_reviewables(count)
|
2021-04-24 02:34:24 +08:00
|
|
|
(1..count).each { |i| create_with_score(i) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_with_score(score)
|
|
|
|
Fabricate(:reviewable_flagged_post).tap do |reviewable|
|
|
|
|
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
|
|
|
|
|
2019-09-20 01:42:50 +08:00
|
|
|
it "needs a minimum amount of reviewables before it calculates anything" do
|
2019-09-20 02:07:56 +08:00
|
|
|
create_reviewables(5)
|
2021-04-24 02:34:24 +08:00
|
|
|
|
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
|
|
|
|
|
|
|
|
it "will set priorities based on the maximum score" do
|
2019-09-20 02:07:56 +08:00
|
|
|
create_reviewables(Jobs::ReviewablePriorities.min_reviewables)
|
2021-04-24 02:34:24 +08:00
|
|
|
|
|
|
|
Jobs::ReviewablePriorities.new.execute({})
|
|
|
|
|
|
|
|
expect_min_score(:low, SiteSetting.reviewable_low_priority_threshold)
|
|
|
|
expect_min_score(:medium, 8.0)
|
|
|
|
expect_min_score('medium', 8.0)
|
|
|
|
expect_min_score(:high, 13.0)
|
|
|
|
expect(Reviewable.score_required_to_hide_post).to eq(8.66)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ignore negative scores when calculating priorities' do
|
|
|
|
create_reviewables(Jobs::ReviewablePriorities.min_reviewables)
|
|
|
|
negative_score = -9
|
|
|
|
10.times { create_with_score(negative_score) }
|
|
|
|
|
2019-09-20 01:42:50 +08:00
|
|
|
Jobs::ReviewablePriorities.new.execute({})
|
|
|
|
|
2021-04-24 02:34:24 +08:00
|
|
|
expect_min_score(:low, SiteSetting.reviewable_low_priority_threshold)
|
|
|
|
expect_min_score(:medium, 8.0)
|
|
|
|
expect_min_score(:high, 13.0)
|
2019-09-20 01:42:50 +08:00
|
|
|
expect(Reviewable.score_required_to_hide_post).to eq(8.66)
|
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
|