diff options
Diffstat (limited to 'spec/services/users')
-rw-r--r-- | spec/services/users/block_service_spec.rb | 11 | ||||
-rw-r--r-- | spec/services/users/signup_service_spec.rb | 20 | ||||
-rw-r--r-- | spec/services/users/unblock_service_spec.rb | 45 |
3 files changed, 65 insertions, 11 deletions
diff --git a/spec/services/users/block_service_spec.rb b/spec/services/users/block_service_spec.rb index 45a5b1e5100..7ff9a887f38 100644 --- a/spec/services/users/block_service_spec.rb +++ b/spec/services/users/block_service_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe Users::BlockService do - let(:current_user) { create(:admin) } + let_it_be(:current_user) { create(:admin) } subject(:service) { described_class.new(current_user) } @@ -18,6 +18,15 @@ RSpec.describe Users::BlockService do it "change the user's state" do expect { operation }.to change { user.state }.to('blocked') end + + 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 end context 'when failed' do diff --git a/spec/services/users/signup_service_spec.rb b/spec/services/users/signup_service_spec.rb index 7169401ab34..ef532e01d0b 100644 --- a/spec/services/users/signup_service_spec.rb +++ b/spec/services/users/signup_service_spec.rb @@ -10,7 +10,7 @@ RSpec.describe Users::SignupService do it 'updates the name attribute' do result = update_user(user, name: 'New Name') - expect(result).to eq(status: :success) + expect(result.success?).to be(true) expect(user.reload.name).to eq('New Name') end @@ -18,8 +18,8 @@ RSpec.describe Users::SignupService do result = update_user(user, name: '') expect(user.reload.name).not_to be_blank - expect(result[:status]).to eq(:error) - expect(result[:message]).to include("Name can't be blank") + expect(result.success?).to be(false) + expect(result.message).to include("Name can't be blank") end end @@ -27,7 +27,7 @@ RSpec.describe Users::SignupService do it 'updates the role attribute' do result = update_user(user, role: 'development_team_lead') - expect(result).to eq(status: :success) + expect(result.success?).to be(true) expect(user.reload.role).to eq('development_team_lead') end @@ -35,8 +35,8 @@ RSpec.describe Users::SignupService do result = update_user(user, role: '') expect(user.reload.role).not_to be_blank - expect(result[:status]).to eq(:error) - expect(result[:message]).to eq("Role can't be blank") + expect(result.success?).to be(false) + expect(result.message).to eq("Role can't be blank") end end @@ -44,7 +44,7 @@ RSpec.describe Users::SignupService do it 'updates the setup_for_company attribute' do result = update_user(user, setup_for_company: 'false') - expect(result).to eq(status: :success) + expect(result.success?).to be(true) expect(user.reload.setup_for_company).to be(false) end @@ -57,8 +57,8 @@ RSpec.describe Users::SignupService do result = update_user(user, setup_for_company: '') expect(user.reload.setup_for_company).not_to be_blank - expect(result[:status]).to eq(:error) - expect(result[:message]).to eq("Setup for company can't be blank") + expect(result.success?).to be(false) + expect(result.message).to eq("Setup for company can't be blank") end end @@ -66,7 +66,7 @@ RSpec.describe Users::SignupService do it 'returns success when setup_for_company is blank' do result = update_user(user, setup_for_company: '') - expect(result).to eq(status: :success) + expect(result.success?).to be(true) expect(user.reload.setup_for_company).to be(nil) end end diff --git a/spec/services/users/unblock_service_spec.rb b/spec/services/users/unblock_service_spec.rb new file mode 100644 index 00000000000..25ee99427ab --- /dev/null +++ b/spec/services/users/unblock_service_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Users::UnblockService do + let_it_be(:current_user) { create(:admin) } + + subject(:service) { described_class.new(current_user) } + + describe '#execute' do + subject(:operation) { service.execute(user) } + + context 'when successful' do + let(:user) { create(:user, :blocked) } + + it { expect(operation.success?).to eq(true) } + + it "change the user's state" do + expect { operation }.to change { user.active? }.to(true) + end + + 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::UNBLOCKED_BY) + expect(custom_attribute.value).to eq("#{current_user.username}/#{current_user.id}+#{Time.current}") + end + end + + context 'when failed' do + let(:user) { create(:user) } + + it 'returns error result', :aggregate_failures do + expect(operation.error?).to eq(true) + expect(operation[:message]).to include(/State cannot transition/) + end + + it "does not change the user's state" do + expect { operation }.not_to change { user.state } + end + end + end +end |