Merge pull request #10743 from demarches-simplifiees/fix-10742

ETQ instructeur mon adresse email est automatiquement vérifiée quand je me connecte par AgentConnect
This commit is contained in:
Mathieu Magnin 2024-09-06 14:26:54 +00:00 committed by GitHub
commit 71d43078ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View file

@ -31,7 +31,8 @@ class AgentConnect::AgentController < ApplicationController
instructeur = user.instructeur instructeur = user.instructeur
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