Add on information entreprise :

- SIRET Siège social
	- Code naf
	- Code effectif
	- Numéro TVA intracommunautaire
	- Exercices
This commit is contained in:
Xavier J 2015-11-16 11:23:29 +01:00
parent 803ca14f72
commit dd8bafab49
18 changed files with 233 additions and 21 deletions

View file

@ -53,6 +53,9 @@ describe Users::DossiersController, type: :controller do
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/exercices/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/exercices.json'))
end
describe 'professionnel fills form' do
@ -98,6 +101,10 @@ describe Users::DossiersController, type: :controller do
expect(Etablissement.last.entreprise).to eq(Entreprise.last)
end
it 'creates exercices for dossier' do
expect { subject }.to change { Exercice.count }.by(3)
end
it 'links procedure to dossier' do
subject
expect(Dossier.last.procedure).to eq(Procedure.last)

View file

@ -7,11 +7,11 @@ describe EntrepriseDecorator do
let(:prenom) { 'mon prenom' }
let(:entreprise_params) do
{
capital_social: 123_000,
code_effectif_entreprise: code_effectif,
raison_sociale: raison_sociale,
nom: nom,
prenom: prenom
capital_social: 123_000,
code_effectif_entreprise: code_effectif,
raison_sociale: raison_sociale,
nom: nom,
prenom: prenom
}
end
@ -47,7 +47,7 @@ describe EntrepriseDecorator do
describe '#pretty_capital_social' do
it 'pretty display capital_social' do
expect(subject.pretty_capital_social).to eq('123 000.00 €')
expect(subject.pretty_capital_social).to eq('123 000,00 €')
end
end

View file

@ -28,9 +28,12 @@ feature 'user path for dossier creation' do
context 'sets siret' do
before do
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}")
.to_return(body: File.read('spec/support/files/etablissement.json', status: 200))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
.to_return(body: File.read('spec/support/files/etablissement.json', status: 200))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/exercices/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/exercices.json'))
page.find_by_id('siret').set siret
page.click_on 'Commencer'
end

View file

@ -26,9 +26,11 @@ feature 'user arrive on siret page' do
context 'when enter a siret' do
before do
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/etablissement.json'))
.to_return(status: 200, body: File.read('spec/support/files/etablissement.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/exercices/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/exercices.json'))
page.find_by_id('siret').set siret
page.click_on 'Commencer'
end

View file

@ -5,7 +5,7 @@ describe SIADE::API do
subject { described_class.entreprise(siren) }
before do
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}")
.to_return(status: status, body: body)
.to_return(status: status, body: body)
end
context 'when siren does not exist' do
let(:siren) { '111111111' }
@ -31,7 +31,7 @@ describe SIADE::API do
subject { described_class.etablissement(siret) }
before do
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}")
.to_return(status: status, body: body)
.to_return(status: status, body: body)
end
context 'when siret does not exist' do
@ -54,4 +54,35 @@ describe SIADE::API do
end
end
end
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
end

View file

@ -0,0 +1,33 @@
require 'spec_helper'
describe SIADE::ExercicesAdapter do
let(:siret) { '41816609600051' }
subject { described_class.new(siret).to_params }
before do
stub_request(:get, /https:\/\/api-dev.apientreprise.fr\/api\/v1\/etablissements\/exercices\/.*token=/)
.to_return(body: File.read('spec/support/files/exercices.json', status: 200))
end
it '#to_params class est une Hash ?' do
expect(subject).to be_an_instance_of(Hash)
end
it 'have 3 exercices' do
expect(subject.size).to eq(3)
end
context 'Attributs Exercices' do
it 'L\'exercice contient bien un ca' do
expect(subject[0][:ca]).to eq('21009417')
end
it 'L\'exercice contient bien une date de fin d\'exercice' do
expect(subject[0][:dateFinExercice]).to eq("2013-12-31T00:00:00+01:00")
end
it 'L\'exercice contient bien une date_fin_exercice_timestamp' do
expect(subject[0][:date_fin_exercice_timestamp]).to eq(1388444400)
end
end
end

View file

@ -19,5 +19,6 @@ describe Etablissement do
describe 'associations' do
it { is_expected.to belong_to(:dossier) }
it { is_expected.to belong_to(:entreprise) }
it { is_expected.to have_many(:exercices) }
end
end

View file

@ -0,0 +1,13 @@
require 'spec_helper'
describe Exercice do
describe 'database columns' do
it { is_expected.to have_db_column(:ca) }
it { is_expected.to have_db_column(:dateFinExercice) }
it { is_expected.to have_db_column(:date_fin_exercice_timestamp) }
end
describe 'associations' do
it { is_expected.to belong_to(:etablissement) }
end
end

View file

@ -0,0 +1,19 @@
{
"exercices":[
{
"ca":"21009417",
"dateFinExercice":"2013-12-31T00:00:00+01:00",
"date_fin_exercice_timestamp": 1388444400
},
{
"ca":"18968298",
"dateFinExercice":"2012-12-31T00:00:00+01:00",
"date_fin_exercice_timestamp": 1356908400
},
{
"ca":"17768838",
"dateFinExercice":"2011-12-31T00:00:00+01:00",
"date_fin_exercice_timestamp": 1325286000
}
]
}