Merge pull request #7890 from colinux/fix-address-without-postcode

fix(api_address): support Adresse BAN without postcode
This commit is contained in:
Colin Darie 2022-10-11 12:44:34 +02:00 committed by GitHub
commit 9fc12a87cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 5 deletions

View file

@ -22,7 +22,7 @@ class APIAddress::AddressAdapter
street_address: result.street_address,
street_number: result.street_number,
street_name: result.street_name,
postal_code: result.postal_code,
postal_code: result.postal_code.presence || "",
city_name: result.city_name,
city_code: result.city_code,
department_name: result.department_name,

View file

@ -19,7 +19,7 @@
"enum": ["housenumber", "street", "locality", "municipality"]
}
},
"required": ["label", "type", "name", "postcode", "citycode", "city"]
"required": ["label", "type", "name", "citycode", "city"]
},
"geometry": {
"type": "object",

View file

@ -1,6 +1,7 @@
describe APIAddress::AddressAdapter do
let(:search_term) { 'Paris' }
let(:adapter) { described_class.new(search_term) }
let(:status) { 200 }
subject { adapter.to_params }
before do
@ -15,7 +16,6 @@ describe APIAddress::AddressAdapter do
context "when responds with valid schema" do
let(:body) { File.read('spec/fixtures/files/api_address/address.json') }
let(:status) { 200 }
it '#to_params returns a valid' do
expect(subject).to be_an_instance_of(Hash)
@ -26,7 +26,6 @@ describe APIAddress::AddressAdapter do
context "when responds with an address which is not a direct match to search term" do
let(:body) { File.read('spec/fixtures/files/api_address/address.json') }
let(:status) { 200 }
let(:search_term) { 'Lyon' }
it '#to_params ignores the response' do
@ -36,10 +35,21 @@ describe APIAddress::AddressAdapter do
context "when responds with invalid schema" do
let(:body) { File.read('spec/fixtures/files/api_address/address_invalid.json') }
let(:status) { 200 }
it '#to_params raise exception' do
expect { subject }.to raise_exception(APIAddress::AddressAdapter::InvalidSchemaError)
end
end
context "when responds without postcode" do
let(:body) {
json = JSON.parse(File.read('spec/fixtures/files/api_address/address.json'))
json["features"][0]["properties"].delete("postcode")
json.to_json
}
it "#to_params default to an empty postcode" do
expect(subject[:postal_code]).to eq("")
end
end
end