add more tests for phone numbers

This commit is contained in:
clemkeirua 2020-09-08 15:31:06 +02:00
parent 7038ca6c04
commit a62907f33b
3 changed files with 56 additions and 0 deletions

View file

@ -698,6 +698,43 @@ describe Users::DossiersController, type: :controller do
expect(instructeur.reload.followed_dossiers.with_notifications(instructeur)).to eq([dossier.reload])
end
end
context 'when the champ is a phone number' do
let(:procedure) { create(:procedure, :published, :with_phone) }
let!(:dossier) { create(:dossier, :en_construction, user: user, procedure: procedure) }
let(:first_champ) { dossier.champs.first }
let(:now) { Time.zone.parse('01/01/2100') }
let(:submit_payload) do
{
id: dossier.id,
dossier: {
champs_attributes: [
{
id: first_champ.id,
value: value
}
]
}
}
end
context 'with a valid value sent as string' do
let(:value) { '0612345678' }
it 'updates the value' do
subject
expect(first_champ.reload.value).to eq('0612345678')
end
end
context 'with a valid value sent as number' do
let(:value) { '45187272'.to_i }
it 'updates the value' do
subject
expect(first_champ.reload.value).to eq('45187272')
end
end
end
end
describe '#index' do

View file

@ -182,6 +182,12 @@ FactoryBot.define do
end
end
trait :with_phone do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_phone, procedure: procedure)
end
end
trait :published do
after(:build) do |procedure, _evaluator|
procedure.path = generate(:published_path)

View file

@ -20,6 +20,19 @@ describe Champs::PhoneChamp do
expect(build(:champ_phone, value: "+1(0) - 123456789")).to be_valid
expect(build(:champ_phone, value: "+49 2109 87654321")).to be_valid
expect(build(:champ_phone, value: "012345678")).to be_valid
# polynesian numbers should not return errors in any way
## landline numbers start with 40 or 45
expect(build(:champ_phone, value: "45187272")).to be_valid
expect(build(:champ_phone, value: "40 473 500")).to be_valid
expect(build(:champ_phone, value: "40473500")).to be_valid
expect(build(:champ_phone, value: "45473500")).to be_valid
## +689 is the international indicator
expect(build(:champ_phone, value: "+689 45473500")).to be_valid
expect(build(:champ_phone, value: "0145473500")).to be_valid
## polynesian mobile numbers start with 87, 88, 89
expect(build(:champ_phone, value: "87473500")).to be_valid
expect(build(:champ_phone, value: "88473500")).to be_valid
expect(build(:champ_phone, value: "89473500")).to be_valid
end
end
end