[#10742] Set email as verified when instructeur signs in with Agent Connect

This commit is contained in:
Mathieu Magnin 2024-09-03 19:03:12 +02:00 committed by Mathieu Magnin
parent 723ea310ba
commit 22473adec7
No known key found for this signature in database
GPG key ID: 8DCAFC82D7BA654E
2 changed files with 9 additions and 2 deletions

View file

@ -32,6 +32,7 @@ class AgentConnect::AgentController < ApplicationController
end 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 = 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')) aci.update(user_info.slice('given_name', 'usual_name', 'email', 'sub', 'siret', 'organizational_unit', 'belonging_population', 'phone'))

View file

@ -33,7 +33,7 @@ describe AgentConnect::AgentController, type: :controller do
context 'when the callback code is correct' do context 'when the callback code is correct' do
let(:code) { 'correct' } let(:code) { 'correct' }
let(:state) { original_state } 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 context 'and user_info returns some info' do
before do before do
@ -52,6 +52,7 @@ describe AgentConnect::AgentController, type: :controller do
expect(last_user.email).to eq(email) expect(last_user.email).to eq(email)
expect(last_user.confirmed_at).to be_present 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(last_user.instructeur.agent_connect_id_token).to eq('id_token')
expect(response).to redirect_to(instructeur_procedures_path) expect(response).to redirect_to(instructeur_procedures_path)
expect(state_cookie).to be_nil 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 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) expect { subject }.to change { User.count }.by(0).and change { Instructeur.count }.by(0)
instructeur.reload instructeur.reload
expect(instructeur.agent_connect_id_token).to eq('id_token') expect(instructeur.agent_connect_id_token).to eq('id_token')
expect(response).to redirect_to(instructeur_procedures_path) expect(response).to redirect_to(instructeur_procedures_path)
end end
it "sets email_verified_at" do
expect { subject }.to change { instructeur.user.reload.email_verified_at }.from(
nil
)
end
end end
context 'and the instructeur already has an account as a user' do context 'and the instructeur already has an account as a user' do