demarches-normaliennes/spec/features/users/sign_up_spec.rb
Pierre de La Morinerie a8444927ab specs: fix the sign-up with unconfirmed account test
It was testing the sign-in instead of the sign-up.
2020-02-12 13:24:52 +00:00

142 lines
5.3 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

require 'spec_helper'
feature 'Signing up:' do
let(:user_email) { generate :user_email }
let(:user_password) { 'démarches-simplifiées-pwd' }
let(:procedure) { create :simple_procedure, :with_service }
scenario 'a new user can sign-up' do
visit commencer_path(path: procedure.path)
click_on 'Créer un compte demarches-simplifiees.fr'
sign_up_with user_email, user_password
expect(page).to have_content "nous avons besoin de vérifier votre adresse #{user_email}"
click_confirmation_link_for user_email
expect(page).to have_content 'Votre compte a été activé'
expect(page).to have_current_path commencer_path(path: procedure.path)
end
context 'when the user makes a typo in their email address' do
let(:procedure) { create :simple_procedure, :with_service }
before do
visit commencer_path(path: procedure.path)
click_on 'Créer un compte demarches-simplifiees.fr'
expect(page).to have_selector('.suspect-email', visible: false)
fill_in 'Email', with: 'bidou@yahoo.rf'
fill_in 'Mot de passe', with: '12345'
end
scenario 'they can accept the suggestion', js: true do
expect(page).to have_selector('.suspect-email', visible: true)
click_on 'Oui'
expect(page).to have_field("Email", :with => 'bidou@yahoo.fr')
expect(page).to have_selector('.suspect-email', visible: false)
end
scenario 'they can discard the suggestion', js: true do
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
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
end
scenario 'a new user cant sign-up with too short password when visiting a procedure' do
visit commencer_path(path: procedure.path)
click_on 'Créer un compte demarches-simplifiees.fr'
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
context 'when visiting a procedure' do
let(:procedure) { create :simple_procedure, :with_service }
before do
visit commencer_path(path: procedure.path)
end
scenario 'a new user can sign-up and fill the procedure' do
click_on 'Créer un compte'
expect(page).to have_current_path new_user_registration_path
expect(page).to have_procedure_description(procedure)
sign_up_with user_email, user_password
expect(page).to have_content "nous avons besoin de vérifier votre adresse #{user_email}"
click_confirmation_link_for user_email
expect(page).to have_current_path(commencer_path(path: procedure.path))
expect(page).to have_content 'Votre compte a été activé'
click_on 'Commencer la démarche'
expect(page).to have_current_path identite_dossier_path(procedure.reload.dossiers.last)
expect(page).to have_procedure_description(procedure)
end
end
context 'when the user is not confirmed yet' do
before do
create(:user, :unconfirmed, email: user_email, password: user_password)
end
scenario 'the email confirmation page is displayed' 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}"
# The confirmation email is sent again
confirmation_email = open_email(user_email)
expect(confirmation_email.body).to have_text('Pour activer votre compte')
end
end
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à')
# When clicking the main button, the user has a link to directly sign-in
# for the procedure they were initially starting
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
end