2015-08-10 11:05:06 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-03-15 16:56:21 +01:00
|
|
|
describe ApiEntreprise::EntrepriseAdapter do
|
2018-02-21 16:29:22 +01:00
|
|
|
let(:siren) { '418166096' }
|
2018-03-15 12:02:45 +01:00
|
|
|
let(:procedure_id) { 22 }
|
|
|
|
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
|
2018-05-09 12:03:04 +02:00
|
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}?.*token=/)
|
2019-03-12 17:36:16 +01:00
|
|
|
.to_return(body: body, status: status)
|
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 un capital_social' do
|
|
|
|
expect(subject[:entreprise_capital_social]).to eq(462308)
|
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2019-03-12 17:36:16 +01:00
|
|
|
it 'L\'entreprise contient bien un numero_tva_intracommunautaire' do
|
|
|
|
expect(subject[:entreprise_numero_tva_intracommunautaire]).to eq('FR16418166096')
|
|
|
|
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
|
|
|
|
expect(subject[:entreprise_forme_juridique]).to eq('SA à directoire (s.a.i.)')
|
|
|
|
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
|
|
|
|
expect(subject[:entreprise_forme_juridique_code]).to eq('5699')
|
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2019-03-12 17:36:16 +01:00
|
|
|
it 'L\'entreprise contient bien un nom_commercial' do
|
|
|
|
expect(subject[:entreprise_nom_commercial]).to eq('OCTO-TECHNOLOGY')
|
|
|
|
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
|
|
|
|
expect(subject[:entreprise_raison_sociale]).to eq('OCTO-TECHNOLOGY')
|
|
|
|
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
|
|
|
|
expect(subject[:entreprise_siret_siege_social]).to eq('41816609600051')
|
|
|
|
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
|
|
|
|
expect(subject[:entreprise_code_effectif_entreprise]).to eq('31')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'L\'entreprise contient bien une date_creation' do
|
|
|
|
expect(subject[:entreprise_date_creation]).to eq('Wed, 01 Apr 1998 00:00:00.000000000 +0200')
|
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2019-03-12 17:36:16 +01:00
|
|
|
it 'L\'entreprise contient bien un nom' do
|
|
|
|
expect(subject[:entreprise_nom]).to eq('test_nom')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'L\'entreprise contient bien un prenom' do
|
|
|
|
expect(subject[:entreprise_prenom]).to eq('test_prenom')
|
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
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') }
|
|
|
|
let(:status) { 502 }
|
|
|
|
|
|
|
|
it 'raises an exception' do
|
|
|
|
expect { subject }.to raise_error(RestClient::RequestFailed)
|
|
|
|
end
|
|
|
|
end
|
2015-08-20 17:30:17 +02:00
|
|
|
end
|