2020-01-29 13:38:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Jobs::EnqueueSuspectUsers do
|
|
|
|
before { SiteSetting.approve_suspect_users = true }
|
|
|
|
|
|
|
|
it 'does nothing when there are no suspect users' do
|
|
|
|
subject.execute({})
|
|
|
|
|
|
|
|
expect(ReviewableUser.count).to be_zero
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with suspect users' do
|
2021-02-19 11:10:19 -05:00
|
|
|
let!(:suspect_user) { Fabricate(:active_user, created_at: 1.day.ago) }
|
2020-01-29 13:38:27 -05:00
|
|
|
|
|
|
|
it 'creates a reviewable when there is a suspect user' do
|
|
|
|
subject.execute({})
|
|
|
|
|
|
|
|
expect(ReviewableUser.count).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'only creates one reviewable per user' do
|
|
|
|
review_user = ReviewableUser.needs_review!(
|
|
|
|
target: suspect_user,
|
|
|
|
created_by: Discourse.system_user,
|
|
|
|
reviewable_by_moderator: true
|
|
|
|
)
|
|
|
|
|
|
|
|
subject.execute({})
|
|
|
|
|
|
|
|
expect(ReviewableUser.count).to eq(1)
|
|
|
|
expect(ReviewableUser.last).to eq(review_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds a score' do
|
|
|
|
subject.execute({})
|
|
|
|
score = ReviewableScore.last
|
|
|
|
|
|
|
|
expect(score.reason).to eq('suspect_user')
|
|
|
|
end
|
2020-03-11 16:05:44 -04:00
|
|
|
|
|
|
|
it 'only enqueues non-approved users' do
|
|
|
|
suspect_user.update!(approved: true)
|
|
|
|
|
|
|
|
subject.execute({})
|
|
|
|
|
|
|
|
expect(ReviewableUser.where(target: suspect_user).exists?).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does nothing if must_approve_users is set to true' do
|
|
|
|
SiteSetting.must_approve_users = true
|
|
|
|
suspect_user.update!(approved: false)
|
|
|
|
|
|
|
|
subject.execute({})
|
|
|
|
|
|
|
|
expect(ReviewableUser.where(target: suspect_user).exists?).to eq(false)
|
|
|
|
end
|
2020-03-14 07:47:53 -04:00
|
|
|
|
|
|
|
it 'ignores users created more than six months ago' do
|
|
|
|
suspect_user.update!(created_at: 1.year.ago)
|
|
|
|
|
|
|
|
subject.execute({})
|
|
|
|
|
|
|
|
expect(ReviewableUser.where(target: suspect_user).exists?).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ignores users that were imported from another site' do
|
|
|
|
suspect_user.upsert_custom_fields({ import_id: 'fake_id' })
|
|
|
|
|
|
|
|
subject.execute({})
|
|
|
|
|
|
|
|
expect(ReviewableUser.where(target: suspect_user).exists?).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'enqueues a suspect users with custom fields' do
|
|
|
|
suspect_user.upsert_custom_fields({ field_a: 'value', field_b: 'value' })
|
|
|
|
|
|
|
|
subject.execute({})
|
|
|
|
|
|
|
|
expect(ReviewableUser.where(target: suspect_user).exists?).to eq(true)
|
|
|
|
end
|
2020-12-22 12:28:07 -05:00
|
|
|
|
|
|
|
it 'ignores imported users even if they have multiple custom fields' do
|
|
|
|
suspect_user.upsert_custom_fields({ field_a: 'value', field_b: 'value', import_id: 'fake_id' })
|
|
|
|
|
|
|
|
subject.execute({})
|
|
|
|
|
|
|
|
expect(ReviewableUser.where(target: suspect_user).exists?).to eq(false)
|
|
|
|
end
|
2021-02-19 11:10:19 -05:00
|
|
|
|
|
|
|
it 'enqueues a suspect user with not enough time read' do
|
2021-02-20 06:25:32 -05:00
|
|
|
suspect_user.user_stat.update!(posts_read_count: 2, topics_entered: 2, time_read: 30.seconds.to_i)
|
2021-02-19 11:10:19 -05:00
|
|
|
|
|
|
|
subject.execute({})
|
|
|
|
|
|
|
|
expect(ReviewableUser.count).to eq(1)
|
|
|
|
end
|
|
|
|
|
2021-02-20 06:25:32 -05:00
|
|
|
it 'ignores users if their time read is higher than one minute' do
|
|
|
|
suspect_user.user_stat.update!(posts_read_count: 2, topics_entered: 2, time_read: 2.minutes.to_i)
|
2021-02-19 11:10:19 -05:00
|
|
|
|
|
|
|
subject.execute({})
|
|
|
|
|
|
|
|
expect(ReviewableUser.count).to eq(0)
|
|
|
|
end
|
2020-01-29 13:38:27 -05:00
|
|
|
end
|
|
|
|
end
|