diff --git a/app/controllers/recoveries_controller.rb b/app/controllers/recoveries_controller.rb index d3b1f7368..696f27cd5 100644 --- a/app/controllers/recoveries_controller.rb +++ b/app/controllers/recoveries_controller.rb @@ -14,9 +14,14 @@ class RecoveriesController < ApplicationController end def identification + @structure_name = structure_name end def post_identification + # cookies are used to avoid leaking + # email in url + cookies[:recover_previous_email] = previous_email + redirect_to selection_recovery_path end @@ -39,6 +44,12 @@ class RecoveriesController < ApplicationController def siret = current_instructeur.agent_connect_information.siret def previous_email = params[:previous_email] + def structure_name + # we know that the structure exists because + # of the ensure_collectivite_territoriale guard + APIRechercheEntreprisesService.new.(siret:).value![:nom_complet] + end + def ensure_agent_connect_is_used if current_instructeur&.agent_connect_information.nil? redirect_to support_recovery_path(error: :must_use_agent_connect) diff --git a/app/views/recoveries/identification.html.haml b/app/views/recoveries/identification.html.haml index 7ba8c4153..5f449f47a 100644 --- a/app/views/recoveries/identification.html.haml +++ b/app/views/recoveries/identification.html.haml @@ -5,6 +5,7 @@ %h2 Identification du propriétaire des dossiers + %p Votre organisation est « #{@structure_name} » identifiée par le SIRET #{current_instructeur.agent_connect_information.siret} = form_with do |f| .fr-input-group %label.fr-label{ for: "email" } diff --git a/spec/controllers/recoveries_controller_spec.rb b/spec/controllers/recoveries_controller_spec.rb index 56b496626..c483bad72 100644 --- a/spec/controllers/recoveries_controller_spec.rb +++ b/spec/controllers/recoveries_controller_spec.rb @@ -1,4 +1,6 @@ describe RecoveriesController, type: :controller do + include Dry::Monads[:result] + describe 'GET #nature' do subject { get :nature } @@ -75,4 +77,32 @@ describe RecoveriesController, type: :controller do it { is_expected.to redirect_to(support_recovery_path(error: 'not_collectivite_territoriale')) } end end + + context 'when the current instructeur used agent connect and works for a collectivite territoriale' do + let(:instructeur) { create(:instructeur, :with_agent_connect_information) } + let(:api_recherche_result) do + { nom_complet: 'name', complements: { collectivite_territoriale: { is: :present } } } + end + + before do + allow(controller).to receive(:current_instructeur).and_return(instructeur) + allow_any_instance_of(APIRechercheEntreprisesService).to receive(:call) + .and_return(Success(api_recherche_result)) + end + + describe 'GET #identification' do + subject { get :identification } + + it { is_expected.to have_http_status(:success) } + end + + describe 'POST #post_identification' do + subject { post :post_identification, params: { previous_email: 'email@a.com' } } + + it do + is_expected.to redirect_to(selection_recovery_path) + expect(cookies[:recover_previous_email]).to eq('email@a.com') + end + end + end end