- Code review

- Delete Mandataires sociaux adapter
- Add function to get mandataires sociaux in Enterprise Adapter
This commit is contained in:
Xavier J 2016-01-19 17:19:38 +01:00
parent e0d980e804
commit e8fd212d13
14 changed files with 121 additions and 138 deletions

View file

@ -11,7 +11,6 @@ class Admin::ProceduresController < AdminController
partial: "admin/procedures/list",
array: true
@page = 'active'
active_class
end
@ -21,7 +20,6 @@ class Admin::ProceduresController < AdminController
partial: "admin/procedures/list",
array: true
@page = 'archived'
archived_class
render 'index'
@ -78,11 +76,11 @@ class Admin::ProceduresController < AdminController
end
def active_class
@active_class = 'active' if @page == 'active'
@active_class = 'active'
end
def archived_class
@archived_class = 'active' if @page == 'archived'
@archived_class = 'active'
end
private

View file

@ -33,20 +33,21 @@ class FranceConnect::ParticulierController < ApplicationController
end
def check_email
return create if User.find_by_email(params[:user][:email]).nil?
user = User.find_by_email(params[:user][:email])
return create if user.nil?
return redirect_to root_path if france_connect_particulier_id_blank?
unless params[:user][:password].nil?
user = User.find_by_email(params[:user][:email])
valid_password = user.valid_password?(params[:user][:password])
if valid_password
if user.valid_password?(params[:user][:password])
user.update_attributes create_user_params
return connect_france_connect_particulier user
else
flash.now.alert = 'Mot de passe invalide'
end
end
@user = (User.new create_user_params).decorate
end

View file

@ -37,43 +37,31 @@ class Users::DossiersController < UsersController
end
def create
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
mandataires_sociaux = SIADE::MandatairesSociauxAdapter.new(siren).to_params
entreprise_adapter = SIADE::EntrepriseAdapter.new(siren)
dossier = Dossier.create(user: current_user,
state: 'draft',
procedure_id: create_params[:procedure_id],
mandataire_social: mandataire_social?(entreprise_adapter.mandataires_sociaux))
entreprise = Entreprise.create entreprise_adapter.to_params
.merge({dossier_id: dossier.id})
etablissement = Etablissement.create SIADE::EtablissementAdapter.new(siret).to_params
.merge({dossier_id: dossier.id,
entreprise_id: entreprise.id})
rna_information = SIADE::RNAAdapter.new(siret).to_params
unless rna_information.nil?
RNAInformation.create rna_information.merge({entreprise_id: entreprise.id})
end
exercices = SIADE::ExercicesAdapter.new(siret).to_params
unless exercices.nil?
exercices.each_value do |exercice|
exercice = Exercice.new(exercice)
exercice.etablissement = etablissement
exercice.save
Exercice.create(exercice.merge({etablissement_id: etablissement.id}))
end
end
mandataire_social = false
mandataires_sociaux.each do |k, mandataire|
break mandataire_social = true if !current_user.france_connect_particulier_id.nil? &&
mandataire[:nom] == current_user.family_name &&
mandataire[:prenom] == current_user.given_name &&
mandataire[:date_naissance_timestamp] == current_user.birthdate.to_time.to_i
end
dossier = Dossier.create(user: current_user, state: 'draft', procedure_id: create_params[:procedure_id], mandataire_social: mandataire_social)
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
redirect_to url_for(controller: :dossiers, action: :show, id: dossier.id)
@ -177,4 +165,17 @@ class Users::DossiersController < UsersController
redirect_to url_for users_dossiers_path
end
def mandataire_social? mandataires_list
mandataire_social = false
mandataires_list.each do |mandataire|
break mandataire_social = true if !current_user.france_connect_particulier_id.nil? &&
mandataire[:nom].upcase == current_user.family_name.upcase &&
mandataire[:prenom].upcase == current_user.given_name.upcase &&
mandataire[:date_naissance_timestamp] == current_user.birthdate.to_time.to_i
end
mandataire_social
end
end

View file

@ -5,6 +5,6 @@ class Etablissement < ActiveRecord::Base
has_many :exercices
def geo_adresse
numero_voie.to_s << ' ' << type_voie.to_s << ' ' << nom_voie.to_s << ' ' << complement_adresse.to_s << ' ' << code_postal.to_s << ' ' << localite.to_s
[numero_voie, type_voie, nom_voie, complement_adresse, code_postal, localite].join(' ')
end
end

View file

