2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2024-09-16 14:58:37 +02:00
|
|
|
|
describe 'Signing up:', js: true do
|
2018-11-08 15:02:41 +01:00
|
|
|
|
let(:user_email) { generate :user_email }
|
2023-03-03 14:16:15 +01:00
|
|
|
|
let(:user_password) { SECURE_PASSWORD }
|
2019-08-23 15:32:33 +02:00
|
|
|
|
let(:procedure) { create :simple_procedure, :with_service }
|
2018-11-08 15:02:41 +01:00
|
|
|
|
|
2020-02-13 16:14:30 +01:00
|
|
|
|
scenario 'a new user can sign-up from scratch' do
|
|
|
|
|
visit new_user_registration_path
|
2018-11-06 17:07:44 +01:00
|
|
|
|
|
2018-11-08 15:02:41 +01:00
|
|
|
|
sign_up_with user_email, user_password
|
2024-02-20 14:28:45 +01:00
|
|
|
|
expect(page).to have_content "nous avons besoin de vérifier votre adresse électronique #{user_email}"
|
2018-11-06 17:07:44 +01:00
|
|
|
|
|
2018-11-08 15:02:41 +01:00
|
|
|
|
click_confirmation_link_for user_email
|
2020-09-01 15:28:31 +02:00
|
|
|
|
expect(page).to have_content('Votre compte a bien été confirmé.')
|
2020-02-13 16:14:30 +01:00
|
|
|
|
expect(page).to have_current_path dossiers_path
|
2018-11-06 17:07:44 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-12-02 17:16:18 +01:00
|
|
|
|
context 'when the user makes a typo in their email address' do
|
2019-12-02 15:27:02 +01:00
|
|
|
|
let(:procedure) { create :simple_procedure, :with_service }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
visit commencer_path(path: procedure.path)
|
2021-03-08 10:37:31 +01:00
|
|
|
|
click_on "Créer un compte #{APPLICATION_NAME}"
|
2019-12-02 15:27:02 +01:00
|
|
|
|
expect(page).to have_selector('.suspect-email', visible: false)
|
2023-06-28 10:24:37 +02:00
|
|
|
|
fill_in 'Adresse électronique', with: 'bidou@yahoo.rf'
|
2024-09-16 14:58:37 +02:00
|
|
|
|
fill_in 'Mot de passe', with: '1 2 3 4 5 6 '
|
2019-12-02 15:27:02 +01:00
|
|
|
|
end
|
|
|
|
|
|
2023-11-06 15:15:51 +01:00
|
|
|
|
scenario 'they can accept the suggestion', js: true do
|
2019-12-02 15:27:02 +01:00
|
|
|
|
expect(page).to have_selector('.suspect-email', visible: true)
|
|
|
|
|
click_on 'Oui'
|
2023-06-28 10:24:37 +02:00
|
|
|
|
expect(page).to have_field("Adresse électronique", :with => 'bidou@yahoo.fr')
|
2019-12-02 15:27:02 +01:00
|
|
|
|
expect(page).to have_selector('.suspect-email', visible: false)
|
|
|
|
|
end
|
|
|
|
|
|
2023-11-06 15:15:51 +01:00
|
|
|
|
scenario 'they can discard the suggestion', js: true do
|
2019-12-02 15:27:02 +01:00
|
|
|
|
expect(page).to have_selector('.suspect-email', visible: true)
|
|
|
|
|
click_on 'Non'
|
2023-06-28 10:24:37 +02:00
|
|
|
|
expect(page).to have_field("Adresse électronique", :with => 'bidou@yahoo.rf')
|
2019-12-02 15:27:02 +01:00
|
|
|
|
expect(page).to have_selector('.suspect-email', visible: false)
|
|
|
|
|
end
|
2019-12-02 17:16:42 +01:00
|
|
|
|
|
2023-11-06 15:15:51 +01:00
|
|
|
|
scenario 'they can fix the typo themselves', js: true do
|
2019-12-02 17:16:42 +01:00
|
|
|
|
expect(page).to have_selector('.suspect-email', visible: true)
|
2023-06-28 10:24:37 +02:00
|
|
|
|
fill_in 'Adresse électronique', with: 'bidou@yahoo.fr'
|
2019-12-02 17:16:42 +01:00
|
|
|
|
blur
|
|
|
|
|
expect(page).to have_selector('.suspect-email', visible: false)
|
|
|
|
|
end
|
2019-12-02 15:27:02 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-08-23 15:32:33 +02:00
|
|
|
|
scenario 'a new user can’t sign-up with too short password when visiting a procedure' do
|
|
|
|
|
visit commencer_path(path: procedure.path)
|
2024-09-16 14:58:37 +02:00
|
|
|
|
click_on 'Créer un compte'
|
2018-12-12 00:59:49 +01:00
|
|
|
|
|
|
|
|
|
expect(page).to have_current_path new_user_registration_path
|
2024-09-16 14:58:37 +02:00
|
|
|
|
fill_in :user_email, with: user_email
|
|
|
|
|
fill_in :user_password, with: '1234567'
|
|
|
|
|
expect(page).to have_content "Le mot de passe doit faire au moins 12 caractères."
|
2018-12-12 00:59:49 +01:00
|
|
|
|
|
|
|
|
|
# Then with a good password
|
|
|
|
|
sign_up_with user_email, user_password
|
|
|
|
|
expect(page).to have_current_path new_user_confirmation_path user: { email: user_email }
|
2024-02-20 14:28:45 +01:00
|
|
|
|
expect(page).to have_content "nous avons besoin de vérifier votre adresse électronique #{user_email}"
|
2018-12-12 00:59:49 +01:00
|
|
|
|
end
|
|
|
|
|
|
2018-11-06 17:07:44 +01:00
|
|
|
|
context 'when visiting a procedure' do
|
2019-01-14 16:26:53 +01:00
|
|
|
|
let(:procedure) { create :simple_procedure, :with_service }
|
2018-11-06 17:07:44 +01:00
|
|
|
|
|
2020-02-13 16:14:52 +01:00
|
|
|
|
scenario 'a new user can sign-up and fill the procedure' do
|
2018-11-06 17:07:44 +01:00
|
|
|
|
visit commencer_path(path: procedure.path)
|
|
|
|
|
|
|
|
|
|
click_on 'Créer un compte'
|
2019-01-16 11:57:58 +01:00
|
|
|
|
expect(page).to have_current_path new_user_registration_path
|
2018-11-06 17:07:44 +01:00
|
|
|
|
|
2018-11-08 15:02:41 +01:00
|
|
|
|
sign_up_with user_email, user_password
|
2024-02-20 14:28:45 +01:00
|
|
|
|
expect(page).to have_content "nous avons besoin de vérifier votre adresse électronique #{user_email}"
|
2018-11-06 17:07:44 +01:00
|
|
|
|
|
2020-02-24 11:55:29 +01:00
|
|
|
|
click_confirmation_link_for(user_email, in_another_browser: true)
|
2019-01-16 16:16:15 +01:00
|
|
|
|
|
2020-02-24 11:55:29 +01:00
|
|
|
|
# After confirmation, the user is redirected to the procedure they were initially starting
|
|
|
|
|
# (even when confirming the account in another browser).
|
2019-01-16 16:16:15 +01:00
|
|
|
|
expect(page).to have_current_path(commencer_path(path: procedure.path))
|
2020-09-01 15:28:31 +02:00
|
|
|
|
expect(page).to have_content I18n.t('devise.confirmations.confirmed')
|
2019-01-16 16:16:15 +01:00
|
|
|
|
click_on 'Commencer la démarche'
|
|
|
|
|
|
2019-01-16 11:57:58 +01:00
|
|
|
|
expect(page).to have_current_path identite_dossier_path(procedure.reload.dossiers.last)
|
2023-05-25 15:19:55 +02:00
|
|
|
|
expect(page).to have_content(procedure.libelle)
|
2018-11-06 17:07:44 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2018-11-08 15:02:41 +01:00
|
|
|
|
|
2020-02-11 18:18:31 +01:00
|
|
|
|
context 'when the user is not confirmed yet' do
|
2018-11-08 15:02:41 +01:00
|
|
|
|
before do
|
2020-02-11 18:18:31 +01:00
|
|
|
|
create(:user, :unconfirmed, email: user_email, password: user_password)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'the email confirmation page is displayed' do
|
2019-08-23 15:32:33 +02:00
|
|
|
|
visit commencer_path(path: procedure.path)
|
2020-02-11 18:18:31 +01:00
|
|
|
|
click_on 'Créer un compte'
|
2018-11-08 15:02:41 +01:00
|
|
|
|
|
|
|
|
|
sign_up_with user_email, user_password
|
|
|
|
|
|
2020-02-11 18:18:31 +01:00
|
|
|
|
# The same page than for initial sign-ups is displayed, to avoid leaking informations
|
2020-02-13 16:14:52 +01:00
|
|
|
|
# about the account existence.
|
2024-02-20 14:28:45 +01:00
|
|
|
|
expect(page).to have_content "nous avons besoin de vérifier votre adresse électronique #{user_email}"
|
2020-02-11 18:18:31 +01:00
|
|
|
|
|
|
|
|
|
# The confirmation email is sent again
|
|
|
|
|
confirmation_email = open_email(user_email)
|
|
|
|
|
expect(confirmation_email.body).to have_text('Pour activer votre compte')
|
2020-02-24 11:55:29 +01:00
|
|
|
|
|
|
|
|
|
click_confirmation_link_for(user_email, in_another_browser: true)
|
|
|
|
|
|
|
|
|
|
# After confirmation, the user is redirected to the procedure they were initially starting
|
|
|
|
|
# (even when confirming the account in another browser).
|
|
|
|
|
expect(page).to have_current_path(commencer_path(path: procedure.path))
|
2020-09-01 15:28:31 +02:00
|
|
|
|
expect(page).to have_content I18n.t('devise.confirmations.confirmed')
|
2020-02-24 11:55:29 +01:00
|
|
|
|
expect(page).to have_content 'Commencer la démarche'
|
2018-11-08 15:02:41 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2020-02-11 18:17:09 +01:00
|
|
|
|
|
|
|
|
|
context 'when the user already has a confirmed account' do
|
|
|
|
|
before do
|
|
|
|
|
create(:user, email: user_email, password: user_password)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'they get a warning email, containing a link to the procedure' do
|
|
|
|
|
visit commencer_path(path: procedure.path)
|
|
|
|
|
click_on 'Créer un compte'
|
|
|
|
|
|
|
|
|
|
sign_up_with user_email, user_password
|
|
|
|
|
|
|
|
|
|
# The same page than for initial sign-ups is displayed, to avoid leaking informations
|
|
|
|
|
# about the accound existence.
|
2024-02-20 14:28:45 +01:00
|
|
|
|
expect(page).to have_content "nous avons besoin de vérifier votre adresse électronique #{user_email}"
|
2020-02-11 18:17:09 +01:00
|
|
|
|
|
|
|
|
|
# A warning email is sent
|
|
|
|
|
warning_email = open_email(user_email)
|
|
|
|
|
expect(warning_email.body).to have_text('Votre compte existe déjà')
|
|
|
|
|
|
2020-02-13 16:14:52 +01:00
|
|
|
|
# When clicking the main button, the user is redirected directly to
|
|
|
|
|
# the sign-in page for the procedure they were initially starting.
|
2020-02-11 18:17:09 +01:00
|
|
|
|
click_procedure_sign_in_link_for user_email
|
|
|
|
|
|
|
|
|
|
expect(page).to have_current_path new_user_session_path
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-07-18 13:53:06 +02:00
|
|
|
|
|
|
|
|
|
context 'when the user already has a confirmed account but is blocked' do
|
|
|
|
|
before do
|
|
|
|
|
create(:user, email: user_email, password: user_password, blocked_at: Time.current)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'they cannot signed in' do
|
|
|
|
|
visit new_user_session_path
|
|
|
|
|
sign_in_with user_email, user_password
|
|
|
|
|
|
|
|
|
|
expect(page).to have_current_path new_user_session_path
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-11-06 17:07:44 +01:00
|
|
|
|
end
|