2020-08-05 18:40:47 +02:00
describe APIEntreprise :: EtablissementAdapter do
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
2020-05-05 16:58:37 +02:00
before do
2020-08-05 18:40:47 +02:00
allow_any_instance_of ( APIEntrepriseToken ) . to receive ( :expired? ) . and_return ( false )
2020-05-05 16:58:37 +02:00
end
2020-03-04 17:12:50 +01:00
context 'SIRET valide avec infos diffusables' do
2023-05-30 16:27:20 +02:00
let ( :siret ) { '30613890001294' }
2020-08-20 10:21:34 +02:00
let ( :fixture ) { 'spec/fixtures/files/api_entreprise/etablissements.json' }
2018-03-15 12:02:45 +01:00
subject { described_class . new ( siret , procedure_id ) . to_params }
2015-08-10 11:05:06 +02:00
before do
2023-05-30 16:27:20 +02:00
stub_request ( :get , / https: \/ \/ entreprise.api.gouv.fr \/ v3 \/ insee \/ sirene \/ etablissements \/ #{ siret } / )
2020-08-20 10:21:34 +02:00
. to_return ( body : File . read ( fixture , status : 200 ) )
2015-08-10 11:05:06 +02:00
end
it '#to_params class est une Hash ?' do
2015-08-20 16:29:06 +02:00
expect ( subject ) . to be_a_instance_of ( Hash )
2015-08-10 11:05:06 +02:00
end
context 'Attributs Etablissements' do
it 'L\'entreprise contient bien un siret' do
2018-02-21 16:29:22 +01:00
expect ( subject [ :siret ] ) . to eq ( siret )
2015-08-10 11:05:06 +02:00
end
it 'L\'entreprise contient bien un siege_social' do
expect ( subject [ :siege_social ] ) . to eq ( true )
end
it 'L\'entreprise contient bien un naf' do
2023-05-30 16:27:20 +02:00
expect ( subject [ :naf ] ) . to eq ( '8411Z' )
2015-08-10 11:05:06 +02:00
end
it 'L\'entreprise contient bien un libelle_naf' do
2023-05-30 16:27:20 +02:00
expect ( subject [ :libelle_naf ] ) . to eq ( 'Administration publique générale' )
2015-08-10 11:05:06 +02:00
end
2020-03-04 17:12:50 +01:00
it 'L\'entreprise contient bien un diffusable_commercialement qui vaut true' do
expect ( subject [ :diffusable_commercialement ] ) . to eq ( true )
end
2015-08-10 11:05:06 +02:00
context 'Concaténation lignes adresse' do
it 'L\'entreprise contient bien une adresse sur plusieurs lignes' do
2023-05-30 16:27:20 +02:00
expect ( subject [ :adresse ] ) . to eq ( " DIRECTION INTERMINISTERIELLE DU NUMERIQUE \r \n JEAN MARIE DURAND \r \n ZAE SAINT GUENAULT \r \n 51 BIS RUE DE LA PAIX \r \n CS 72809 \r \n 75256 PARIX CEDEX 12 \r \n FRANCE " )
2015-08-10 11:05:06 +02:00
end
end
context 'Détails adresse' do
it 'L\'entreprise contient bien un numero_voie' do
2023-05-30 16:27:20 +02:00
expect ( subject [ :numero_voie ] ) . to eq ( '22' )
2015-08-10 11:05:06 +02:00
end
it 'L\'entreprise contient bien un type_voie' do
2023-05-30 16:27:20 +02:00
expect ( subject [ :type_voie ] ) . to eq ( 'RUE' )
2015-08-10 11:05:06 +02:00
end
it 'L\'entreprise contient bien un nom_voie' do
2023-05-30 16:27:20 +02:00
expect ( subject [ :nom_voie ] ) . to eq ( 'DE LA PAIX' )
2015-08-10 11:05:06 +02:00
end
2023-05-30 16:27:20 +02:00
2015-08-10 11:05:06 +02:00
it 'L\'entreprise contient bien un complement_adresse' do
2023-05-30 16:27:20 +02:00
expect ( subject [ :complement_adresse ] ) . to eq ( 'ZAE SAINT GUENAULT' )
2015-08-10 11:05:06 +02:00
end
it 'L\'entreprise contient bien un code_postal' do
2023-05-30 16:27:20 +02:00
expect ( subject [ :code_postal ] ) . to eq ( '75016' )
2015-08-10 11:05:06 +02:00
end
it 'L\'entreprise contient bien une localite' do
2023-05-30 16:27:20 +02:00
expect ( subject [ :localite ] ) . to eq ( 'PARIS 12' )
2015-08-10 11:05:06 +02:00
end
it 'L\'entreprise contient bien un code_insee_localite' do
2023-05-30 16:27:20 +02:00
expect ( subject [ :code_insee_localite ] ) . to eq ( '75112' )
2015-08-10 11:05:06 +02:00
end
end
end
2020-08-20 10:21:34 +02:00
context 'Attributs Etablissements pour etablissement non siege' do
let ( :siret ) { '17310120500719' }
let ( :fixture ) { 'spec/fixtures/files/api_entreprise/etablissements-non-siege.json' }
it 'L\'entreprise contient bien un siret' do
expect ( subject [ :siret ] ) . to eq ( siret )
end
it 'L\'etablissement contient bien un siege_social à false' do
expect ( subject [ :siege_social ] ) . to eq ( false )
end
it 'L\'etablissement contient bien une enseigne' do
expect ( subject [ :enseigne ] ) . to eq ( " SERVICE PENITENTIAIRE D'INSERTION ET DE PROBATION, DE LA HAUTE-GARONNE " )
end
end
2015-08-10 11:05:06 +02:00
end
2020-03-04 17:12:50 +01:00
context 'SIRET valide avec infos non diffusables' do
let ( :siret ) { '41816609600051' }
subject { described_class . new ( siret , procedure_id ) . to_params }
before do
2023-05-30 16:27:20 +02:00
stub_request ( :get , / https: \/ \/ entreprise.api.gouv.fr \/ v3 \/ insee \/ sirene \/ etablissements \/ #{ siret } / )
2020-03-04 17:12:50 +01:00
. to_return ( body : File . read ( 'spec/fixtures/files/api_entreprise/etablissements_private.json' , status : 200 ) )
end
it 'L\'entreprise contient bien un diffusable_commercialement qui vaut false' do
expect ( subject [ :diffusable_commercialement ] ) . to eq ( false )
end
end
2015-08-17 15:53:35 +02:00
context 'when siret is not found' do
2015-08-20 17:30:17 +02:00
let ( :bad_siret ) { 11_111_111_111_111 }
2020-04-27 16:31:41 +02:00
subject { described_class . new ( bad_siret , procedure_id ) . to_params }
2015-08-10 11:05:06 +02:00
before do
2023-05-30 16:27:20 +02:00
stub_request ( :get , / https: \/ \/ entreprise.api.gouv.fr \/ v3 \/ insee \/ sirene \/ etablissements \/ #{ bad_siret } / )
2018-01-15 19:34:08 +01:00
. to_return ( body : 'Fake body' , status : 404 )
2015-08-10 11:05:06 +02:00
end
2018-03-19 14:47:56 +01:00
it { expect ( subject ) . to eq ( { } ) }
2015-08-10 11:05:06 +02:00
end
2015-08-20 17:30:17 +02:00
end