demarches-normaliennes/spec/features/users/sign_up_spec.rb
2019-12-03 14:06:11 +01:00

110 lines
4.1 KiB
Ruby
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 'a new user can sign-up and be suggested a valid email when he makes a typo' 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 :user_email, with: 'bidou@yahoo.rf'
fill_in :user_password, with: '12345'
end
scenario 'it can accept the suggestion' 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 'it can discard the suggestion' 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
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 a user is not confirmed yet' do
before do
visit commencer_path(path: procedure.path)
click_on 'Créer un compte demarches-simplifiees.fr'
sign_up_with user_email, user_password
end
# 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
click_on 'Connexion'
sign_in_with user_email, user_password
expect(page).to have_content 'Vous devez confirmer votre adresse email pour continuer'
end
end
end