debian-mirror-gitlab/spec/workers/delete_user_worker_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

75 lines
2 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2016-06-02 11:05:42 +05:30
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe DeleteUserWorker, feature_category: :user_management do
2016-06-02 11:05:42 +05:30
let!(:user) { create(:user) }
let!(:current_user) { create(:user) }
it "calls the DeleteUserWorker with the params it was given" do
2018-11-08 19:23:39 +05:30
expect_next_instance_of(Users::DestroyService) do |service|
expect(service).to receive(:execute).with(user, {})
end
2016-06-02 11:05:42 +05:30
2017-08-17 22:00:37 +05:30
described_class.new.perform(current_user.id, user.id)
2016-06-02 11:05:42 +05:30
end
it "uses symbolized keys" do
2018-11-08 19:23:39 +05:30
expect_next_instance_of(Users::DestroyService) do |service|
2022-07-16 23:28:13 +05:30
expect(service).to receive(:execute).with(user, { test: "test" })
2018-11-08 19:23:39 +05:30
end
2016-06-02 11:05:42 +05:30
2022-07-16 23:28:13 +05:30
described_class.new.perform(current_user.id, user.id, { "test" => "test" })
2016-06-02 11:05:42 +05:30
end
2023-07-09 08:55:56 +05:30
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
2016-06-02 11:05:42 +05:30
end