Display RNA information on partial dossier entreprise information

This commit is contained in:
Xavier J 2015-12-11 12:36:44 +01:00
parent 05298f7a40
commit a2a5d63c0d
9 changed files with 92 additions and 9 deletions

View file

@ -53,6 +53,7 @@ class Users::DossiersController < UsersController
@etablissement = Etablissement.new(SIADE::EtablissementAdapter.new(siret).to_params)
@entreprise = Entreprise.new(SIADE::EntrepriseAdapter.new(siren).to_params)
rna_information = SIADE::RNAAdapter.new(siret).to_params
exercices = SIADE::ExercicesAdapter.new(siret).to_params
unless exercices.nil?
@ -68,6 +69,12 @@ class Users::DossiersController < UsersController
@entreprise.dossier = @dossier
@entreprise.save
unless rna_information.nil?
rna_information = RNAInformation.new(rna_information)
rna_information.entreprise = @entreprise
rna_information.save
end
@etablissement.dossier = @dossier
@etablissement.entreprise = @entreprise
@etablissement.save

View file

@ -54,3 +54,6 @@
= "#{exercice.dateFinExercice.year} : "
= number_to_currency(exercice.ca)
%br
- unless @entreprise.rna_information.nil?
= render partial: '/dossiers/infos_rna'

View file

@ -0,0 +1,23 @@
.row#infos_rna
.col-lg-6.col-md-6
%dl.dl-horizontal
%dt Association ID :
%dd.text-success= @entreprise.rna_information.association_id
%dt Titre :
%dd= @entreprise.rna_information.titre
%dt Objet :
%dd= @entreprise.rna_information.objet
.col-lg-6.col-md-6
%dl.dl-horizontal
%dt Date création :
%dd= @entreprise.rna_information.date_creation
%dt Capital publication :
%dd= @entreprise.rna_information.date_publication
%dt Capital déclaration :
%dd= @entreprise.rna_information.date_declaration

View file

@ -4,7 +4,7 @@ class SIADE::RNAAdapter
end
def data_source
@data_source ||= JSON.parse(SIADE::API.rna(@siren), symbolize_names: true)
@data_source ||= JSON.parse(SIADE::API.rna(@siret), symbolize_names: true)
end
def to_params
@ -12,8 +12,15 @@ class SIADE::RNAAdapter
data_source[:association].each do |k, v|
params[k] = v if attr_to_fetch.include?(k)
end
params[:association_id] = params[:id]
params.delete(:id)
params
rescue
nil
end
def attr_to_fetch

View file

@ -9,6 +9,9 @@ describe Users::DossiersController, type: :controller do
let(:dossier_id) { dossier.id }
let(:siret_not_found) { 999_999_999_999 }
let(:rna_status) { 404 }
let(:rna_body) { '' }
let(:siren) { dossier.siren }
let(:siret) { dossier.siret }
let(:bad_siret) { 1 }
@ -76,9 +79,12 @@ describe Users::DossiersController, type: :controller do
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'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/associations/#{siret}?token=#{SIADETOKEN}")
.to_return(status: rna_status, body: rna_body)
end
describe 'professionnel fills form' do
describe 'dossier attributs' do
let(:user) { create(:user) }
context 'with valid siret ' do
before do
@ -87,7 +93,6 @@ describe Users::DossiersController, type: :controller do
subject { post :create, dossier: {siret: siret, procedure_id: Procedure.last} }
it 'create a dossier' do
expect { subject }.to change { Dossier.count }.by(1)
end
@ -134,6 +139,31 @@ describe Users::DossiersController, type: :controller do
subject
expect(Dossier.last.state).to eq('draft')
end
describe 'get rna informations' do
context 'when siren have not rna informations' do
let(:rna_status) { 404 }
let(:rna_body) { '' }
it 'not creates rna information for entreprise' do
expect { subject }.to change { RNAInformation.count }.by(0)
end
end
context 'when siren have rna informations' do
let(:rna_status) { 200 }
let(:rna_body) { File.read('spec/support/files/rna.json') }
it 'creates rna information for entreprise' do
expect { subject }.to change { RNAInformation.count }.by(1)
end
it 'links rna informations to entreprise' do
subject
expect(RNAInformation.last.entreprise).to eq(Entreprise.last)
end
end
end
end
context 'with non existant siret' do

View file

@ -34,6 +34,9 @@ feature 'user path for dossier creation' do
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'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/associations/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 404, body: '')
page.find_by_id('dossier_siret').set siret
page.click_on 'Commencer'
end

View file

@ -31,6 +31,9 @@ feature 'user arrive on siret page' do
.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'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/associations/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 404, body: '')
page.find_by_id('dossier_siret').set siret
page.click_on 'Commencer'
end

View file

@ -1,12 +1,21 @@
require 'spec_helper'
describe SIADE::RNAAdapter do
let(:siren) { '418166096' }
subject { described_class.new(siren).to_params }
let(:siret) { '50480511000013' }
let(:body) { File.read('spec/support/files/rna.json') }
let(:status) { 200 }
subject { described_class.new(siret).to_params }
before do
stub_request(:get, /https:\/\/api-dev.apientreprise.fr\/api\/v1\/associations\/.*token=/)
.to_return(body: File.read('spec/support/files/rna.json', status: 200))
.to_return(body: body, status: status)
end
context 'when siret is not valid' do
let(:siret) { '234567' }
let(:body) { '' }
let(:status) { '404' }
it { is_expected.to eq(nil) }
end
it '#to_params class est une Hash ?' do
@ -15,7 +24,7 @@ describe SIADE::RNAAdapter do
context 'Attributs Associations' do
it 'L\'associations contient bien un id' do
expect(subject[:id]).to eq('W595001988')
expect(subject[:association_id]).to eq('W595001988')
end
it 'L\'associations contient bien un titre' do

View file

@ -41,8 +41,6 @@ describe 'users/dossiers/new.html.haml', type: :view do
let(:logo) { File.new(File.join(::Rails.root.to_s, "/spec/support/files", "logo_test_procedure.png")) }
it 'Procedure logo is present' do
p subject
is_expected.to have_css("img[src='#{procedure.logo}']")
end
end