Welcome to mirror list, hosted at ThFree Co, Russian Federation.

delete_user_worker_spec.rb « workers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8a99f69c0795e7e980705dd9dc92356beca341c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe DeleteUserWorker, feature_category: :user_management do
  let!(:user)         { create(:user) }
  let!(:current_user) { create(:user) }

  it "calls the DeleteUserWorker with the params it was given" do
    expect_next_instance_of(Users::DestroyService) do |service|
      expect(service).to receive(:execute).with(user, {})
    end

    described_class.new.perform(current_user.id, user.id)
  end

  it "uses symbolized keys" do
    expect_next_instance_of(Users::DestroyService) do |service|
      expect(service).to receive(:execute).with(user, { test: "test" })
    end

    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