Feat(user): set email_verified_at when setting confirmed_at

This commit is contained in:
simon lehericey 2024-05-27 10:01:14 +02:00
parent 841c1cc845
commit fa06d17169
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
4 changed files with 19 additions and 3 deletions

View file

@ -99,7 +99,7 @@ class User < ApplicationRecord
def self.create_or_promote_to_instructeur(email, password, administrateurs: [])
user = User
.create_with(password: password, confirmed_at: Time.zone.now)
.create_with(password: password, confirmed_at: Time.zone.now, email_verified_at: Time.zone.now)
.find_or_create_by(email: email)
if user.valid?
@ -138,7 +138,7 @@ class User < ApplicationRecord
def self.create_or_promote_to_expert(email, password)
user = User
.create_with(password: password, confirmed_at: Time.zone.now)
.create_with(password: password, confirmed_at: Time.zone.now, email_verified_at: Time.zone.now)
.find_or_create_by(email: email)
if user.valid?

View file

@ -13,7 +13,8 @@ SuperAdmin.create!(email: default_user, password: default_password)
user = User.create!(
email: default_user,
password: default_password,
confirmed_at: Time.zone.now
confirmed_at: Time.zone.now,
email_verified_at: Time.zone.now
)
user.create_instructeur!
user.create_administrateur!

View file

@ -19,6 +19,7 @@ describe FranceConnectInformation, type: :model do
it do
subject
expect(fci.user.email).to eq('a@email.com')
expect(fci.user.email_verified_at).to be_present
end
end
end

View file

@ -117,6 +117,7 @@ describe User, type: :model do
user = subject
expect(user.valid_password?(password)).to be true
expect(user.confirmed_at).to be_present
expect(user.email_verified_at).to be_present
expect(user.instructeur).to be_present
end
@ -190,6 +191,7 @@ describe User, type: :model do
user = subject
expect(user.valid_password?(password)).to be true
expect(user.confirmed_at).to be_present
expect(user.email_verified_at).to be_present
expect(user.expert).to be_present
end
end
@ -220,6 +222,18 @@ describe User, type: :model do
end
end
describe '.create_or_promote_to_gestionnaire' do
let(:email) { 'inst1@gmail.com' }
let(:password) { 'un super password !' }
subject { User.create_or_promote_to_gestionnaire(email, password) }
it 'verifies its email' do
user = subject
expect(user.email_verified_at).to be_present
end
end
describe 'invite_administrateur!' do
let(:super_admin) { create(:super_admin) }
let(:administrateur) { create(:administrateur) }