zeitwerk: Api -> API

This commit is contained in:
Pierre de La Morinerie 2020-08-05 16:40:47 +00:00
parent 482f990594
commit 150ddab660
82 changed files with 235 additions and 217 deletions

View file

@ -1,4 +1,4 @@
describe ApiEntreprise::API do
describe APIEntreprise::API do
let(:procedure) { create(:procedure) }
let(:procedure_id) { procedure.id }
let(:token) { Rails.application.secrets.api_entreprise[:key] }
@ -9,7 +9,7 @@ describe ApiEntreprise::API do
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}/)
.to_return(status: status, body: body)
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end
context 'when the service throws a bad gateaway exception' do
@ -17,8 +17,8 @@ describe ApiEntreprise::API do
let(:status) { 502 }
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_unavailable.json') }
it 'raises ApiEntreprise::API::Error::RequestFailed' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::BadGateway)
it 'raises APIEntreprise::API::Error::RequestFailed' do
expect { subject }.to raise_error(APIEntreprise::API::Error::BadGateway)
end
end
@ -27,8 +27,8 @@ describe ApiEntreprise::API do
let(:status) { 404 }
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_not_found.json') }
it 'raises ApiEntreprise::API::Error::ResourceNotFound' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::ResourceNotFound)
it 'raises APIEntreprise::API::Error::ResourceNotFound' do
expect { subject }.to raise_error(APIEntreprise::API::Error::ResourceNotFound)
end
end
@ -37,8 +37,8 @@ describe ApiEntreprise::API do
let(:status) { 400 }
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_not_found.json') }
it 'raises ApiEntreprise::API::Error::BadFormatRequest' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::BadFormatRequest)
it 'raises APIEntreprise::API::Error::BadFormatRequest' do
expect { subject }.to raise_error(APIEntreprise::API::Error::BadFormatRequest)
end
end
@ -47,8 +47,8 @@ describe ApiEntreprise::API do
let(:status) { 403 }
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_private.json') }
it 'raises ApiEntreprise::API::Error::ResourceNotFound' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::ResourceNotFound)
it 'raises APIEntreprise::API::Error::ResourceNotFound' do
expect { subject }.to raise_error(APIEntreprise::API::Error::ResourceNotFound)
end
end
@ -89,7 +89,7 @@ describe ApiEntreprise::API do
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*non_diffusables=true/)
.to_return(status: status, body: body)
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end
context 'when siret does not exist' do
@ -97,8 +97,8 @@ describe ApiEntreprise::API do
let(:status) { 404 }
let(:body) { '' }
it 'raises ApiEntreprise::API::Error::ResourceNotFound' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::ResourceNotFound)
it 'raises APIEntreprise::API::Error::ResourceNotFound' do
expect { subject }.to raise_error(APIEntreprise::API::Error::ResourceNotFound)
end
end
@ -117,7 +117,7 @@ describe ApiEntreprise::API do
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\//)
.to_return(status: status, body: body)
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end
context 'when siret does not exist' do
@ -127,8 +127,8 @@ describe ApiEntreprise::API do
let(:status) { 404 }
let(:body) { '' }
it 'raises ApiEntreprise::API::Error::ResourceNotFound' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::ResourceNotFound)
it 'raises APIEntreprise::API::Error::ResourceNotFound' do
expect { subject }.to raise_error(APIEntreprise::API::Error::ResourceNotFound)
end
end
@ -149,7 +149,7 @@ describe ApiEntreprise::API do
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//)
.to_return(status: status, body: body)
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end
subject { described_class.rna(siren, procedure_id) }
@ -159,8 +159,8 @@ describe ApiEntreprise::API do
let(:status) { 404 }
let(:body) { '' }
it 'raises ApiEntreprise::API::Error::ResourceNotFound' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::ResourceNotFound)
it 'raises APIEntreprise::API::Error::ResourceNotFound' do
expect { subject }.to raise_error(APIEntreprise::API::Error::ResourceNotFound)
end
end
@ -180,8 +180,8 @@ describe ApiEntreprise::API do
let(:body) { File.read('spec/fixtures/files/api_entreprise/attestation_sociale.json') }
before do
allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(roles)
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return(roles)
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_sociales_acoss\/#{siren}/)
.to_return(body: body, status: status)
end
@ -209,8 +209,8 @@ describe ApiEntreprise::API do
let(:body) { File.read('spec/fixtures/files/api_entreprise/attestation_fiscale.json') }
before do
allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(roles)
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return(roles)
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_fiscales_dgfip\/#{siren}/)
.to_return(body: body, status: status)
end
@ -237,8 +237,8 @@ describe ApiEntreprise::API do
let(:body) { File.read('spec/fixtures/files/api_entreprise/bilans_entreprise_bdf.json') }
before do
allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(roles)
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return(roles)
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}/)
.to_return(body: body, status: status)
end
@ -263,7 +263,7 @@ describe ApiEntreprise::API do
subject { described_class.entreprise(siren, procedure_id) }
before do
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(true)
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(true)
end
it 'makes no call to api-entreprise' do

View file

