Fix Sentry 165 : api crash when siret is unknown
This commit is contained in:
parent
2b93c8903a
commit
ff0356e698
3 changed files with 71 additions and 51 deletions
|
@ -7,9 +7,9 @@ class ApiEntreprise::EntrepriseAdapter < ApiEntreprise::Adapter
|
|||
end
|
||||
|
||||
def process_params
|
||||
params = data_source[:entreprise].slice(*attr_to_fetch)
|
||||
params = data_source[:entreprise]&.slice(*attr_to_fetch)
|
||||
|
||||
if valid_params?(params)
|
||||
if params.present? && valid_params?(params)
|
||||
params[:date_creation] = Time.zone.at(params[:date_creation]).to_datetime
|
||||
params.transform_keys { |k| :"entreprise_#{k}" }
|
||||
else
|
||||
|
|
6
spec/fixtures/files/api_entreprise/entreprises_not_found.json
vendored
Normal file
6
spec/fixtures/files/api_entreprise/entreprises_not_found.json
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"errors": [
|
||||
"Le siret ou siren indiqué n'existe pas, n'est pas connu ou ne comporte aucune information pour cet appel"
|
||||
],
|
||||
"gateway_error": true
|
||||
}
|
|
@ -8,9 +8,13 @@ describe ApiEntreprise::EntrepriseAdapter do
|
|||
|
||||
before do
|
||||
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}?.*token=/)
|
||||
.to_return(body: File.read('spec/fixtures/files/api_entreprise/entreprises.json', status: 200))
|
||||
.to_return(body: body, status: status)
|
||||
end
|
||||
|
||||
context "when SIRET is OK" do
|
||||
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises.json') }
|
||||
let(:status) { 200 }
|
||||
|
||||
it '#to_params class est une Hash ?' do
|
||||
expect(subject).to be_an_instance_of(Hash)
|
||||
end
|
||||
|
@ -65,3 +69,13 @@ describe ApiEntreprise::EntrepriseAdapter do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when SIRET is KO" do
|
||||
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_not_found.json') }
|
||||
let(:status) { 206 }
|
||||
|
||||
it '#to_params class est une Hash ?' do
|
||||
expect(subject).to eq({})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue