Files
Dalan/spec/models/phone_spec.rb
2026-08-13 19:56:46 +03:30

42 lines
1.1 KiB
Ruby

# frozen_string_literal: true
RSpec.describe Phone, type: :model do
let!(:create_member_permission) do
create :permission,
role: 'member'
end
context 'submasked fields' do
let!(:phone) { create(:phone) }
context 'number' do
it 'should mask country code and last 4 digits' do
phone.update(number: '79225551234')
expect(phone.sub_masked_number).to eq '7******1234'
end
it 'should mask country code and last 4 digits' do
phone.update(number: '+201112341923')
expect(phone.sub_masked_number).to eq '20******1923'
end
it 'should mask country code and last 4 digits' do
phone.update(number: '+380971232322')
expect(phone.sub_masked_number).to eq '380*****2322'
end
it 'should return empty phone number' do
phone.update(number: '')
expect(phone.sub_masked_number).to eq ''
end
context 'default country code' do
it 'should mask country code' do
phone.update_attribute(:number, '1112222')
expect(phone.sub_masked_number).to eq '11*2222'
end
end
end
end
end