diff options
Diffstat (limited to 'spec/models/users')
-rw-r--r-- | spec/models/users/namespace_callout_spec.rb | 39 | ||||
-rw-r--r-- | spec/models/users/phone_number_validation_spec.rb | 81 |
2 files changed, 81 insertions, 39 deletions
diff --git a/spec/models/users/namespace_callout_spec.rb b/spec/models/users/namespace_callout_spec.rb deleted file mode 100644 index f8207f2abc8..00000000000 --- a/spec/models/users/namespace_callout_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Users::NamespaceCallout do - let_it_be(:user) { create_default(:user) } - let_it_be(:namespace) { create_default(:namespace) } - let_it_be(:callout) { create(:namespace_callout) } - - it_behaves_like 'having unique enum values' - - describe 'relationships' do - it { is_expected.to belong_to(:namespace) } - end - - describe 'validations' do - it { is_expected.to validate_presence_of(:namespace) } - it { is_expected.to validate_presence_of(:user) } - it { is_expected.to validate_presence_of(:feature_name) } - - specify do - is_expected.to validate_uniqueness_of(:feature_name) - .scoped_to(:user_id, :namespace_id) - .ignoring_case_sensitivity - end - - it { is_expected.to allow_value(:web_hook_disabled).for(:feature_name) } - - it 'rejects invalid feature names' do - expect { callout.feature_name = :non_existent_feature }.to raise_error(ArgumentError) - end - end - - describe '#source_feature_name' do - it 'provides string based off source and feature' do - expect(callout.source_feature_name).to eq "#{callout.feature_name}_#{callout.namespace_id}" - end - end -end diff --git a/spec/models/users/phone_number_validation_spec.rb b/spec/models/users/phone_number_validation_spec.rb new file mode 100644 index 00000000000..2f0fd1d3ac9 --- /dev/null +++ b/spec/models/users/phone_number_validation_spec.rb @@ -0,0 +1,81 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Users::PhoneNumberValidation do + it { is_expected.to belong_to(:user) } + it { is_expected.to belong_to(:banned_user) } + + it { is_expected.to validate_presence_of(:country) } + it { is_expected.to validate_length_of(:country).is_at_most(3) } + + it { is_expected.to validate_presence_of(:international_dial_code) } + + it { + is_expected.to validate_numericality_of(:international_dial_code) + .only_integer + .is_greater_than_or_equal_to(1) + .is_less_than_or_equal_to(999) + } + + it { is_expected.to validate_presence_of(:phone_number) } + it { is_expected.to validate_length_of(:phone_number).is_at_most(12) } + it { is_expected.to allow_value('555555').for(:phone_number) } + it { is_expected.not_to allow_value('555-555').for(:phone_number) } + it { is_expected.not_to allow_value('+555555').for(:phone_number) } + it { is_expected.not_to allow_value('555 555').for(:phone_number) } + + it { is_expected.to validate_length_of(:telesign_reference_xid).is_at_most(255) } + + describe '.related_to_banned_user?' do + let_it_be(:international_dial_code) { 1 } + let_it_be(:phone_number) { '555' } + + let_it_be(:user) { create(:user) } + let_it_be(:banned_user) { create(:user, :banned) } + + subject(:related_to_banned_user?) do + described_class.related_to_banned_user?(international_dial_code, phone_number) + end + + context 'when banned user has the same international dial code and phone number' do + before do + create(:phone_number_validation, user: banned_user) + end + + it { is_expected.to eq(true) } + end + + context 'when banned user has the same international dial code and phone number, but different country code' do + before do + create(:phone_number_validation, user: banned_user, country: 'CA') + end + + it { is_expected.to eq(true) } + end + + context 'when banned user does not have the same international dial code' do + before do + create(:phone_number_validation, user: banned_user, international_dial_code: 61) + end + + it { is_expected.to eq(false) } + end + + context 'when banned user does not have the same phone number' do + before do + create(:phone_number_validation, user: banned_user, phone_number: '666') + end + + it { is_expected.to eq(false) } + end + + context 'when not-banned user has the same international dial code and phone number' do + before do + create(:phone_number_validation, user: user) + end + + it { is_expected.to eq(false) } + end + end +end |