2020-08-05 18:40:47 +02:00
|
|
|
describe APIEntreprise::EntrepriseAdapter do
|
2023-05-25 11:15:26 +02:00
|
|
|
let(:siren) { '130025265' }
|
2020-04-27 16:31:41 +02:00
|
|
|
let(:procedure) { create(:procedure) }
|
|
|
|
let(:procedure_id) { procedure.id }
|
2018-03-15 12:02:45 +01:00
|
|
|
let(:adapter) { described_class.new(siren, procedure_id) }
|
2018-02-21 16:29:22 +01:00
|
|
|
subject { adapter.to_params }
|
2015-08-10 11:05:06 +02:00
|
|
|
|
|
|
|
before do
|
2023-05-25 11:15:26 +02:00
|
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v3\/insee\/sirene\/unites_legales\/#{siren}/)
|
2019-03-12 17:36:16 +01:00
|
|
|
.to_return(body: body, status: status)
|
2020-08-05 18:40:47 +02:00
|
|
|
allow_any_instance_of(APIEntrepriseToken).to receive(:expired?).and_return(false)
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
2019-04-30 16:36:40 +02:00
|
|
|
context "when the SIRET is valid" do
|
2019-03-12 17:36:16 +01:00
|
|
|
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises.json') }
|
|
|
|
let(:status) { 200 }
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2019-03-12 17:36:16 +01:00
|
|
|
it '#to_params class est une Hash ?' do
|
|
|
|
expect(subject).to be_an_instance_of(Hash)
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
2019-03-12 17:36:16 +01:00
|
|
|
context 'Attributs Entreprises' do
|
|
|
|
it 'L\'entreprise contient bien un siren' do
|
|
|
|
expect(subject[:entreprise_siren]).to eq(siren)
|
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2019-03-12 17:36:16 +01:00
|
|
|
it 'L\'entreprise contient bien une forme_juridique' do
|
2023-05-25 11:15:26 +02:00
|
|
|
expect(subject[:entreprise_forme_juridique]).to eq("Service central d'un ministère")
|
2019-03-12 17:36:16 +01:00
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2019-03-12 17:36:16 +01:00
|
|
|
it 'L\'entreprise contient bien un forme_juridique_code' do
|
2023-05-25 11:15:26 +02:00
|
|
|
expect(subject[:entreprise_forme_juridique_code]).to eq('7120')
|
2019-03-12 17:36:16 +01:00
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2019-03-12 17:36:16 +01:00
|
|
|
it 'L\'entreprise contient bien une raison_sociale' do
|
2023-05-25 11:15:26 +02:00
|
|
|
expect(subject[:entreprise_raison_sociale]).to eq('DIRECTION INTERMINISTERIELLE DU NUMERIQUE')
|
2019-03-12 17:36:16 +01:00
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2019-03-12 17:36:16 +01:00
|
|
|
it 'L\'entreprise contient bien un siret_siege_social' do
|
2023-05-25 11:15:26 +02:00
|
|
|
expect(subject[:entreprise_siret_siege_social]).to eq('13002526500013')
|
2019-03-12 17:36:16 +01:00
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2019-03-12 17:36:16 +01:00
|
|
|
it 'L\'entreprise contient bien un code_effectif_entreprise' do
|
2023-05-25 11:15:26 +02:00
|
|
|
expect(subject[:entreprise_code_effectif_entreprise]).to eq('51')
|
2019-03-12 17:36:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'L\'entreprise contient bien une date_creation' do
|
2023-05-25 11:15:26 +02:00
|
|
|
expect(subject[:entreprise_date_creation].to_i).to eq(1634103818)
|
2019-03-12 17:36:16 +01:00
|
|
|
end
|
2022-07-18 12:24:41 +02:00
|
|
|
|
|
|
|
it 'L\'entreprise contient bien un etat administratif' do
|
|
|
|
expect(subject[:entreprise_etat_administratif]).to eq('actif')
|
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
2022-09-05 15:52:06 +02:00
|
|
|
|
|
|
|
context "when date_creation is empty" do
|
|
|
|
let(:body) do
|
|
|
|
hash = JSON.parse(super())
|
2023-05-25 11:15:26 +02:00
|
|
|
hash["data"]["date_creation"] = nil
|
2022-09-05 15:52:06 +02:00
|
|
|
JSON.generate(hash)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'L\'entreprise ne contient pas de date_creation' do
|
|
|
|
expect(subject[:entreprise_date_creation]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2019-03-12 17:36:16 +01:00
|
|
|
end
|
|
|
|
|
2019-04-30 16:36:40 +02:00
|
|
|
context "when the SIRET is unknown" do
|
2019-03-12 17:36:16 +01:00
|
|
|
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_not_found.json') }
|
2019-04-30 16:36:40 +02:00
|
|
|
let(:status) { 404 }
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2019-03-12 17:36:16 +01:00
|
|
|
it '#to_params class est une Hash ?' do
|
|
|
|
expect(subject).to eq({})
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
2016-01-19 17:19:38 +01:00
|
|
|
end
|
2019-04-30 16:36:40 +02:00
|
|
|
|
|
|
|
context "when the service is unavailable" do
|
|
|
|
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprises_unavailable.json') }
|
2020-12-02 17:17:00 +01:00
|
|
|
let(:status) { 500 }
|
2019-04-30 16:36:40 +02:00
|
|
|
|
|
|
|
it 'raises an exception' do
|
2020-08-05 18:40:47 +02:00
|
|
|
expect { subject }.to raise_error(APIEntreprise::API::Error::RequestFailed)
|
2019-04-30 16:36:40 +02:00
|
|
|
end
|
|
|
|
end
|
2022-12-06 17:35:20 +01:00
|
|
|
|
|
|
|
context "when individual" do
|
|
|
|
let(:siren) { '909700890' }
|
|
|
|
let(:body) { File.read('spec/fixtures/files/api_entreprise/entreprise_individual.json') }
|
|
|
|
let(:status) { 200 }
|
|
|
|
|
2023-05-25 11:15:26 +02:00
|
|
|
it 'L\'entreprise contient bien un forme_juridique_code' do
|
|
|
|
expect(subject[:entreprise_forme_juridique_code]).to eq('1000')
|
|
|
|
end
|
2022-12-06 17:35:20 +01:00
|
|
|
|
2023-05-25 11:15:26 +02:00
|
|
|
# Suppression du champ raison_sociale pour les personnes physiques
|
|
|
|
# en v3
|
|
|
|
# https://entreprise.api.gouv.fr/developpeurs/guide-migration
|
|
|
|
it 'L\'entreprise ne contient pas de raison_sociale' do
|
|
|
|
expect(subject[:entreprise_raison_sociale]).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'L\'entreprise contient bien un nom' do
|
|
|
|
expect(subject[:entreprise_nom]).to eq('LE LOUARN SMAIL (LE LOUARN)')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'L\'entreprise contient bien un prenom' do
|
|
|
|
expect(subject[:entreprise_prenom]).to eq('MARINE')
|
2022-12-06 17:35:20 +01:00
|
|
|
end
|
|
|
|
end
|
2015-08-20 17:30:17 +02:00
|
|
|
end
|