2024-04-29 00:17:15 +02:00
# frozen_string_literal: true
2021-10-26 11:44:53 +02:00
describe 'Signin in:' do
2019-01-08 08:20:49 +01:00
let! ( :user ) { create ( :user , password : password ) }
2023-03-03 14:16:15 +01:00
let ( :password ) { SECURE_PASSWORD }
2019-01-08 08:20:49 +01:00
scenario 'an existing user can sign-in' do
visit root_path
2022-10-05 16:38:49 +02:00
click_on 'Se connecter' , match : :first
2019-01-08 08:20:49 +01:00
2021-04-15 17:14:50 +02:00
sign_in_with user . email , 'invalid-password'
2023-06-28 10:24:37 +02:00
expect ( page ) . to have_content 'Adresse électronique ou mot de passe incorrect.'
expect ( page ) . to have_field ( 'Adresse électronique' , with : user . email )
2019-01-08 08:20:49 +01:00
2021-04-15 17:14:50 +02:00
sign_in_with user . email , password
2019-01-08 08:20:49 +01:00
expect ( page ) . to have_current_path dossiers_path
2023-12-19 10:25:10 +01:00
expect ( page ) . to have_content ( 'Connecté(e).' )
expect ( page ) . not_to have_content ( 'Vous pouvez à tout moment alterner' )
end
context 'user has multiple profiles' do
let! ( :instructeur ) { create ( :instructeur , user : user ) }
let! ( :admin ) { create ( :administrateur , user : user , instructeur : instructeur ) }
scenario 'he can sign-in and he is notified in flash' do
visit root_path
click_on 'Se connecter' , match : :first
sign_in_with user . email , password
expect ( page ) . to have_current_path admin_procedures_path
expect ( page ) . to have_content ( 'Vous êtes connecté(e) ! Vous pouvez à tout moment alterner entre vos différents profils : administrateur, instructeur, usager.' )
end
2019-01-08 08:20:49 +01:00
end
2019-08-16 14:17:39 +02:00
scenario 'an existing user can lock its account' do
visit root_path
2022-10-05 16:38:49 +02:00
click_on 'Se connecter' , match : :first
2019-08-16 14:17:39 +02:00
5 . times { sign_in_with user . email , 'bad password' }
expect ( user . reload . access_locked? ) . to be false
sign_in_with user . email , 'bad password'
expect ( user . reload . access_locked? ) . to be true
end
2019-01-08 08:20:49 +01:00
context 'when visiting a procedure' do
let ( :procedure ) { create :simple_procedure , :with_service }
before do
visit commencer_path ( path : procedure . path )
end
scenario 'an existing user can sign-in and fill the procedure' do
2019-01-16 11:57:58 +01:00
click_on 'J’ ai déjà un compte'
2019-01-08 08:20:49 +01:00
expect ( page ) . to have_current_path new_user_session_path
sign_in_with user . email , password
2019-01-16 16:16:15 +01:00
expect ( page ) . to have_current_path ( commencer_path ( path : procedure . path ) )
click_on 'Commencer la démarche'
2019-01-08 08:20:49 +01:00
expect ( page ) . to have_current_path identite_dossier_path ( user . reload . dossiers . last )
2023-05-25 15:19:55 +02:00
expect ( page ) . to have_content ( procedure . libelle )
2023-11-23 16:38:01 +01:00
expect ( page ) . to have_content " Votre identité "
2019-01-08 08:20:49 +01:00
end
end
context 'when a user is not confirmed yet' do
let! ( :user ) { create ( :user , password : password , confirmed_at : nil ) }
# Ideally, when signing-in with an unconfirmed account,
# the user would be redirected to the "resend email confirmation" page.
#
# However the check for unconfirmed accounts is made by Warden every time a page is loaded –
# and much earlier than SessionsController#create.
#
# For now only test the default behavior (an error message is displayed).
scenario 'they get an error message' do
visit root_path
2022-10-05 16:38:49 +02:00
click_on 'Se connecter' , match : :first
2019-01-08 08:20:49 +01:00
sign_in_with user . email , password
2024-02-05 16:04:36 +01:00
expect ( page ) . to have_content ( 'Vous devez confirmer votre compte par email.' )
2019-01-08 08:20:49 +01:00
end
end
end