2015-08-10 11:05:06 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe SIADE::EtablissementAdapter do
|
|
|
|
context 'SIRET valide' do
|
2015-08-20 17:30:17 +02:00
|
|
|
let(:siret) { 41_816_609_600_051 }
|
|
|
|
subject { described_class.new(siret).to_params }
|
2015-08-10 11:05:06 +02:00
|
|
|
|
|
|
|
before do
|
2017-12-11 15:31:45 +01:00
|
|
|
stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/etablissements/#{siret}?token=#{SIADETOKEN}")
|
2018-01-15 19:34:08 +01:00
|
|
|
.to_return(body: File.read('spec/support/files/etablissement.json', 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
|
|
|
|
expect(subject[:siret]).to eq('41816609600051')
|
|
|
|
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
|
|
|
|
expect(subject[:naf]).to eq('6202A')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'L\'entreprise contient bien un libelle_naf' do
|
|
|
|
expect(subject[:libelle_naf]).to eq('Conseil en systèmes et logiciels informatiques')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'Concaténation lignes adresse' do
|
|
|
|
it 'L\'entreprise contient bien une adresse sur plusieurs lignes' do
|
2016-06-13 10:13:37 +02:00
|
|
|
expect(subject[:adresse]).to eq("OCTO TECHNOLOGY\r\n50 AVENUE DES CHAMPS ELYSEES\r\n75008 PARIS\r\nFRANCE\r\n")
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'Détails adresse' do
|
|
|
|
it 'L\'entreprise contient bien un numero_voie' do
|
|
|
|
expect(subject[:numero_voie]).to eq('50')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'L\'entreprise contient bien un type_voie' do
|
|
|
|
expect(subject[:type_voie]).to eq('AV')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'L\'entreprise contient bien un nom_voie' do
|
|
|
|
expect(subject[:nom_voie]).to eq('DES CHAMPS ELYSEES')
|
|
|
|
end
|
|
|
|
it 'L\'entreprise contient bien un complement_adresse' do
|
|
|
|
expect(subject[:complement_adresse]).to eq('complement_adresse')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'L\'entreprise contient bien un code_postal' do
|
|
|
|
expect(subject[:code_postal]).to eq('75008')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'L\'entreprise contient bien une localite' do
|
|
|
|
expect(subject[:localite]).to eq('PARIS 8')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'L\'entreprise contient bien un code_insee_localite' do
|
|
|
|
expect(subject[:code_insee_localite]).to eq('75108')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
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 }
|
|
|
|
subject { described_class.new(bad_siret).to_params }
|
2015-08-10 11:05:06 +02:00
|
|
|
|
|
|
|
before do
|
2017-12-11 15:31:45 +01:00
|
|
|
stub_request(:get, "https://staging.entreprise.api.gouv.fr/v2/etablissements/#{bad_siret}?token=#{SIADETOKEN}")
|
2018-01-15 19:34:08 +01:00
|
|
|
.to_return(body: 'Fake body', status: 404)
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
2016-09-16 17:18:29 +02:00
|
|
|
it { expect(subject).to be_nil }
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
2015-08-20 17:30:17 +02:00
|
|
|
end
|