2019-05-12 21:55:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-05-07 13:25:11 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Jobs::ReviewablePriorities do
|
|
|
|
|
2019-09-19 13:42:50 -04:00
|
|
|
it "needs returns 0s with no existing reviewables" do
|
2019-05-07 13:25:11 -04:00
|
|
|
Jobs::ReviewablePriorities.new.execute({})
|
2019-05-22 17:23:45 -04:00
|
|
|
expect(Reviewable.min_score_for_priority(:low)).to eq(0.0)
|
2019-09-19 13:42:50 -04: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-07 13:25:11 -04:00
|
|
|
end
|
|
|
|
|
2019-09-19 14:07:56 -04: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-19 13:42:50 -04:00
|
|
|
it "needs a minimum amount of reviewables before it calculates anything" do
|
2019-09-19 14:07:56 -04:00
|
|
|
create_reviewables(5)
|
2019-05-07 13:25:11 -04:00
|
|
|
Jobs::ReviewablePriorities.new.execute({})
|
2019-05-22 17:23:45 -04: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-19 13:42:50 -04: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-19 14:07:56 -04:00
|
|
|
create_reviewables(Jobs::ReviewablePriorities.min_reviewables)
|
2019-09-19 13:42:50 -04: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-07 13:25:11 -04:00
|
|
|
end
|
2019-09-19 13:42:50 -04:00
|
|
|
|
2019-05-07 13:25:11 -04:00
|
|
|
end
|