Check if starter informations and autorisations_donnees is valid on description dossier page
This commit is contained in:
parent
b03dd07d97
commit
e596f71b07
3 changed files with 74 additions and 5 deletions
|
@ -3,8 +3,11 @@ class Users::DescriptionController < UsersController
|
|||
authorized_routes? self.class
|
||||
end
|
||||
|
||||
before_action :check_autorisation_donnees, only: [:show]
|
||||
before_action :check_starter_dossier_informations, only: [:show]
|
||||
|
||||
def show
|
||||
@dossier = current_user_dossier.decorate
|
||||
@dossier ||= current_user_dossier.decorate
|
||||
|
||||
@procedure = @dossier.procedure
|
||||
@champs = @dossier.ordered_champs
|
||||
|
@ -99,6 +102,21 @@ class Users::DescriptionController < UsersController
|
|||
|
||||
private
|
||||
|
||||
def check_autorisation_donnees
|
||||
@dossier ||= current_user_dossier
|
||||
|
||||
redirect_to url_for(users_dossier_path(@dossier.id)) if @dossier.autorisation_donnees.nil? || !@dossier.autorisation_donnees
|
||||
end
|
||||
|
||||
def check_starter_dossier_informations
|
||||
@dossier ||= current_user_dossier
|
||||
|
||||
if (@dossier.procedure.for_individual? && @dossier.individual.nil?) ||
|
||||
(!@dossier.procedure.for_individual? && @dossier.entreprise.nil?)
|
||||
redirect_to url_for(users_dossier_path(@dossier.id))
|
||||
end
|
||||
end
|
||||
|
||||
def create_params
|
||||
params.permit()
|
||||
end
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
shared_examples 'description_controller_spec' do
|
||||
describe 'GET #show' do
|
||||
before do
|
||||
dossier.update_column :autorisation_donnees, true
|
||||
end
|
||||
context 'user is not connected' do
|
||||
before do
|
||||
sign_out dossier.user
|
||||
|
@ -11,9 +14,15 @@ shared_examples 'description_controller_spec' do
|
|||
end
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
get :show, dossier_id: dossier_id
|
||||
expect(response).to have_http_status(:success)
|
||||
context 'when all is ok' do
|
||||
before do
|
||||
dossier.entreprise = create :entreprise
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
get :show, dossier_id: dossier_id
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
|
||||
it 'redirection vers start si mauvais dossier ID' do
|
||||
|
@ -35,6 +44,48 @@ shared_examples 'description_controller_spec' do
|
|||
it { is_expected.to redirect_to root_path }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'before action check_autorisation_donnees' do
|
||||
subject { get :show, dossier_id: dossier_id }
|
||||
|
||||
context 'when dossier does not have a valid autorisations_donness (nil)' do
|
||||
before do
|
||||
dossier.update_column :autorisation_donnees, nil
|
||||
end
|
||||
|
||||
it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
|
||||
end
|
||||
|
||||
context 'when dossier does not have a valid autorisations_donness (false)' do
|
||||
before do
|
||||
dossier.update_column :autorisation_donnees, false
|
||||
end
|
||||
|
||||
it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'before action check_starter_dossier_informations' do
|
||||
subject { get :show, dossier_id: dossier_id }
|
||||
|
||||
context 'when dossier does not have an enterprise datas' do
|
||||
before do
|
||||
|
||||
end
|
||||
|
||||
it { expect(dossier.entreprise).to be_nil }
|
||||
it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
|
||||
end
|
||||
|
||||
context 'when dossier does not have an individual datas' do
|
||||
before do
|
||||
procedure.update_column :for_individual, true
|
||||
end
|
||||
|
||||
it { expect(dossier.individual).to be_nil }
|
||||
it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
feature 'user is on description page' do
|
||||
let!(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, cerfa_flag: true) }
|
||||
let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure) }
|
||||
let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, autorisation_donnees: true) }
|
||||
|
||||
before do
|
||||
allow(ClamavService).to receive(:safe_file?).and_return(true)
|
||||
|
|
Loading…
Reference in a new issue