Corrige le crash de l'app lors d'un SIRET en erreur | Merge pull request #3604 from betagouv/fix-sentry-165
Corrige le crash de l'app lors d'un SIRET en erreur
This commit is contained in:
commit
0f0f917d3d
5 changed files with 79 additions and 51 deletions
1
Gemfile
1
Gemfile
|
@ -90,6 +90,7 @@ group :development do
|
|||
gem 'rubocop', require: false
|
||||
gem 'rubocop-rspec-focused', require: false
|
||||
gem 'scss_lint', require: false
|
||||
gem 'web-console'
|
||||
gem 'xray-rails'
|
||||
end
|
||||
|
||||
|
|
|
@ -101,6 +101,7 @@ GEM
|
|||
axlsx (>= 2.0, < 4)
|
||||
bcrypt (3.1.12)
|
||||
bindata (2.4.4)
|
||||
bindex (0.5.0)
|
||||
bootstrap-sass (3.4.1)
|
||||
autoprefixer-rails (>= 5.2.1)
|
||||
sassc (>= 2.0.0)
|
||||
|
@ -620,6 +621,11 @@ GEM
|
|||
vcr (4.0.0)
|
||||
warden (1.2.8)
|
||||
rack (>= 2.0.6)
|
||||
web-console (3.7.0)
|
||||
actionview (>= 5.0)
|
||||
activemodel (>= 5.0)
|
||||
bindex (>= 0.4.0)
|
||||
railties (>= 5.0)
|
||||
webfinger (1.1.0)
|
||||
activesupport
|
||||
httpclient (>= 2.4)
|
||||
|
@ -734,6 +740,7 @@ DEPENDENCIES
|
|||
typhoeus
|
||||
vcr
|
||||
warden
|
||||
web-console
|
||||
webmock
|
||||
webpacker (>= 4.0.x)
|
||||
xray-rails
|
||||
|
|
|
@ -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