2015-08-10 11:05:06 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-03-15 16:56:21 +01:00
|
|
|
describe ApiEntreprise::EtablissementAdapter do
|
2018-03-15 12:02:45 +01:00
|
|
|
let(:procedure_id) { 33 }
|
|
|
|
|
2015-08-10 11:05:06 +02:00
|
|
|
context 'SIRET valide' do
|
2018-02-21 16:29:22 +01:00
|
|
|
let(:siret) { '41816609600051' }
|
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
|
2018-03-15 12:02:45 +01:00
|
|
|
stub_request(:get, /https:\/\/staging.entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/)
|
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
|
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
|
|
|
|
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
|
2018-01-30 15:16:02 +01:00
|
|
|
expect(subject[:adresse]).to eq("OCTO TECHNOLOGY\r\n50 AVENUE DES CHAMPS ELYSEES\r\n75008 PARIS\r\nFRANCE")
|
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 }
|
2018-03-15 12:02:45 +01:00
|
|
|
subject { described_class.new(bad_siret, 12).to_params }
|
2015-08-10 11:05:06 +02:00
|
|
|
|
|
|
|
before do
|
2018-03-15 12:02:45 +01:00
|
|
|
stub_request(:get, /https:\/\/staging.entreprise.api.gouv.fr\/v2\/etablissements\/#{bad_siret}?.*token=/)
|
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
|