diff options
Diffstat (limited to 'spec/services/users')
-rw-r--r-- | spec/services/users/auto_ban_service_spec.rb | 56 | ||||
-rw-r--r-- | spec/services/users/in_product_marketing_email_records_spec.rb | 13 | ||||
-rw-r--r-- | spec/services/users/signup_service_spec.rb | 75 | ||||
-rw-r--r-- | spec/services/users/trust_service_spec.rb (renamed from spec/services/users/allow_possible_spam_service_spec.rb) | 4 | ||||
-rw-r--r-- | spec/services/users/untrust_service_spec.rb (renamed from spec/services/users/disallow_possible_spam_service_spec.rb) | 8 |
5 files changed, 63 insertions, 93 deletions
diff --git a/spec/services/users/auto_ban_service_spec.rb b/spec/services/users/auto_ban_service_spec.rb new file mode 100644 index 00000000000..b989cec6a9d --- /dev/null +++ b/spec/services/users/auto_ban_service_spec.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Users::AutoBanService, feature_category: :instance_resiliency do + let_it_be_with_reload(:user) { create(:user) } + let(:reason) { :auto_ban_reason } + + context 'when auto banning a user', :aggregate_failures do + subject(:auto_ban_user) { described_class.new(user: user, reason: reason).execute } + + context 'when successful' do + it 'returns success status' do + response = auto_ban_user + + expect(response[:status]).to eq(:success) + end + + it 'bans the user' do + expect { auto_ban_user }.to change { user.state }.from('active').to('banned') + end + + it 'creates a BannedUser' do + expect { auto_ban_user }.to change { Users::BannedUser.count }.by(1) + expect(Users::BannedUser.last.user_id).to eq(user.id) + end + + describe 'recording a custom attribute' do + it 'records a custom attribute' do + expect { auto_ban_user }.to change { UserCustomAttribute.count }.by(1) + expect(user.custom_attributes.by_key(UserCustomAttribute::AUTO_BANNED_BY).first.value).to eq(reason.to_s) + end + end + end + + context 'when failed' do + context 'when user is blocked' do + before do + user.block! + end + + it 'returns state error message' do + response = auto_ban_user + + expect(response[:status]).to eq(:error) + expect(response[:message]).to match('State cannot transition via \"ban\"') + end + + it 'does not modify the BannedUser record or user state' do + expect { auto_ban_user }.not_to change { Users::BannedUser.count } + expect { auto_ban_user }.not_to change { user.state } + end + end + end + end +end diff --git a/spec/services/users/in_product_marketing_email_records_spec.rb b/spec/services/users/in_product_marketing_email_records_spec.rb index 059f0890b53..d214560b2a6 100644 --- a/spec/services/users/in_product_marketing_email_records_spec.rb +++ b/spec/services/users/in_product_marketing_email_records_spec.rb @@ -17,7 +17,6 @@ RSpec.describe Users::InProductMarketingEmailRecords, feature_category: :onboard records.add(user, track: :team_short, series: 0) records.add(user, track: :create, series: 1) - records.add(user, campaign: Users::InProductMarketingEmail::BUILD_IOS_APP_GUIDE) end it 'bulk inserts added records' do @@ -36,30 +35,20 @@ RSpec.describe Users::InProductMarketingEmailRecords, feature_category: :onboard freeze_time do records.add(user, track: :team_short, series: 0) records.add(user, track: :create, series: 1) - records.add(user, campaign: Users::InProductMarketingEmail::BUILD_IOS_APP_GUIDE) - first, second, third = records.records + first, second = records.records expect(first).to be_a Users::InProductMarketingEmail - expect(first.campaign).to be_nil expect(first.track.to_sym).to eq :team_short expect(first.series).to eq 0 expect(first.created_at).to eq Time.zone.now expect(first.updated_at).to eq Time.zone.now expect(second).to be_a Users::InProductMarketingEmail - expect(second.campaign).to be_nil expect(second.track.to_sym).to eq :create expect(second.series).to eq 1 expect(second.created_at).to eq Time.zone.now expect(second.updated_at).to eq Time.zone.now - - expect(third).to be_a Users::InProductMarketingEmail - expect(third.campaign).to eq Users::InProductMarketingEmail::BUILD_IOS_APP_GUIDE - expect(third.track).to be_nil - expect(third.series).to be_nil - expect(third.created_at).to eq Time.zone.now - expect(third.updated_at).to eq Time.zone.now end end end diff --git a/spec/services/users/signup_service_spec.rb b/spec/services/users/signup_service_spec.rb deleted file mode 100644 index 29663411346..00000000000 --- a/spec/services/users/signup_service_spec.rb +++ /dev/null @@ -1,75 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Users::SignupService, feature_category: :system_access do - let(:user) { create(:user, setup_for_company: true) } - - describe '#execute' do - context 'when updating name' do - it 'updates the name attribute' do - result = update_user(user, name: 'New Name') - - expect(result.success?).to be(true) - expect(user.reload.name).to eq('New Name') - end - - it 'returns an error result when name is missing' do - result = update_user(user, name: '') - - expect(user.reload.name).not_to be_blank - expect(result.success?).to be(false) - expect(result.message).to include("Name can't be blank") - end - end - - context 'when updating role' do - it 'updates the role attribute' do - result = update_user(user, role: 'development_team_lead') - - expect(result.success?).to be(true) - expect(user.reload.role).to eq('development_team_lead') - end - - it 'returns an error result when role is missing' do - result = update_user(user, role: '') - - expect(user.reload.role).not_to be_blank - expect(result.success?).to be(false) - expect(result.message).to eq("Role can't be blank") - end - end - - context 'when updating setup_for_company' do - it 'updates the setup_for_company attribute' do - result = update_user(user, setup_for_company: 'false') - - expect(result.success?).to be(true) - expect(user.reload.setup_for_company).to be(false) - end - - context 'when on SaaS', :saas do - it 'returns an error result when setup_for_company is missing' do - result = update_user(user, setup_for_company: '') - - expect(user.reload.setup_for_company).not_to be_blank - expect(result.success?).to be(false) - expect(result.message).to eq("Setup for company can't be blank") - end - end - - context 'when not on .com' do - it 'returns success when setup_for_company is blank' do - result = update_user(user, setup_for_company: '') - - expect(result.success?).to be(true) - expect(user.reload.setup_for_company).to be(nil) - end - end - end - - def update_user(user, opts) - described_class.new(user, opts).execute - end - end -end diff --git a/spec/services/users/allow_possible_spam_service_spec.rb b/spec/services/users/trust_service_spec.rb index 53618f0c8e9..1f71992ce9b 100644 --- a/spec/services/users/allow_possible_spam_service_spec.rb +++ b/spec/services/users/trust_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Users::AllowPossibleSpamService, feature_category: :user_management do +RSpec.describe Users::TrustService, feature_category: :user_management do let_it_be(:current_user) { create(:admin) } subject(:service) { described_class.new(current_user) } @@ -18,7 +18,7 @@ RSpec.describe Users::AllowPossibleSpamService, feature_category: :user_manageme operation user.reload - expect(user.custom_attributes.by_key(UserCustomAttribute::ALLOW_POSSIBLE_SPAM)).to be_present + expect(user.custom_attributes.by_key(UserCustomAttribute::TRUSTED_BY)).to be_present end end end diff --git a/spec/services/users/disallow_possible_spam_service_spec.rb b/spec/services/users/untrust_service_spec.rb index 32a47e05525..054cb9b82dc 100644 --- a/spec/services/users/disallow_possible_spam_service_spec.rb +++ b/spec/services/users/untrust_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Users::DisallowPossibleSpamService, feature_category: :user_management do +RSpec.describe Users::UntrustService, feature_category: :user_management do let_it_be(:current_user) { create(:admin) } subject(:service) { described_class.new(current_user) } @@ -16,19 +16,19 @@ RSpec.describe Users::DisallowPossibleSpamService, feature_category: :user_manag UserCustomAttribute.upsert_custom_attributes( [{ user_id: user.id, - key: :allow_possible_spam, + key: UserCustomAttribute::TRUSTED_BY, value: 'not important' }] ) end it 'updates the custom attributes', :aggregate_failures do - expect(user.custom_attributes.by_key(UserCustomAttribute::ALLOW_POSSIBLE_SPAM)).to be_present + expect(user.trusted_with_spam_attribute).to be_present operation user.reload - expect(user.custom_attributes).to be_empty + expect(user.trusted_with_spam_attribute).to be nil end end end |