From d86bebdd03dc16948e8911882cc767e2e0540e9b Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 19 Dec 2023 16:25:41 +0100 Subject: [PATCH] feat(file retrieval): ensure collectivite territoriale --- app/controllers/recoveries_controller.rb | 9 ++++++ app/views/recoveries/support.html.haml | 2 +- .../controllers/recoveries_controller_spec.rb | 31 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/app/controllers/recoveries_controller.rb b/app/controllers/recoveries_controller.rb index 5fbc0ffb4..d3b1f7368 100644 --- a/app/controllers/recoveries_controller.rb +++ b/app/controllers/recoveries_controller.rb @@ -1,5 +1,6 @@ class RecoveriesController < ApplicationController before_action :ensure_agent_connect_is_used, except: [:nature, :post_nature, :support] + before_action :ensure_collectivite_territoriale, except: [:nature, :post_nature, :support] def nature end @@ -35,10 +36,18 @@ class RecoveriesController < ApplicationController private def nature_params = params[:nature] + def siret = current_instructeur.agent_connect_information.siret + def previous_email = params[:previous_email] def ensure_agent_connect_is_used if current_instructeur&.agent_connect_information.nil? redirect_to support_recovery_path(error: :must_use_agent_connect) end end + + def ensure_collectivite_territoriale + if !APIRechercheEntreprisesService.collectivite_territoriale?(siret:) + redirect_to support_recovery_path(error: 'not_collectivite_territoriale') + end + end end diff --git a/app/views/recoveries/support.html.haml b/app/views/recoveries/support.html.haml index e196e8ab9..d09f46d2b 100644 --- a/app/views/recoveries/support.html.haml +++ b/app/views/recoveries/support.html.haml @@ -4,7 +4,7 @@ %h1.fr-h1 Récupération de dossiers - case params[:error] - - when 'other_nature' + - when 'other_nature', 'not_collectivite_territoriale' %p Votre situation nécessite un traitement particulier. = mail_to(CONTACT_EMAIL, diff --git a/spec/controllers/recoveries_controller_spec.rb b/spec/controllers/recoveries_controller_spec.rb index 2301805fb..56b496626 100644 --- a/spec/controllers/recoveries_controller_spec.rb +++ b/spec/controllers/recoveries_controller_spec.rb @@ -30,6 +30,11 @@ describe RecoveriesController, type: :controller do describe 'ensure_agent_connect_is_used' do subject { post :selection } + before do + allow(controller).to receive(:ensure_collectivite_territoriale).and_return(true) + allow(controller).to receive(:selection).and_return(true) + end + context 'when agent connect is used' do let(:instructeur) { create(:instructeur, :with_agent_connect_information) } @@ -44,4 +49,30 @@ describe RecoveriesController, type: :controller do it { is_expected.to redirect_to(support_recovery_path(error: :must_use_agent_connect)) } end end + + describe 'ensure_collectivite_territoriale' do + subject { post :selection } + + before do + allow(controller).to receive(:ensure_agent_connect_is_used).and_return(true) + allow(controller).to receive(:siret).and_return('123') + allow(controller).to receive(:selection).and_return(true) + end + + context 'when collectivite territoriale' do + before do + allow(APIRechercheEntreprisesService).to receive(:collectivite_territoriale?).and_return(true) + end + + it { is_expected.to have_http_status(:success) } + end + + context 'when not collectivite territoriale' do + before do + allow(APIRechercheEntreprisesService).to receive(:collectivite_territoriale?).and_return(false) + end + + it { is_expected.to redirect_to(support_recovery_path(error: 'not_collectivite_territoriale')) } + end + end end