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({})
|
2019-05-23 05:23:45 +08:00
|
|
|
expect(Reviewable.min_score_for_priority(:low)).to eq(0.0)
|
2019-09-20 01:42:50 +08:00
|
|
|
expect(Reviewable.min_score_for_priority(:medium)).to eq(0.0)
|
|
|
|
expect(Reviewable.min_score_for_priority(:high)).to eq(0.0)
|
|
|
|
expect(Reviewable.score_required_to_hide_post).to eq(8.33)
|
2019-05-08 01:25:11 +08:00
|
|
|
end
|
|
|
|
|
2019-09-20 02:07:56 +08:00
|
|
|
fab!(:u0) { Fabricate(:user) }
|
|
|
|
fab!(:u1) { Fabricate(:user) }
|
|
|
|
|
|
|
|
def create_reviewables(count)
|
|
|
|
(1..count).each do |i|
|
|
|
|
r = Fabricate(:reviewable_flagged_post)
|
|
|
|
r.add_score(u0, PostActionType.types[:off_topic])
|
|
|
|
r.add_score(u1, PostActionType.types[:off_topic])
|
|
|
|
r.update!(score: i)
|
|
|
|
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)
|
2019-05-08 01:25:11 +08:00
|
|
|
Jobs::ReviewablePriorities.new.execute({})
|
2019-05-23 05:23:45 +08:00
|
|
|
expect(Reviewable.min_score_for_priority(:low)).to eq(0.0)
|
|
|
|
expect(Reviewable.min_score_for_priority(:medium)).to eq(0.0)
|
|
|
|
expect(Reviewable.min_score_for_priority(:high)).to eq(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)
|
2019-09-20 01:42:50 +08:00
|
|
|
Jobs::ReviewablePriorities.new.execute({})
|
|
|
|
|
|
|
|
expect(Reviewable.min_score_for_priority(:low)).to eq(0.0)
|
|
|
|
expect(Reviewable.min_score_for_priority(:medium)).to eq(8.0)
|
|
|
|
expect(Reviewable.min_score_for_priority('medium')).to eq(8.0)
|
|
|
|
expect(Reviewable.min_score_for_priority(:high)).to eq(13.0)
|
|
|
|
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
|
|
|
|
2019-05-08 01:25:11 +08:00
|
|
|
end
|