Merge pull request #10794 from mfo/US/fix-normalized-international-adresse

correctif: ETQ usager une adresse internationnale ne fait pas planter la page
This commit is contained in:
mfo 2024-09-13 12:13:11 +00:00 committed by GitHub
commit 52610010b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 12 deletions

View file

@ -32,10 +32,14 @@ class AddressProxy
@city_name = etablissement.localite @city_name = etablissement.localite
@postal_code = etablissement.code_postal @postal_code = etablissement.code_postal
@city_code = etablissement.code_insee_localite @city_code = etablissement.code_insee_localite
if @postal_code
@departement_name = APIGeoService.departement_name_by_postal_code(@postal_code) @departement_name = APIGeoService.departement_name_by_postal_code(@postal_code)
@departement_code = APIGeoService.departement_code(@departement_name) @departement_code = APIGeoService.departement_code(@departement_name)
@region_code = APIGeoService.region_code_by_departement(@departement_code) @region_code = APIGeoService.region_code_by_departement(@departement_code)
@region_name = APIGeoService.region_name(@region_code) @region_name = APIGeoService.region_name(@region_code)
else # adresse without postal_code, ex:
@departement_name, @departement_code, @region_code, @region_name = nil
end
end end
end end

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
describe 'shared/dossiers/normalized_address', type: :view do describe 'shared/dossiers/normalized_address', type: :view do
before { render 'shared/dossiers/normalized_address', address: } let(:subject) { render 'shared/dossiers/normalized_address', address: }
context 'given an champ' do context 'given an champ' do
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :siret }]) } let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :siret }]) }
@ -10,7 +10,7 @@ describe 'shared/dossiers/normalized_address', type: :view do
it 'render address' do it 'render address' do
AddressProxy::ADDRESS_PARTS.each do |address_part| AddressProxy::ADDRESS_PARTS.each do |address_part|
expect(rendered).to have_text(address_part) expect(subject).to have_text(address_part)
end end
end end
end end
@ -20,12 +20,22 @@ describe 'shared/dossiers/normalized_address', type: :view do
let(:address) { AddressProxy.new(etablissement) } let(:address) { AddressProxy.new(etablissement) }
it 'render address' do it 'render address' do
expect(rendered).to have_text("6 RUE RAOUL NORDLING") expect(subject).to have_text("6 RUE RAOUL NORDLING")
expect(rendered).to have_text("BOIS COLOMBES 92270") expect(subject).to have_text("BOIS COLOMBES 92270")
expect(rendered).to have_text("92009") expect(subject).to have_text("92009")
expect(rendered).to have_text("92270") expect(subject).to have_text("92270")
expect(rendered).to have_text("Hauts-de-Seine 92") expect(subject).to have_text("Hauts-de-Seine 92")
expect(rendered).to have_text("Île-de-France 11") expect(subject).to have_text("Île-de-France 11")
end
end
context 'given a partial etablissement address' do
let(:etablissement) { create(:etablissement) }
before { allow(etablissement).to receive(:code_postal).and_return(nil) }
let(:address) { AddressProxy.new(etablissement) }
it 'render address' do
expect { subject }.not_to raise_error
end end
end end
end end