@ -7,7 +7,7 @@
%br
%p
%h4.center Nous vous avons trouvé un compte qui utilise déjà cette adresse email.
%h4.center Nous avons trouvé un compte qui utilise déjà cette adresse email.
%p.center
Afin d'associer ce compte à votre identifiant France Connect, merci de saisir votre mot de passe TPS.
%br
@ -15,7 +15,7 @@
#france_connect_particulier_email
= form_for @user, url: {controller: 'france_connect/particulier', action: :check_email}, method: :post do |f|
.form-group.form-group-lg
= f.text_field :email, class: "form-control", placeholder: "Entrez votre email", readonly: 'readonly'
= f.text_field :email, class: "form-control", readonly: 'readonly'
%br
= f.password_field :password, class: "form-control", placeholder: "Entrez votre mot de passe"
= f.hidden_field :email

View file

@ -34,4 +34,10 @@ class SIADE::EntrepriseAdapter
:nom,
:prenom]
end
def mandataires_sociaux
data_source[:entreprise][:mandataires_sociaux]
rescue
nil
end
end

View file

@ -1,35 +0,0 @@
class SIADE::MandatairesSociauxAdapter
def initialize(siren)
@siren = siren
end
def data_source
@data_source ||= JSON.parse(SIADE::API.entreprise(@siren), symbolize_names: true)
rescue
@data_source = nil
end
def to_params
params = {}
data_source[:entreprise][:mandataires_sociaux].each_with_index do |mandataire, i|
params[i] = {}
mandataire.each do |k, v|
params[i][k] = v if attr_to_fetch.include?(k)
end
end
params
rescue
nil
end
def attr_to_fetch
[:nom,
:prenom,
:fonction,
:date_naissance,
:date_naissance_timestamp]
end
end

View file

@ -81,28 +81,20 @@ describe FranceConnect::ParticulierController, type: :controller do
end
describe 'POST #create' do
let(:email) { 'plop@gmail.com' }
subject { post :create, user: user_info }
context 'when email is filled' do
it { expect { subject }.to change { User.count }.by(1) }
let(:email) { 'plop@gmail.com' }
it 'redirects user root page' do
subject
expect(response).to redirect_to(root_path)
end
it { expect { subject }.to change { User.count }.by(1) }
it { expect(subject).to redirect_to(root_path) }
end
context 'when email is incorrect' do
let(:email) { '' }
it { expect { subject }.to change { User.count }.by(0) }
it 'redirect to check email FC page' do
subject
expect(response).to redirect_to(france_connect_particulier_new_path(user: user_info))
end
it { expect(subject).to redirect_to(france_connect_particulier_new_path(user: user_info)) }
end
end

View file

@ -17,7 +17,7 @@ describe Users::RegistrationsController, type: :controller do
context 'when user is correct' do
it { expect(described_class).to be < Devise::RegistrationsController }
it 'welcome email is send' do
it 'sends welcome email' do
expect(WelcomeMailer).to receive(:welcome_email).and_return(WelcomeMailer)
expect(WelcomeMailer).to receive(:deliver_now!)
@ -28,7 +28,7 @@ describe Users::RegistrationsController, type: :controller do
context 'when user is not correct' do
let(:user) { {email: '', password: password, password_confirmation: password} }
it 'welcome email is not send' do
it 'not sends welcome email' do
expect(WelcomeMailer).not_to receive(:welcome_email)
subject

View file

@ -12,7 +12,13 @@ feature 'France Connect Particulier Connexion' do
let(:know_france_connect_particulier_id) { 'blabla' }
let(:unknow_france_connect_particulier_id) { 'titi' }
let(:user_info) { Hashie::Mash.new(france_connect_particulier_id: france_connect_particulier_id, given_name: given_name, family_name: family_name, birthdate: birthdate, birthplace: birthplace, gender: gender, email: email) }
let(:user_info) { Hashie::Mash.new(france_connect_particulier_id: france_connect_particulier_id,
given_name: given_name,
family_name: family_name,
birthdate: birthdate,
birthplace: birthplace,
gender: gender,
email: email) }
context 'when user is on login page' do
@ -28,7 +34,13 @@ feature 'France Connect Particulier Connexion' do
let(:code) { 'plop' }
context 'when authentification is ok' do
let!(:user) { create(:user, france_connect_particulier_id: know_france_connect_particulier_id, given_name: given_name, family_name: family_name, birthdate: birthdate, birthplace: birthplace, gender: gender) }
let!(:user) { create(:user,
france_connect_particulier_id: know_france_connect_particulier_id,
given_name: given_name,
family_name: family_name,
birthdate: birthdate,
birthplace: birthplace,
gender: gender) }
before do
allow_any_instance_of(FranceConnectParticulierClient).to receive(:authorization_uri).and_return(france_connect_particulier_callback_path(code: code))

View file

