diff --git a/app/controllers/agent_connect/agent_controller.rb b/app/controllers/agent_connect/agent_controller.rb index e7374113b..346c19a8d 100644 --- a/app/controllers/agent_connect/agent_controller.rb +++ b/app/controllers/agent_connect/agent_controller.rb @@ -31,7 +31,8 @@ class AgentConnect::AgentController < ApplicationController instructeur = user.instructeur end - instructeur.update(agent_connect_id_token: id_token) + instructeur.update!(agent_connect_id_token: id_token) + instructeur.user.update!(email_verified_at: Time.zone.now) aci = AgentConnectInformation.find_or_initialize_by(instructeur:, sub: user_info['sub']) aci.update(user_info.slice('given_name', 'usual_name', 'email', 'sub', 'siret', 'organizational_unit', 'belonging_population', 'phone')) diff --git a/spec/controllers/agent_connect/agent_controller_spec.rb b/spec/controllers/agent_connect/agent_controller_spec.rb index 11fb9aaca..80a255d16 100644 --- a/spec/controllers/agent_connect/agent_controller_spec.rb +++ b/spec/controllers/agent_connect/agent_controller_spec.rb @@ -33,7 +33,7 @@ describe AgentConnect::AgentController, type: :controller do context 'when the callback code is correct' do let(:code) { 'correct' } let(:state) { original_state } - let(:user_info) { { 'sub' => 'sub', 'email' => ' I@email.com', 'given_name' => 'given', 'usual_name' => 'usual' } } + let(:user_info) { { 'sub' => 'sub', 'email' => email, 'given_name' => 'given', 'usual_name' => 'usual' } } context 'and user_info returns some info' do before do @@ -52,6 +52,7 @@ describe AgentConnect::AgentController, type: :controller do expect(last_user.email).to eq(email) expect(last_user.confirmed_at).to be_present + expect(last_user.email_verified_at).to be_present expect(last_user.instructeur.agent_connect_id_token).to eq('id_token') expect(response).to redirect_to(instructeur_procedures_path) expect(state_cookie).to be_nil @@ -68,12 +69,17 @@ describe AgentConnect::AgentController, type: :controller do it 'reuses the account, signs in and redirects to procedure_path' do expect { subject }.to change { User.count }.by(0).and change { Instructeur.count }.by(0) - instructeur.reload expect(instructeur.agent_connect_id_token).to eq('id_token') expect(response).to redirect_to(instructeur_procedures_path) end + + it "sets email_verified_at" do + expect { subject }.to change { instructeur.user.reload.email_verified_at }.from( + nil + ) + end end context 'and the instructeur already has an account as a user' do