2015-08-10 11:05:06 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-08-17 15:53:35 +02:00
|
|
|
describe SIADE::API do
|
|
|
|
describe '.entreprise' do
|
2015-08-20 17:30:17 +02:00
|
|
|
subject { described_class.entreprise(siren) }
|
2015-08-10 11:05:06 +02:00
|
|
|
before do
|
2015-08-20 17:30:17 +02:00
|
|
|
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}")
|
2015-11-16 11:23:29 +01:00
|
|
|
.to_return(status: status, body: body)
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
2015-08-17 15:53:35 +02:00
|
|
|
context 'when siren does not exist' do
|
|
|
|
let(:siren) { '111111111' }
|
|
|
|
let(:status) { 404 }
|
|
|
|
let(:body) { '' }
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2015-08-17 15:53:35 +02:00
|
|
|
it 'raises RestClient::ResourceNotFound' do
|
2015-08-20 17:30:17 +02:00
|
|
|
expect { subject }.to raise_error(RestClient::ResourceNotFound)
|
2015-08-17 15:53:35 +02:00
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
2015-08-17 15:53:35 +02:00
|
|
|
context 'when siret exist' do
|
|
|
|
let(:siren) { '418166096' }
|
|
|
|
let(:status) { 200 }
|
|
|
|
let(:body) { File.read('spec/support/files/entreprise.json') }
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2015-08-17 15:53:35 +02:00
|
|
|
it 'returns response body' do
|
|
|
|
expect(subject).to eq(body)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2015-08-17 15:53:35 +02:00
|
|
|
describe '.etablissement' do
|
2015-08-20 17:30:17 +02:00
|
|
|
subject { described_class.etablissement(siret) }
|
2015-08-10 11:05:06 +02:00
|
|
|
before do
|
2015-08-20 17:30:17 +02:00
|
|
|
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}")
|
2015-11-16 11:23:29 +01:00
|
|
|
.to_return(status: status, body: body)
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
2015-08-17 15:53:35 +02:00
|
|
|
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)
|
2015-08-17 15:53:35 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when siret exists' do
|
|
|
|
let(:siret) { '41816609600051' }
|
|
|
|
let(:status) { 200 }
|
|
|
|
let(:body) { File.read('spec/support/files/etablissement.json') }
|
|
|
|
|
|
|
|
it 'returns body' do
|
|
|
|
expect(subject).to eq(body)
|
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
end
|
2015-11-16 11:23:29 +01:00
|
|
|
|
|
|
|
describe '.exercices' do
|
|
|
|
before do
|
|
|
|
stub_request(:get, /https:\/\/api-dev.apientreprise.fr\/api\/v1\/etablissements\/exercices\/.*token=/)
|
|
|
|
.to_return(status: status, body: body)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when siret does not exist' do
|
|
|
|
subject { described_class.exercices(siret) }
|
|
|
|
|
|
|
|
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) }
|
|
|
|
|
|
|
|
let(:siret) { '41816609600051' }
|
|
|
|
let(:status) { 200 }
|
|
|
|
let(:body) { File.read('spec/support/files/exercices.json') }
|
|
|
|
|
|
|
|
it 'raises RestClient::Unauthorized' do
|
|
|
|
expect(subject).to eq(body)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-08-20 17:30:17 +02:00
|
|
|
end
|