@ -1,4 +1,4 @@
describe ApiEntreprise::AttestationFiscaleAdapter do
describe APIEntreprise::AttestationFiscaleAdapter do
let(:siret) { '41816609600069' }
let(:siren) { '418166096' }
let(:procedure) { create(:procedure) }
@ -9,8 +9,8 @@ describe ApiEntreprise::AttestationFiscaleAdapter do
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_fiscales_dgfip\/#{siren}/)
.to_return(body: body, status: status)
allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(["attestations_fiscales"])
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return(["attestations_fiscales"])
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end
context "when the SIREN is valid" do

View file

@ -1,4 +1,4 @@
describe ApiEntreprise::AttestationSocialeAdapter do
describe APIEntreprise::AttestationSocialeAdapter do
let(:siret) { '41816609600069' }
let(:siren) { '418166096' }
let(:procedure) { create(:procedure) }
@ -8,8 +8,8 @@ describe ApiEntreprise::AttestationSocialeAdapter do
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/attestations_sociales_acoss\/#{siren}/)
.to_return(body: body, status: status)
allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(["attestations_sociales"])
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return(["attestations_sociales"])
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end
context "when the SIREN is valid" do

View file

@ -1,4 +1,4 @@
describe ApiEntreprise::BilansBdfAdapter do
describe APIEntreprise::BilansBdfAdapter do
let(:siret) { '41816609600069' }
let(:siren) { '418166096' }
let(:procedure) { create(:procedure) }
@ -9,8 +9,8 @@ describe ApiEntreprise::BilansBdfAdapter do
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/bilans_entreprises_bdf\/#{siren}/)
.to_return(body: body, status: status)
allow_any_instance_of(ApiEntrepriseToken).to receive(:roles).and_return(["bilans_entreprise_bdf"])
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
allow_any_instance_of(APIEntrepriseToken).to receive(:roles).and_return(["bilans_entreprise_bdf"])
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end
context "when the SIREN is valid" do

View file

@ -1,4 +1,4 @@
describe ApiEntreprise::EffectifsAdapter do
describe APIEntreprise::EffectifsAdapter do
let(:siret) { '41816609600069' }
let(:siren) { '418166096' }
let(:procedure) { create(:procedure) }
@ -11,7 +11,7 @@ describe ApiEntreprise::EffectifsAdapter do
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_mensuels_acoss_covid\/#{annee}\/#{mois}\/entreprise\/#{siren}/)
.to_return(body: body, status: status)
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end
context "when the SIREN is valid" do

View file

@ -1,4 +1,4 @@
describe ApiEntreprise::EffectifsAnnuelsAdapter do
describe APIEntreprise::EffectifsAnnuelsAdapter do
let(:siret) { '41816609600069' }
let(:siren) { '418166096' }
let(:procedure) { create(:procedure) }
@ -9,7 +9,7 @@ describe ApiEntreprise::EffectifsAnnuelsAdapter do
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_annuels_acoss_covid\/#{siren}/)
.to_return(body: body, status: status)
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end
context "when the SIREN is valid" do

View file

@ -1,4 +1,4 @@
describe ApiEntreprise::EntrepriseAdapter do
describe APIEntreprise::EntrepriseAdapter do
let(:siren) { '418166096' }
let(:procedure) { create(:procedure) }
let(:procedure_id) { procedure.id }
@ -8,7 +8,7 @@ describe ApiEntreprise::EntrepriseAdapter do
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}/)
.to_return(body: body, status: status)
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end
context "when the SIRET is valid" do
@ -84,7 +84,7 @@ describe ApiEntreprise::EntrepriseAdapter do
let(:status) { 500 }
it 'raises an exception' do
expect { subject }.to raise_error(ApiEntreprise::API::Error::RequestFailed)
expect { subject }.to raise_error(APIEntreprise::API::Error::RequestFailed)
end
end
end

View file

@ -1,9 +1,9 @@
describe ApiEntreprise::EtablissementAdapter do
describe APIEntreprise::EtablissementAdapter do
let(:procedure) { create(:procedure) }
let(:procedure_id) { procedure.id }
before do
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end
context 'SIRET valide avec infos diffusables' do

View file

@ -1,4 +1,4 @@
describe ApiEntreprise::ExercicesAdapter do
describe APIEntreprise::ExercicesAdapter do
let(:siret) { '41816609600051' }
let(:procedure) { create(:procedure) }
subject { described_class.new(siret, procedure.id).to_params }
@ -6,7 +6,7 @@ describe ApiEntreprise::ExercicesAdapter do
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\//)
.to_return(body: File.read('spec/fixtures/files/api_entreprise/exercices.json', status: 200))
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end
it { is_expected.to be_an_instance_of(Hash) }

View file

@ -1,4 +1,4 @@
describe ApiEntreprise::RNAAdapter do
describe APIEntreprise::RNAAdapter do
let(:siret) { '50480511000013' }
let(:procedure) { create(:procedure) }
let(:procedure_id) { procedure.id }
@ -11,7 +11,7 @@ describe ApiEntreprise::RNAAdapter do
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\//)
.to_return(body: body, status: status)
allow_any_instance_of(ApiEntrepriseToken).to receive(:expired?).and_return(false)
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
end
context 'when siret is not valid' do