feat(registration): set preferred host on signup/signin

This commit is contained in:
Colin Darie 2024-03-20 12:56:11 +01:00
parent 41a02d1ead
commit f768801b7d
No known key found for this signature in database
GPG key ID: 8C76CADD40253590
4 changed files with 22 additions and 1 deletions

View file

@ -39,7 +39,9 @@ class Users::RegistrationsController < Devise::RegistrationsController
return redirect_to after_inactive_sign_up_path_for(existing_user)
end
super
super do
resource.update_preferred_domain(Current.host) if resource.valid?
end
end
# GET /resource/edit

View file

@ -13,6 +13,7 @@ class Users::SessionsController < Devise::SessionsController
if user&.valid_password?(params[:user][:password])
user.update(loged_in_with_france_connect: nil)
user.update_preferred_domain(Current.host)
end
super

View file

@ -42,6 +42,10 @@ describe Users::RegistrationsController, type: :controller do
post :create, params: { user: user }
end
before do
allow(Current).to receive(:host).and_return(ENV.fetch("APP_HOST"))
end
context 'when user is correct' do
it 'sends confirmation instruction' do
message = double()
@ -49,6 +53,8 @@ describe Users::RegistrationsController, type: :controller do
expect(message).to receive(:deliver_later)
subject
expect(User.last.preferred_domain_demarches_gouv_fr?).to be_truthy
end
end

View file

@ -65,6 +65,18 @@ describe Users::SessionsController, type: :controller do
expect(flash.alert).to eq("Adresse électronique ou mot de passe incorrect.")
end
end
context 'when user has not yet a preferred domain' do
before do
allow(Current).to receive(:host).and_return(ENV.fetch("APP_HOST"))
end
it 'update preferred domain' do
subject
expect(user.reload.preferred_domain_demarches_gouv_fr?).to be_truthy
end
end
end
context 'when the credentials are wrong' do