From a2a5d63c0d1be465f9cf434e30c1a62eb3eb1eee Mon Sep 17 00:00:00 2001 From: Xavier J Date: Fri, 11 Dec 2015 12:36:44 +0100 Subject: [PATCH] Display RNA information on partial dossier entreprise information --- app/controllers/users/dossiers_controller.rb | 7 ++++ .../dossiers/_infos_entreprise.html.haml | 3 ++ app/views/dossiers/_infos_rna.html.haml | 23 +++++++++++++ lib/siade/rna_adapter.rb | 9 ++++- .../users/dossiers_controller_spec.rb | 34 +++++++++++++++++-- spec/features/users/complete_demande_spec.rb | 3 ++ spec/features/users/start_demande_spec.rb | 3 ++ spec/lib/siade/rna_adapter_spec.rb | 17 +++++++--- .../users/dossiers/new_html.haml_spec.rb | 2 -- 9 files changed, 92 insertions(+), 9 deletions(-) create mode 100644 app/views/dossiers/_infos_rna.html.haml diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 465d030cd..e389249a6 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -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 diff --git a/app/views/dossiers/_infos_entreprise.html.haml b/app/views/dossiers/_infos_entreprise.html.haml index fbf729ae9..4e6eaab81 100644 --- a/app/views/dossiers/_infos_entreprise.html.haml +++ b/app/views/dossiers/_infos_entreprise.html.haml @@ -54,3 +54,6 @@ = "#{exercice.dateFinExercice.year} : " = number_to_currency(exercice.ca) %br + +- unless @entreprise.rna_information.nil? + = render partial: '/dossiers/infos_rna' \ No newline at end of file diff --git a/app/views/dossiers/_infos_rna.html.haml b/app/views/dossiers/_infos_rna.html.haml new file mode 100644 index 000000000..ddcf74810 --- /dev/null +++ b/app/views/dossiers/_infos_rna.html.haml @@ -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 + diff --git a/lib/siade/rna_adapter.rb b/lib/siade/rna_adapter.rb index 6de06896f..242fd725d 100644 --- a/lib/siade/rna_adapter.rb +++ b/lib/siade/rna_adapter.rb @@ -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 diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 2cf734c9c..91cd025af 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -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 diff --git a/spec/features/users/complete_demande_spec.rb b/spec/features/users/complete_demande_spec.rb index d17080cba..b67272a26 100644 --- a/spec/features/users/complete_demande_spec.rb +++ b/spec/features/users/complete_demande_spec.rb @@ -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 diff --git a/spec/features/users/start_demande_spec.rb b/spec/features/users/start_demande_spec.rb index 6e8aeedc3..0393c6339 100644 --- a/spec/features/users/start_demande_spec.rb +++ b/spec/features/users/start_demande_spec.rb @@ -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 diff --git a/spec/lib/siade/rna_adapter_spec.rb b/spec/lib/siade/rna_adapter_spec.rb index d46e040a8..dfbaf8d19 100644 --- a/spec/lib/siade/rna_adapter_spec.rb +++ b/spec/lib/siade/rna_adapter_spec.rb @@ -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 diff --git a/spec/views/users/dossiers/new_html.haml_spec.rb b/spec/views/users/dossiers/new_html.haml_spec.rb index 04f228de6..2d0193f82 100644 --- a/spec/views/users/dossiers/new_html.haml_spec.rb +++ b/spec/views/users/dossiers/new_html.haml_spec.rb @@ -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