diff options
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/ci/create_pipeline_service/cache_spec.rb | 15 | ||||
-rw-r--r-- | spec/services/import/github_service_spec.rb | 3 | ||||
-rw-r--r-- | spec/services/users/deactivate_service_spec.rb | 86 |
3 files changed, 98 insertions, 6 deletions
diff --git a/spec/services/ci/create_pipeline_service/cache_spec.rb b/spec/services/ci/create_pipeline_service/cache_spec.rb index e8d9cec6695..2a65f92bfd6 100644 --- a/spec/services/ci/create_pipeline_service/cache_spec.rb +++ b/spec/services/ci/create_pipeline_service/cache_spec.rb @@ -39,7 +39,8 @@ RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectnes policy: 'pull-push', untracked: true, unprotect: false, - when: 'on_success' + when: 'on_success', + fallback_keys: [] } expect(pipeline).to be_persisted @@ -72,7 +73,8 @@ RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectnes paths: ['logs/'], policy: 'pull-push', when: 'on_success', - unprotect: false + unprotect: false, + fallback_keys: [] } expect(pipeline).to be_persisted @@ -89,7 +91,8 @@ RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectnes paths: ['logs/'], policy: 'pull-push', when: 'on_success', - unprotect: false + unprotect: false, + fallback_keys: [] } expect(pipeline).to be_persisted @@ -123,7 +126,8 @@ RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectnes paths: ['logs/'], policy: 'pull-push', when: 'on_success', - unprotect: false + unprotect: false, + fallback_keys: [] } expect(pipeline).to be_persisted @@ -140,7 +144,8 @@ RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectnes paths: ['logs/'], policy: 'pull-push', when: 'on_success', - unprotect: false + unprotect: false, + fallback_keys: [] } expect(pipeline).to be_persisted diff --git a/spec/services/import/github_service_spec.rb b/spec/services/import/github_service_spec.rb index a8928fb5c09..fa8b2489599 100644 --- a/spec/services/import/github_service_spec.rb +++ b/spec/services/import/github_service_spec.rb @@ -152,7 +152,8 @@ RSpec.describe Import::GithubService, feature_category: :importers do { single_endpoint_issue_events_import: true, single_endpoint_notes_import: 'false', - attachments_import: false + attachments_import: false, + collaborators_import: true } end diff --git a/spec/services/users/deactivate_service_spec.rb b/spec/services/users/deactivate_service_spec.rb new file mode 100644 index 00000000000..0bb6e51a3b1 --- /dev/null +++ b/spec/services/users/deactivate_service_spec.rb @@ -0,0 +1,86 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Users::DeactivateService, feature_category: :user_management do + let_it_be(:current_user) { build(:admin) } + let_it_be(:user) { build(:user) } + + subject(:service) { described_class.new(current_user) } + + describe '#execute' do + subject(:operation) { service.execute(user) } + + context 'when successful', :enable_admin_mode do + let(:user) { create(:user) } + + it 'returns success status' do + expect(operation[:status]).to eq(:success) + end + + it "changes the user's state" do + expect { operation }.to change { user.state }.to('deactivated') + end + + it 'creates a log entry' do + expect(Gitlab::AppLogger).to receive(:info).with(message: "User deactivated", user: user.username, + email: user.email, deactivated_by: current_user.username, ip_address: current_user.current_sign_in_ip.to_s) + + operation + end + end + + context 'when the user is already deactivated', :enable_admin_mode do + let(:user) { create(:user, :deactivated) } + + it 'returns error result' do + aggregate_failures 'error result' do + expect(operation[:status]).to eq(:success) + expect(operation[:message]).to eq('User has already been deactivated') + end + end + + it "does not change the user's state" do + expect { operation }.not_to change { user.state } + end + end + + context 'when internal user', :enable_admin_mode do + let(:user) { create(:user, :bot) } + + it 'returns an error message' do + expect(operation[:status]).to eq(:error) + expect(operation[:message]).to eq('Internal users cannot be deactivated') + expect(operation.reason).to eq :forbidden + end + end + + context 'when user is blocked', :enable_admin_mode do + let(:user) { create(:user, :blocked) } + + it 'returns an error message' do + expect(operation[:status]).to eq(:error) + expect(operation[:message]).to eq('Error occurred. A blocked user cannot be deactivated') + expect(operation.reason).to eq :forbidden + end + end + + context 'when user is not an admin' do + it 'returns permissions error message' do + expect(operation[:status]).to eq(:error) + expect(operation[:message]).to eq("You are not authorized to perform this action") + expect(operation.reason).to eq :forbidden + end + end + + context 'when skip_authorization is true' do + let(:non_admin_user) { create(:user) } + let(:user_to_deactivate) { create(:user) } + let(:skip_authorization_service) { described_class.new(non_admin_user, skip_authorization: true) } + + it 'deactivates the user even if the current user is not an admin' do + expect(skip_authorization_service.execute(user_to_deactivate)[:status]).to eq(:success) + end + end + end +end |