debian-mirror-gitlab/spec/services/users/block_service_spec.rb

58 lines
1.6 KiB
Ruby
Raw Permalink Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Users::BlockService, feature_category: :user_management do
2023-03-17 16:20:25 +05:30
let_it_be(:current_user) { create(:admin) }
2020-03-13 15:44:24 +05:30
subject(:service) { described_class.new(current_user) }
describe '#execute' do
subject(:operation) { service.execute(user) }
context 'when successful' do
let(:user) { create(:user) }
it { is_expected.to eq(status: :success) }
it "change the user's state" do
expect { operation }.to change { user.state }.to('blocked')
end
2023-03-17 16:20:25 +05:30
it 'saves a custom attribute', :aggregate_failures, :freeze_time, feature_category: :insider_threat do
operation
custom_attribute = user.custom_attributes.last
expect(custom_attribute.key).to eq(UserCustomAttribute::BLOCKED_BY)
expect(custom_attribute.value).to eq("#{current_user.username}/#{current_user.id}+#{Time.current}")
end
2020-03-13 15:44:24 +05:30
end
context 'when failed' do
let(:user) { create(:user, :blocked) }
it 'returns error result' do
aggregate_failures 'error result' do
expect(operation[:status]).to eq(:error)
expect(operation[:message]).to match(/State cannot transition/)
end
end
it "does not change the user's state" do
expect { operation }.not_to change { user.state }
end
end
2021-01-03 14:25:43 +05:30
context 'when internal user' do
let(:user) { create(:user, :bot) }
it 'returns error result' do
expect(operation[:status]).to eq(:error)
expect(operation[:message]).to eq('An internal user cannot be blocked')
expect(operation[:http_status]).to eq(403)
end
end
2020-03-13 15:44:24 +05:30
end
end