diff options
Diffstat (limited to 'spec/workers/delete_user_worker_spec.rb')
-rw-r--r-- | spec/workers/delete_user_worker_spec.rb | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/spec/workers/delete_user_worker_spec.rb b/spec/workers/delete_user_worker_spec.rb index 4046b670640..8a99f69c079 100644 --- a/spec/workers/delete_user_worker_spec.rb +++ b/spec/workers/delete_user_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe DeleteUserWorker do +RSpec.describe DeleteUserWorker, feature_category: :user_management do let!(:user) { create(:user) } let!(:current_user) { create(:user) } @@ -21,4 +21,54 @@ RSpec.describe DeleteUserWorker do described_class.new.perform(current_user.id, user.id, { "test" => "test" }) end + + shared_examples 'does nothing' do + it "does not instantiate a DeleteUserWorker" do + expect(Users::DestroyService).not_to receive(:new) + + perform + end + end + + context 'when user is banned' do + subject(:perform) { described_class.new.perform(current_user.id, user.id) } + + before do + user.ban + end + + it_behaves_like 'does nothing' + + 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 + + perform + end + end + end + + context 'when user to delete does not exist' do + subject(:perform) { described_class.new.perform(current_user.id, non_existing_record_id) } + + it_behaves_like 'does nothing' + end + + context 'when current user does not exist' do + subject(:perform) { described_class.new.perform(non_existing_record_id, user.id) } + + it_behaves_like 'does nothing' + end + + context 'when user to delete and current user do not exist' do + subject(:perform) { described_class.new.perform(non_existing_record_id, non_existing_record_id) } + + it_behaves_like 'does nothing' + end end |