2021-10-26 11:44:53 +02:00
|
|
|
|
describe 'Signing up:' do
|
2018-11-08 15:02:41 +01:00
|
|
|
|
let(:user_email) { generate :user_email }
|
2020-07-21 16:49:26 +02:00
|
|
|
|
let(:user_password) { 'my-s3cure-p4ssword' }
|
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
|
|
|
|
|
expect(page).to have_content "nous avons besoin de vérifier votre adresse #{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)
|
2019-12-02 17:16:18 +01:00
|
|
|
|
fill_in 'Email', with: 'bidou@yahoo.rf'
|
|
|
|
|
fill_in 'Mot de passe', with: '12345'
|
2019-12-02 15:27:02 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-12-02 17:16:18 +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'
|
2019-12-02 17:16:18 +01:00
|
|
|
|
expect(page).to have_field("Email", :with => 'bidou@yahoo.fr')
|
2019-12-02 15:27:02 +01:00
|
|
|
|
expect(page).to have_selector('.suspect-email', visible: false)
|
|
|
|
|
end
|
|
|
|
|
|
2019-12-02 17:16:18 +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'
|
|
|
|
|
expect(page).to have_field("Email", :with => 'bidou@yahoo.rf')
|
|
|
|
|
expect(page).to have_selector('.suspect-email', visible: false)
|
|
|
|
|
end
|
2019-12-02 17:16:42 +01:00
|
|
|
|
|
|
|
|
|
scenario 'they can fix the typo themselves', js: true do
|
|
|
|
|
expect(page).to have_selector('.suspect-email', visible: true)
|
|
|
|
|
fill_in 'Email', with: 'bidou@yahoo.fr'
|
|
|
|
|
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)
|
2021-03-08 10:37:31 +01:00
|
|
|
|
click_on "Créer un compte #{APPLICATION_NAME}"
|
2018-12-12 00:59:49 +01:00
|
|
|
|
|
|
|
|
|
expect(page).to have_current_path new_user_registration_path
|
|
|
|
|
sign_up_with user_email, '1234567'
|
|
|
|
|
expect(page).to have_current_path user_registration_path
|
|
|
|
|
expect(page).to have_content 'Le mot de passe est trop court'
|
|
|
|
|
|
|
|
|
|
# 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 }
|
|
|
|
|
expect(page).to have_content "nous avons besoin de vérifier votre adresse #{user_email}"
|
|
|
|
|
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
|
2019-11-26 15:05:33 +01:00
|
|
|
|
expect(page).to have_procedure_description(procedure)
|
2018-11-06 17:07:44 +01:00
|
|
|
|
|
2018-11-08 15:02:41 +01:00
|
|
|
|
sign_up_with user_email, user_password
|
|
|
|
|
expect(page).to have_content "nous avons besoin de vérifier votre adresse #{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)
|
2019-11-26 15:05:33 +01:00
|
|
|
|
expect(page).to have_procedure_description(procedure)
|
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.
|
2020-02-11 18:18:31 +01:00
|
|
|
|
expect(page).to have_content "nous avons besoin de vérifier votre adresse #{user_email}"
|
|
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
expect(page).to have_content "nous avons besoin de vérifier votre adresse #{user_email}"
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
expect(page).to have_procedure_description(procedure)
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-11-06 17:07:44 +01:00
|
|
|
|
end
|