2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe SpamLog do
|
2020-03-13 15:44:24 +05:30
|
|
|
let_it_be(:admin) { create(:admin) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to belong_to(:user) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to validate_presence_of(:user) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#remove_user' do
|
|
|
|
it 'blocks the user' do
|
|
|
|
spam_log = build(:spam_log)
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect { spam_log.remove_user(deleted_by: admin) }.to change { spam_log.user.blocked? }.to(true)
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
context 'when admin mode is enabled', :enable_admin_mode do
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when user_destroy_with_limited_execution_time_worker is enabled' do
|
|
|
|
it 'initiates user removal', :sidekiq_inline do
|
|
|
|
spam_log = build(:spam_log)
|
|
|
|
user = spam_log.user
|
|
|
|
|
|
|
|
perform_enqueued_jobs do
|
|
|
|
spam_log.remove_user(deleted_by: admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(
|
|
|
|
Users::GhostUserMigration.where(user: user,
|
|
|
|
initiator_user: admin)
|
|
|
|
).to be_exists
|
|
|
|
end
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
context 'when user_destroy_with_limited_execution_time_worker is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(user_destroy_with_limited_execution_time_worker: false)
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
it 'removes the user', :sidekiq_inline do
|
|
|
|
spam_log = build(:spam_log)
|
|
|
|
user = spam_log.user
|
|
|
|
|
|
|
|
perform_enqueued_jobs do
|
|
|
|
spam_log.remove_user(deleted_by: admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
context 'when admin mode is disabled' do
|
|
|
|
it 'does not allow to remove the user', :sidekiq_might_not_need_inline do
|
|
|
|
spam_log = build(:spam_log)
|
|
|
|
user = spam_log.user
|
|
|
|
|
|
|
|
perform_enqueued_jobs do
|
|
|
|
spam_log.remove_user(deleted_by: admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(User.exists?(user.id)).to be(true)
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
describe '.verify_recaptcha!' do
|
|
|
|
let_it_be(:spam_log) { create(:spam_log, user: admin, recaptcha_verified: false) }
|
|
|
|
|
|
|
|
context 'the record cannot be found' do
|
|
|
|
it 'updates nothing' do
|
|
|
|
expect(instance_of(described_class)).not_to receive(:update!)
|
|
|
|
|
|
|
|
described_class.verify_recaptcha!(id: spam_log.id, user_id: admin.id)
|
|
|
|
|
|
|
|
expect(spam_log.recaptcha_verified).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not error despite not finding a record' do
|
|
|
|
expect { described_class.verify_recaptcha!(id: -1, user_id: admin.id) }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'the record exists' do
|
|
|
|
it 'updates recaptcha_verified' do
|
|
|
|
expect { described_class.verify_recaptcha!(id: spam_log.id, user_id: admin.id) }
|
|
|
|
.to change { spam_log.reload.recaptcha_verified }.from(false).to(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|