diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-17 18:15:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-17 18:15:43 +0300 |
commit | 843b1e9386fbda332839d23246d0ee2382fb7f4c (patch) | |
tree | 7663f7e38aa4e018c7210a9abdfddcd83a8bcbce /spec/workers | |
parent | 2724004cd7b8fa9d179c926c62f2fd7be63c2d81 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/delete_user_worker_spec.rb | 77 |
1 files changed, 70 insertions, 7 deletions
diff --git a/spec/workers/delete_user_worker_spec.rb b/spec/workers/delete_user_worker_spec.rb index 8a99f69c079..13a7390f592 100644 --- a/spec/workers/delete_user_worker_spec.rb +++ b/spec/workers/delete_user_worker_spec.rb @@ -30,28 +30,91 @@ RSpec.describe DeleteUserWorker, feature_category: :user_management do end end - context 'when user is banned' do + context 'when user deleted their own account' do subject(:perform) { described_class.new.perform(current_user.id, user.id) } before do - user.ban + # user is blocked as part of User#delete_async + user.block + # custom attribute is created as part of User#delete_async + UserCustomAttribute.set_deleted_own_account_at(user) end - it_behaves_like 'does nothing' + shared_examples 'proceeds with deletion' do + it "proceeds with deletion" do + expect_next_instance_of(Users::DestroyService) do |service| + expect(service).to receive(:execute).with(user, {}) + end + + perform + end + end + + it_behaves_like 'proceeds with deletion' context 'when delay_delete_own_user feature flag is disabled' do before do stub_feature_flags(delay_delete_own_user: false) end - it "proceeds with deletion" do - expect_next_instance_of(Users::DestroyService) do |service| - expect(service).to receive(:execute).with(user, {}) - end + it_behaves_like 'proceeds with deletion' + end + + shared_examples 'logs' do |reason| + it 'logs' do + expect(Gitlab::AppLogger).to receive(:info).with({ + message: 'Skipped own account deletion.', + reason: reason, + user_id: user.id, + username: user.username + }) perform end end + + shared_examples 'updates the user\'s custom attributes' do + it 'destroys the user\'s DELETED_OWN_ACCOUNT_AT custom attribute' do + key = UserCustomAttribute::DELETED_OWN_ACCOUNT_AT + expect { perform }.to change { user.custom_attributes.by_key(key).count }.from(1).to(0) + end + + context 'when custom attribute is not present' do + before do + UserCustomAttribute.delete_all + end + + it 'does nothing' do + expect { perform }.not_to raise_error + end + end + + it 'creates a SKIPPED_ACCOUNT_DELETION_AT custom attribute for the user' do + key = UserCustomAttribute::SKIPPED_ACCOUNT_DELETION_AT + expect { perform }.to change { user.custom_attributes.by_key(key).count }.from(0).to(1) + end + end + + context 'when user is banned' do + before do + user.activate + user.ban + end + + it_behaves_like 'does nothing' + it_behaves_like 'logs', 'User has been banned.' + it_behaves_like 'updates the user\'s custom attributes' + end + + context 'when user is not blocked (e.g. result of user reinstatement request)' do + before do + user.activate + end + + it_behaves_like 'does nothing' + it_behaves_like 'logs', 'User has been unblocked.' + it_behaves_like 'updates the user\'s custom attributes' + end end context 'when user to delete does not exist' do |