add and use api_djepva_up?

This commit is contained in:
simon lehericey 2024-04-05 12:08:40 +02:00
parent e994738a2e
commit 7b33963a67
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
4 changed files with 12 additions and 3 deletions

View file

@ -12,7 +12,7 @@ module RNAChampAssociationFetchableConcern
update!(data: data)
rescue APIEntreprise::API::Error => error
error_key = :network_error if error.try(:network_error?) && !APIEntrepriseService.api_up?
error_key = :network_error if error.try(:network_error?) && !APIEntrepriseService.api_djepva_up?
clear_association!(error_key)
end

View file

@ -74,5 +74,14 @@ class APIEntrepriseService
false
end
end
def api_djepva_up?
response = Typhoeus.get("https://entreprise.api.gouv.fr/ping/djepva/api-association", timeout: 1)
if response.success?
JSON.parse(response.body).fetch('status') == 'ok'
else
false
end
end
end
end

View file

@ -85,7 +85,7 @@ describe Champs::RNAController, type: :controller do
let(:body) { File.read('spec/fixtures/files/api_entreprise/associations.json') }
before do
expect(APIEntrepriseService).to receive(:api_up?).and_return(false)
expect(APIEntrepriseService).to receive(:api_djepva_up?).and_return(false)
end
subject! { get :show, params: params, format: :turbo_stream }

View file

@ -52,7 +52,7 @@ RSpec.describe RNAChampAssociationFetchableConcern do
let(:status) { 503 }
let(:body) { File.read('spec/fixtures/files/api_entreprise/associations.json') }
before { expect(APIEntrepriseService).to receive(:api_up?).and_return(false) }
before { expect(APIEntrepriseService).to receive(:api_djepva_up?).and_return(false) }
it_behaves_like "an association fetcher", false, :network_error, 'W595001988', nil
end