4cb747fdb6
Test helpers are separated between two files: spec_helper and rails_helper. This separation is meant to allow tests that do not require Rails (like testing standalone libs) to boot faster. The spec_helper file is always loaded, through `--require spec_helper` in the `.rspec` config file. When needed, the rails_helper file is expected to be required manually. This is fine, but: - Many test files have a redundant `require 'spec_helper'` line; - Many test files should require `rails_helper`, but don't. Not requiring `rails_helper` will cause the Rails-concerned section of the test environment not to be configured–which may cause subtle bugs (like the test database not being properly initialized). Moreover, Spring loads all the Rails files on preloading anyway. So the gains from using only `spec_helper` are thin. To streamline this process, this commit: - Configures `.rspec` to require `rails_helper` by default; - Remove all manual requires to spec_helper or rails_helper. Reference: https://stackoverflow.com/questions/24145329/how-is-spec-rails-helper-rb-different-from-spec-spec-helper-rb-do-i-need-it
100 lines
3.4 KiB
Ruby
100 lines
3.4 KiB
Ruby
describe ApiEntreprise::EtablissementAdapter do
|
|
let(:procedure_id) { 33 }
|
|
|
|
context 'SIRET valide avec infos diffusables' do
|
|
let(:siret) { '41816609600051' }
|
|
subject { described_class.new(siret, procedure_id).to_params }
|
|
|
|
before do
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/)
|
|
.to_return(body: File.read('spec/fixtures/files/api_entreprise/etablissements.json', status: 200))
|
|
end
|
|
|
|
it '#to_params class est une Hash ?' do
|
|
expect(subject).to be_a_instance_of(Hash)
|
|
end
|
|
|
|
context 'Attributs Etablissements' do
|
|
it 'L\'entreprise contient bien un siret' do
|
|
expect(subject[:siret]).to eq(siret)
|
|
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
|
|
|
|
it 'L\'entreprise contient bien un diffusable_commercialement qui vaut true' do
|
|
expect(subject[:diffusable_commercialement]).to eq(true)
|
|
end
|
|
|
|
context 'Concaténation lignes adresse' do
|
|
it 'L\'entreprise contient bien une adresse sur plusieurs lignes' do
|
|
expect(subject[:adresse]).to eq("OCTO TECHNOLOGY\r\n50 AVENUE DES CHAMPS ELYSEES\r\n75008 PARIS\r\nFRANCE")
|
|
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
|
|
|
|
context 'SIRET valide avec infos non diffusables' do
|
|
let(:siret) { '41816609600051' }
|
|
subject { described_class.new(siret, procedure_id).to_params }
|
|
|
|
before do
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/)
|
|
.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
|
|
|
|
context 'when siret is not found' do
|
|
let(:bad_siret) { 11_111_111_111_111 }
|
|
subject { described_class.new(bad_siret, 12).to_params }
|
|
|
|
before do
|
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{bad_siret}?.*token=/)
|
|
.to_return(body: 'Fake body', status: 404)
|
|
end
|
|
|
|
it { expect(subject).to eq({}) }
|
|
end
|
|
end
|