demarches-normaliennes/spec/lib/api_entreprise/api_spec.rb

117 lines
3.4 KiB
Ruby
Raw Normal View History

2015-08-10 11:05:06 +02:00
require 'spec_helper'
2018-03-15 16:56:21 +01:00
describe ApiEntreprise::API do
let(:procedure_id) { 12 }
describe '.entreprise' do
subject { described_class.entreprise(siren, procedure_id) }
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=/)
.to_return(status: status, body: body)
2015-08-10 11:05:06 +02:00
end
context 'when siren does not exist' do
let(:siren) { '111111111' }
let(:status) { 404 }
let(:body) { '' }
2015-08-10 11:05:06 +02:00
it 'raises RestClient::ResourceNotFound' do
2015-08-20 17:30:17 +02:00
expect { subject }.to raise_error(RestClient::ResourceNotFound)
end
2015-08-10 11:05:06 +02:00
end
context 'when siret exist' do
let(:siren) { '418166096' }
let(:status) { 200 }
let(:body) { File.read('spec/support/files/api_entreprise/entreprises.json') }
2015-08-10 11:05:06 +02:00
it 'returns response body' do
2018-03-15 14:23:57 +01:00
expect(subject).to eq(JSON.parse(body, symbolize_names: true))
end
end
end
2015-08-10 11:05:06 +02:00
describe '.etablissement' do
subject { described_class.etablissement(siret, procedure_id) }
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\/etablissements\/#{siret}?.*token=/)
.to_return(status: status, body: body)
2015-08-10 11:05:06 +02:00
end
context 'when siret does not exist' do
let(:siret) { '11111111111111' }
let(:status) { 404 }
let(:body) { '' }
it 'raises RestClient::ResourceNotFound' do
2015-08-20 17:30:17 +02:00
expect { subject }.to raise_error(RestClient::ResourceNotFound)
end
end
context 'when siret exists' do
let(:siret) { '41816609600051' }
let(:status) { 200 }
let(:body) { File.read('spec/support/files/api_entreprise/etablissements.json') }
it 'returns body' do
2018-03-15 14:23:57 +01:00
expect(subject).to eq(JSON.parse(body, symbolize_names: true))
end
2015-08-10 11:05:06 +02:00
end
end
describe '.exercices' do
before do
2018-05-09 12:03:04 +02:00
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\/.*token=/)
.to_return(status: status, body: body)
end
context 'when siret does not exist' do
subject { described_class.exercices(siret, procedure_id) }
let(:siret) { '11111111111111' }
let(:status) { 404 }
let(:body) { '' }
it 'raises RestClient::ResourceNotFound' do
expect { subject }.to raise_error(RestClient::ResourceNotFound)
end
end
context 'when siret exists' do
subject { described_class.exercices(siret, procedure_id) }
let(:siret) { '41816609600051' }
let(:status) { 200 }
let(:body) { File.read('spec/support/files/api_entreprise/exercices.json') }
it 'raises RestClient::Unauthorized' do
2018-03-15 14:23:57 +01:00
expect(subject).to eq(JSON.parse(body, symbolize_names: true))
end
end
end
2015-12-11 10:36:16 +01:00
describe '.rna' do
before do
2018-05-09 12:03:04 +02:00
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\/.*token=/)
.to_return(status: status, body: body)
2015-12-11 10:36:16 +01:00
end
subject { described_class.rna(siren, procedure_id) }
2015-12-11 10:36:16 +01:00
context 'when siren does not exist' do
let(:siren) { '111111111' }
let(:status) { 404 }
let(:body) { '' }
it 'raises RestClient::ResourceNotFound' do
expect { subject }.to raise_error(RestClient::ResourceNotFound)
end
end
context 'when siren exists' do
let(:siren) { '418166096' }
let(:status) { 200 }
let(:body) { File.read('spec/support/files/api_entreprise/associations.json') }
2015-12-11 10:36:16 +01:00
2018-03-15 14:23:57 +01:00
it { expect(subject).to eq(JSON.parse(body, symbolize_names: true)) }
2015-12-11 10:36:16 +01:00
end
end
2015-08-20 17:30:17 +02:00
end