Merge pull request #5549 from betagouv/ensure-polynesia-numbers-are-ok
Ensure polynesia numbers are ok
This commit is contained in:
commit
515c543dd0
5 changed files with 58 additions and 2 deletions
|
@ -454,7 +454,7 @@ GEM
|
||||||
ast (~> 2.4.1)
|
ast (~> 2.4.1)
|
||||||
pdf-core (0.7.0)
|
pdf-core (0.7.0)
|
||||||
pg (1.2.3)
|
pg (1.2.3)
|
||||||
phonelib (0.6.43)
|
phonelib (0.6.45)
|
||||||
prawn (2.2.2)
|
prawn (2.2.2)
|
||||||
pdf-core (~> 0.7.0)
|
pdf-core (~> 0.7.0)
|
||||||
ttfunk (~> 1.5)
|
ttfunk (~> 1.5)
|
||||||
|
|
|
@ -20,5 +20,5 @@ class Champs::PhoneChamp < Champs::TextChamp
|
||||||
possible: true,
|
possible: true,
|
||||||
allow_blank: true,
|
allow_blank: true,
|
||||||
message: I18n.t(:not_a_phone, scope: 'activerecord.errors.messages')
|
message: I18n.t(:not_a_phone, scope: 'activerecord.errors.messages')
|
||||||
}
|
}, unless: -> { Phonelib.valid_for_country?(value, :pf) }
|
||||||
end
|
end
|
||||||
|
|
|
@ -698,6 +698,43 @@ describe Users::DossiersController, type: :controller do
|
||||||
expect(instructeur.reload.followed_dossiers.with_notifications(instructeur)).to eq([dossier.reload])
|
expect(instructeur.reload.followed_dossiers.with_notifications(instructeur)).to eq([dossier.reload])
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
describe '#index' do
|
describe '#index' do
|
||||||
|
|
|
@ -182,6 +182,12 @@ FactoryBot.define do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :with_phone do
|
||||||
|
after(:build) do |procedure, _evaluator|
|
||||||
|
build(:type_de_champ_phone, procedure: procedure)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
trait :published do
|
trait :published do
|
||||||
after(:build) do |procedure, _evaluator|
|
after(:build) do |procedure, _evaluator|
|
||||||
procedure.path = generate(:published_path)
|
procedure.path = generate(:published_path)
|
||||||
|
|
|
@ -20,6 +20,19 @@ describe Champs::PhoneChamp do
|
||||||
expect(build(:champ_phone, value: "+1(0) - 123456789")).to be_valid
|
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: "+49 2109 87654321")).to be_valid
|
||||||
expect(build(:champ_phone, value: "012345678")).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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue