feat(file retrieval): ensure collectivite territoriale

This commit is contained in:
simon lehericey 2023-12-19 16:25:41 +01:00
parent fac365e01d
commit d86bebdd03
3 changed files with 41 additions and 1 deletions

View file

@ -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

View file

@ -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,

View file

@ -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