2018-08-01 17:27:50 +02:00
|
|
|
require 'spec_helper'
|
2018-09-24 16:23:53 +02:00
|
|
|
require 'features/new_user/dossier_shared_examples.rb'
|
2018-08-01 17:27:50 +02:00
|
|
|
|
|
|
|
feature 'Invitations' do
|
2018-09-24 16:10:50 +02:00
|
|
|
let(:owner) { create(:user) }
|
2018-08-01 17:27:50 +02:00
|
|
|
let(:invited_user) { create(:user, email: 'user_invite@exemple.fr') }
|
2018-09-24 15:54:46 +02:00
|
|
|
let(:procedure) { create(:simple_procedure) }
|
2018-08-01 17:27:50 +02:00
|
|
|
let(:invite) { create(:invite_user, user: invited_user, dossier: dossier) }
|
|
|
|
|
|
|
|
context 'when the dossier is a brouillon' do
|
2018-09-24 16:10:50 +02:00
|
|
|
let!(:dossier) { create(:dossier, :for_individual, state: Dossier.states.fetch(:brouillon), user: owner, procedure: procedure) }
|
2018-08-01 17:27:50 +02:00
|
|
|
|
2018-09-24 16:10:50 +02:00
|
|
|
scenario 'on the form, the owner of a dossier can invite another user to collaborate on the dossier', js: true do
|
|
|
|
log_in(owner)
|
2018-08-01 17:27:50 +02:00
|
|
|
navigate_to_brouillon(dossier)
|
|
|
|
|
2018-09-24 15:54:46 +02:00
|
|
|
fill_in 'Texte obligatoire', with: 'Some edited value'
|
2018-08-01 17:27:50 +02:00
|
|
|
send_invite_to "user_invite@exemple.fr"
|
|
|
|
|
2018-09-06 09:09:23 +02:00
|
|
|
expect(page).to have_current_path(brouillon_dossier_path(dossier))
|
2018-08-01 17:27:50 +02:00
|
|
|
expect(page).to have_text("Une invitation a été envoyée à user_invite@exemple.fr.")
|
|
|
|
expect(page).to have_text("user_invite@exemple.fr")
|
2018-07-31 17:26:08 +02:00
|
|
|
|
|
|
|
# Ensure unsaved edits to the form are not lost
|
2018-09-24 15:54:46 +02:00
|
|
|
expect(page).to have_field('Texte obligatoire', with: 'Some edited value')
|
2018-08-01 17:27:50 +02:00
|
|
|
end
|
|
|
|
|
2018-09-18 16:54:37 +02:00
|
|
|
context 'when inviting someone without an existing account' do
|
|
|
|
let(:invite) { create(:invite_user, dossier: dossier, user: nil) }
|
|
|
|
let(:user_password) { 'l33tus3r' }
|
|
|
|
|
|
|
|
scenario 'an invited user can register using the registration link sent in the invitation email' do
|
|
|
|
# Click the invitation link
|
|
|
|
visit users_dossiers_invite_path(invite.id, params: { email: invite.email })
|
|
|
|
|
|
|
|
# Create the account
|
|
|
|
expect(page).to have_current_path(new_user_registration_path, ignore_query: true)
|
|
|
|
expect(page).to have_field('user_email', with: invite.email)
|
|
|
|
fill_in 'user_password', with: user_password
|
|
|
|
click_on 'Créer un compte'
|
|
|
|
|
2018-09-19 15:05:26 +02:00
|
|
|
expect(page).to have_content("lien d'activation")
|
2018-09-18 16:54:37 +02:00
|
|
|
|
|
|
|
# Confirm the email
|
|
|
|
user = User.find_by(email: invite.email)
|
|
|
|
visit Rails.application.routes.url_helpers.user_confirmation_path(confirmation_token: user.confirmation_token)
|
|
|
|
submit_login_form(user.email, user_password)
|
|
|
|
|
|
|
|
# The user should be redirected to the dossier they was invited on
|
|
|
|
expect(page).to have_current_path(brouillon_dossier_path(dossier))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-01 17:27:50 +02:00
|
|
|
scenario 'an invited user can see and edit the draft', js: true do
|
2018-09-24 16:22:37 +02:00
|
|
|
navigate_to_invited_dossier(invite)
|
2018-09-06 09:09:23 +02:00
|
|
|
expect(page).to have_current_path(brouillon_dossier_path(dossier))
|
2018-09-24 16:22:37 +02:00
|
|
|
|
2018-08-01 17:27:50 +02:00
|
|
|
expect(page).to have_no_selector('.button.invite-user-action')
|
|
|
|
|
2018-09-24 15:54:46 +02:00
|
|
|
fill_in 'Texte obligatoire', with: 'Some edited value'
|
2018-08-01 17:27:50 +02:00
|
|
|
click_button 'Enregistrer le brouillon'
|
|
|
|
expect(page).to have_text('Votre brouillon a bien été sauvegardé')
|
2018-09-24 15:54:46 +02:00
|
|
|
expect(page).to have_field('Texte obligatoire', with: 'Some edited value')
|
2018-08-01 17:27:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'an invited user cannot submit the draft' do
|
2018-09-24 16:22:37 +02:00
|
|
|
navigate_to_invited_dossier(invite)
|
2018-09-06 09:09:23 +02:00
|
|
|
expect(page).to have_current_path(brouillon_dossier_path(dossier))
|
2018-08-01 17:27:50 +02:00
|
|
|
|
|
|
|
expect(page).to have_button('Soumettre le dossier', disabled: true)
|
|
|
|
expect(page).to have_selector('.invite-cannot-submit')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-24 16:23:53 +02:00
|
|
|
context 'when the dossier is en_construction' do
|
|
|
|
let!(:dossier) { create(:dossier, :for_individual, :en_construction, user: owner, procedure: procedure) }
|
|
|
|
|
|
|
|
scenario 'on dossier details, the owner of a dossier can invite another user to collaborate on the dossier', js: true do
|
|
|
|
log_in(owner)
|
|
|
|
navigate_to_dossier(dossier)
|
|
|
|
|
|
|
|
send_invite_to "user_invite@exemple.fr"
|
|
|
|
|
|
|
|
expect(page).to have_current_path(dossier_path(dossier))
|
|
|
|
expect(page).to have_text("Une invitation a été envoyée à user_invite@exemple.fr.")
|
|
|
|
expect(page).to have_text("user_invite@exemple.fr")
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as an invited user' do
|
|
|
|
before do
|
|
|
|
navigate_to_invited_dossier(invite)
|
|
|
|
expect(page).to have_current_path(dossier_path(invite.dossier))
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'the user can edit the submitted demande'
|
|
|
|
it_behaves_like 'the user can send messages to the instructeur'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-01 17:27:50 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
def log_in(user)
|
|
|
|
visit '/'
|
|
|
|
click_on 'Connexion'
|
2018-09-18 16:15:11 +02:00
|
|
|
submit_login_form(user.email, user.password)
|
2018-08-01 17:27:50 +02:00
|
|
|
expect(page).to have_current_path(dossiers_path)
|
|
|
|
end
|
|
|
|
|
2018-09-18 16:15:11 +02:00
|
|
|
def submit_login_form(email, password)
|
|
|
|
fill_in 'user_email', with: email
|
|
|
|
fill_in 'user_password', with: password
|
2018-08-01 17:27:50 +02:00
|
|
|
click_on 'Se connecter'
|
|
|
|
end
|
|
|
|
|
|
|
|
def navigate_to_brouillon(dossier)
|
|
|
|
expect(page).to have_current_path(dossiers_path)
|
|
|
|
click_on(dossier.id)
|
2018-09-06 09:09:23 +02:00
|
|
|
expect(page).to have_current_path(brouillon_dossier_path(dossier))
|
2018-09-24 16:23:53 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def navigate_to_dossier(dossier)
|
|
|
|
expect(page).to have_current_path(dossiers_path)
|
|
|
|
click_on(dossier.id)
|
|
|
|
expect(page).to have_current_path(dossier_path(dossier))
|
2018-08-01 17:27:50 +02:00
|
|
|
end
|
|
|
|
|
2018-09-24 16:22:37 +02:00
|
|
|
def navigate_to_invited_dossier(invite)
|
|
|
|
visit users_dossiers_invite_path(invite)
|
|
|
|
expect(page).to have_current_path(new_user_session_path)
|
|
|
|
submit_login_form(invited_user.email, invited_user.password)
|
|
|
|
end
|
|
|
|
|
2018-08-01 17:27:50 +02:00
|
|
|
def send_invite_to(invited_email)
|
2018-09-11 17:51:44 +02:00
|
|
|
click_on "Inviter une personne à modifier ce dossier"
|
2018-08-01 17:27:50 +02:00
|
|
|
expect(page).to have_button("Envoyer une invitation", visible: true)
|
|
|
|
|
|
|
|
fill_in 'invite_email', with: invited_email
|
|
|
|
click_on "Envoyer une invitation"
|
|
|
|
end
|
|
|
|
end
|