@ -5,7 +5,7 @@ describe SIADE::EntrepriseAdapter do
before do
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/418166096?token=#{SIADETOKEN}")
.to_return(body: File.read('spec/support/files/entreprise.json', status: 200))
.to_return(body: File.read('spec/support/files/entreprise.json', status: 200))
end
it '#to_params class est une Hash ?' do
@ -61,4 +61,35 @@ describe SIADE::EntrepriseAdapter do
expect(subject[:prenom]).to eq('test_prenom')
end
end
context 'Mandataire sociaux' do
subject { described_class.new('418166096').mandataires_sociaux }
it '#to_params class est une Hash ?' do
expect(subject).to be_an_instance_of(Array)
end
it { expect(subject.size).to eq(8) }
describe 'Attributs' do
it 'Un mandataire social possède bien un nom' do
expect(subject[0][:nom]).to eq('HISQUIN')
end
it 'Un mandataire social possède bien un prenom' do
expect(subject[0][:prenom]).to eq('FRANCOIS')
end
it 'Un mandataire social possède bien une fonction' do
expect(subject[0][:fonction]).to eq('PRESIDENT DU DIRECTOIRE')
end
it 'Un mandataire social possède bien une date de naissance' do
expect(subject[0][:date_naissance]).to eq('1965-01-27')
end
it 'Un mandataire social possède bien une date de naissance au format timestamp' do
expect(subject[0][:date_naissance_timestamp]).to eq(-155523600)
end
end
end
end

View file

@ -1,43 +0,0 @@
require 'spec_helper'
describe SIADE::MandatairesSociauxAdapter do
subject { described_class.new('418166096').to_params }
before do
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/418166096?token=#{SIADETOKEN}")
.to_return(body: File.read('spec/support/files/entreprise.json', status: 200))
end
it '#to_params class est une Hash ?' do
expect(subject).to be_an_instance_of(Hash)
end
describe 'Mandataires Sociaux' do
it { expect(subject.size).to eq(8) }
describe 'Attributs' do
it 'Un mandataire social possède bien un nom' do
expect(subject[0][:nom]).to eq('HISQUIN')
end
it 'Un mandataire social possède bien un prenom' do
expect(subject[0][:prenom]).to eq('FRANCOIS')
end
it 'Un mandataire social possède bien une fonction' do
expect(subject[0][:fonction]).to eq('PRESIDENT DU DIRECTOIRE')
end
it 'Un mandataire social possède bien une date de naissance' do
expect(subject[0][:date_naissance]).to eq('1965-01-27')
end
it 'Un mandataire social possède bien une date de naissance au format timestamp' do
expect(subject[0][:date_naissance_timestamp]).to eq(-155523600)
end
end
end
end

View file

@ -21,4 +21,13 @@ describe Etablissement do
it { is_expected.to belong_to(:entreprise) }
it { is_expected.to have_many(:exercices) }
end
describe '#geo_adresse' do
let(:etablissement) { create(:etablissement) }
subject { etablissement.geo_adresse }
it { is_expected.to eq '6 RUE RAOUL NORDLING IMMEUBLE BORA 92270 BOIS COLOMBES' }
end
end

View file

@ -5,6 +5,7 @@ describe 'users/dossiers/index.html.haml', type: :view do
let!(:dossier) { create(:dossier, :with_procedure, user: user, state: 'initiated', nom_projet: 'projet de test').decorate }
let!(:dossier_2) { create(:dossier, :with_procedure, user: user, state: 'replied', nom_projet: 'projet répondu').decorate }
let!(:dossier_3) { create(:dossier, :with_procedure, user: user, state: 'replied', nom_projet: 'projet répondu 2').decorate }
let!(:dossier_termine) { create(:dossier, :with_procedure, user: user, state: 'closed').decorate }
describe 'params liste is a_traiter' do
@ -18,6 +19,10 @@ describe 'users/dossiers/index.html.haml', type: :view do
partial: "users/dossiers/list",
array: true))
assign(:liste, 'a_traiter')
assign(:dossiers_a_traiter_total, '1')
assign(:dossiers_en_attente_total, '2')
assign(:dossiers_termine_total, '1')
render
end
@ -36,6 +41,12 @@ describe 'users/dossiers/index.html.haml', type: :view do
it { is_expected.not_to have_content(dossier.nom_projet) }
it { is_expected.not_to have_content(dossier_termine.nom_projet) }
end
describe 'badges on tabs' do
it { is_expected.to have_content('À traiter 1') }
it { is_expected.to have_content('En attente 2') }
it { is_expected.to have_content('Terminé 1') }
end
end
describe 'params liste is en_attente' do