2017-09-25 14:57:55 +02:00
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
2019-10-17 16:51:42 +02:00
|
|
|
|
feature 'Instructing a dossier:' do
|
2018-05-25 18:05:28 +02:00
|
|
|
|
include ActiveJob::TestHelper
|
|
|
|
|
|
2019-06-20 00:36:50 +02:00
|
|
|
|
let(:password) { 'démarches-simplifiées-pwd' }
|
2019-08-06 11:02:54 +02:00
|
|
|
|
let!(:instructeur) { create(:instructeur, password: password) }
|
2017-09-25 14:57:55 +02:00
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
let!(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) }
|
2019-08-21 09:09:20 +02:00
|
|
|
|
let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
2019-08-08 16:55:51 +02:00
|
|
|
|
context 'the instructeur is also a user' do
|
2019-08-06 11:02:54 +02:00
|
|
|
|
scenario 'a instructeur can fill a dossier' do
|
2018-11-22 18:11:00 +01:00
|
|
|
|
visit commencer_path(path: procedure.path)
|
2019-01-16 11:57:58 +01:00
|
|
|
|
click_on 'J’ai déjà un compte'
|
2018-11-22 18:11:00 +01:00
|
|
|
|
|
|
|
|
|
expect(page).to have_current_path new_user_session_path
|
2019-08-06 11:02:54 +02:00
|
|
|
|
sign_in_with(instructeur.email, password, true)
|
2018-11-22 18:11:00 +01:00
|
|
|
|
|
2019-08-08 16:24:30 +02:00
|
|
|
|
# connexion link erase user stored location
|
|
|
|
|
# expect(page).to have_current_path(commencer_path(path: procedure.path))
|
|
|
|
|
|
|
|
|
|
visit commencer_path(path: procedure.path)
|
2019-01-16 16:16:15 +01:00
|
|
|
|
click_on 'Commencer la démarche'
|
|
|
|
|
|
|
|
|
|
expect(page).to have_content('Identifier votre établissement')
|
2019-01-16 11:57:58 +01:00
|
|
|
|
expect(page).to have_current_path(siret_dossier_path(procedure.reload.dossiers.last))
|
2018-11-22 18:11:00 +01:00
|
|
|
|
expect(page).to have_content(procedure.libelle)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
scenario 'A instructeur can accept a dossier', :js do
|
|
|
|
|
log_in(instructeur.email, password)
|
2017-09-25 14:57:55 +02:00
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
expect(page).to have_current_path(instructeur_procedures_path)
|
2017-09-25 14:57:55 +02:00
|
|
|
|
|
|
|
|
|
click_on procedure.libelle
|
2019-08-06 11:02:54 +02:00
|
|
|
|
expect(page).to have_current_path(instructeur_procedure_path(procedure))
|
2017-09-25 14:57:55 +02:00
|
|
|
|
|
|
|
|
|
click_on dossier.user.email
|
2019-08-06 11:02:54 +02:00
|
|
|
|
expect(page).to have_current_path(instructeur_dossier_path(procedure, dossier))
|
2017-09-25 14:57:55 +02:00
|
|
|
|
|
2018-09-13 17:13:09 +02:00
|
|
|
|
click_on 'En construction'
|
|
|
|
|
accept_confirm do
|
|
|
|
|
click_on 'Passer en instruction'
|
|
|
|
|
end
|
|
|
|
|
expect(page).to have_text('En instruction')
|
|
|
|
|
|
2017-09-25 14:57:55 +02:00
|
|
|
|
dossier.reload
|
2018-08-28 14:10:55 +02:00
|
|
|
|
expect(dossier.state).to eq(Dossier.states.fetch(:en_instruction))
|
2017-09-25 14:57:55 +02:00
|
|
|
|
|
2018-09-13 17:13:09 +02:00
|
|
|
|
click_on 'En instruction'
|
|
|
|
|
|
2019-03-13 16:48:38 +01:00
|
|
|
|
within('.state-button') do
|
2018-09-13 17:13:09 +02:00
|
|
|
|
click_on 'Accepter'
|
|
|
|
|
end
|
|
|
|
|
|
2017-11-29 11:47:18 +01:00
|
|
|
|
within('.accept.motivation') do
|
|
|
|
|
fill_in('dossier_motivation', with: 'a good reason')
|
2018-09-13 17:13:09 +02:00
|
|
|
|
|
|
|
|
|
accept_confirm do
|
|
|
|
|
click_on 'Valider la décision'
|
|
|
|
|
end
|
2017-11-29 11:47:18 +01:00
|
|
|
|
end
|
2017-09-25 14:57:55 +02:00
|
|
|
|
|
2018-09-13 17:13:09 +02:00
|
|
|
|
expect(page).to have_text('Dossier traité avec succès.')
|
2019-08-12 16:46:38 +02:00
|
|
|
|
expect(page).to have_link('Archiver le dossier')
|
2018-09-13 17:13:09 +02:00
|
|
|
|
|
2017-09-25 14:57:55 +02:00
|
|
|
|
dossier.reload
|
2018-08-28 14:10:55 +02:00
|
|
|
|
expect(dossier.state).to eq(Dossier.states.fetch(:accepte))
|
2017-09-25 14:57:55 +02:00
|
|
|
|
expect(dossier.motivation).to eq('a good reason')
|
|
|
|
|
end
|
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
scenario 'A instructeur can follow/unfollow a dossier' do
|
|
|
|
|
log_in(instructeur.email, password)
|
2017-09-25 14:57:55 +02:00
|
|
|
|
|
|
|
|
|
click_on procedure.libelle
|
|
|
|
|
test_statut_bar(a_suivre: 1, tous_les_dossiers: 1)
|
|
|
|
|
dossier_present?(dossier.id, 'en construction')
|
|
|
|
|
|
2017-10-05 19:21:21 +02:00
|
|
|
|
click_on 'Suivre le dossier'
|
2019-08-06 11:02:54 +02:00
|
|
|
|
expect(page).to have_current_path(instructeur_procedure_path(procedure))
|
2017-09-25 14:57:55 +02:00
|
|
|
|
test_statut_bar(suivi: 1, tous_les_dossiers: 1)
|
|
|
|
|
expect(page).to have_text('Aucun dossier')
|
|
|
|
|
|
|
|
|
|
click_on 'suivi'
|
2019-08-06 11:02:54 +02:00
|
|
|
|
expect(page).to have_current_path(instructeur_procedure_path(procedure, statut: 'suivis'))
|
2017-09-25 14:57:55 +02:00
|
|
|
|
dossier_present?(dossier.id, 'en construction')
|
|
|
|
|
|
2017-10-05 19:21:21 +02:00
|
|
|
|
click_on 'Ne plus suivre'
|
2019-08-06 11:02:54 +02:00
|
|
|
|
expect(page).to have_current_path(instructeur_procedure_path(procedure, statut: 'suivis'))
|
2017-09-25 14:57:55 +02:00
|
|
|
|
test_statut_bar(a_suivre: 1, tous_les_dossiers: 1)
|
|
|
|
|
expect(page).to have_text('Aucun dossier')
|
|
|
|
|
end
|
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
scenario 'A instructeur can see the personnes impliquées' do
|
|
|
|
|
instructeur2 = FactoryBot.create(:instructeur, password: password)
|
2017-12-01 15:03:19 +01:00
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
log_in(instructeur.email, password)
|
2017-12-01 15:03:19 +01:00
|
|
|
|
|
|
|
|
|
click_on procedure.libelle
|
|
|
|
|
click_on dossier.user.email
|
|
|
|
|
|
|
|
|
|
click_on 'Avis externes'
|
2019-08-06 11:02:54 +02:00
|
|
|
|
expect(page).to have_current_path(avis_instructeur_dossier_path(procedure, dossier))
|
2017-12-01 15:03:19 +01:00
|
|
|
|
|
|
|
|
|
expert_email = 'expert@tps.com'
|
|
|
|
|
ask_confidential_avis(expert_email, 'a good introduction')
|
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
expert_email = instructeur2.email
|
2017-12-01 15:03:19 +01:00
|
|
|
|
ask_confidential_avis(expert_email, 'a good introduction')
|
|
|
|
|
|
|
|
|
|
click_on 'Personnes impliquées'
|
|
|
|
|
expect(page).to have_text(expert_email)
|
2019-08-06 11:02:54 +02:00
|
|
|
|
expect(page).to have_text(instructeur2.email)
|
2017-12-01 15:03:19 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
scenario 'A instructeur can send a dossier to several instructeurs', js: true do
|
|
|
|
|
instructeur_2 = FactoryBot.create(:instructeur)
|
|
|
|
|
instructeur_3 = FactoryBot.create(:instructeur)
|
2019-08-21 14:09:56 +02:00
|
|
|
|
procedure.defaut_groupe_instructeur.instructeurs << [instructeur_2, instructeur_3]
|
2018-09-10 17:52:49 +02:00
|
|
|
|
|
|
|
|
|
send_dossier = double()
|
2019-08-06 11:02:54 +02:00
|
|
|
|
expect(InstructeurMailer).to receive(:send_dossier).and_return(send_dossier).twice
|
2018-09-10 17:52:49 +02:00
|
|
|
|
expect(send_dossier).to receive(:deliver_later).twice
|
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
log_in(instructeur.email, password)
|
2018-09-10 17:52:49 +02:00
|
|
|
|
|
|
|
|
|
click_on procedure.libelle
|
|
|
|
|
click_on dossier.user.email
|
|
|
|
|
|
|
|
|
|
click_on 'Personnes impliquées'
|
|
|
|
|
|
|
|
|
|
first('.select2-container', minimum: 1).click
|
2019-09-19 10:17:30 +02:00
|
|
|
|
find('li.select2-results__option[role="option"]', text: instructeur_2.email).click
|
2018-09-10 17:52:49 +02:00
|
|
|
|
first('.select2-container', minimum: 1).click
|
2019-09-19 10:17:30 +02:00
|
|
|
|
find('li.select2-results__option[role="option"]', text: instructeur_3.email).click
|
2018-09-10 17:52:49 +02:00
|
|
|
|
|
|
|
|
|
click_on 'Envoyer'
|
|
|
|
|
|
|
|
|
|
expect(page).to have_text("Dossier envoyé")
|
|
|
|
|
end
|
|
|
|
|
|
2018-10-03 11:11:02 +02:00
|
|
|
|
def log_in(email, password, check_email: true)
|
2017-09-25 14:57:55 +02:00
|
|
|
|
visit '/'
|
|
|
|
|
click_on 'Connexion'
|
|
|
|
|
expect(page).to have_current_path(new_user_session_path)
|
|
|
|
|
|
2018-10-03 11:11:02 +02:00
|
|
|
|
sign_in_with(email, password, check_email)
|
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
expect(page).to have_current_path(instructeur_procedures_path)
|
2017-09-25 14:57:55 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def log_out
|
|
|
|
|
click_on 'Se déconnecter'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def ask_confidential_avis(to, introduction)
|
2018-10-31 16:09:11 +01:00
|
|
|
|
fill_in 'avis_emails', with: to
|
2017-09-25 14:57:55 +02:00
|
|
|
|
fill_in 'avis_introduction', with: introduction
|
|
|
|
|
select 'confidentiel', from: 'avis_confidentiel'
|
|
|
|
|
click_on 'Demander un avis'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_mail(to, content)
|
2018-10-03 11:11:02 +02:00
|
|
|
|
mail = ActionMailer::Base.deliveries.last
|
2017-09-25 14:57:55 +02:00
|
|
|
|
expect(mail.to).to match([to])
|
2018-06-10 11:53:51 +02:00
|
|
|
|
expect(mail.body.parts.map(&:to_s)).to all(include(content))
|
2017-09-25 14:57:55 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_statut_bar(a_suivre: 0, suivi: 0, traite: 0, tous_les_dossiers: 0, archive: 0)
|
|
|
|
|
texts = [
|
|
|
|
|
"à suivre #{a_suivre}",
|
|
|
|
|
"suivi #{suivi}",
|
|
|
|
|
"traité #{traite}",
|
|
|
|
|
"tous les dossiers #{tous_les_dossiers}",
|
2018-01-15 19:17:01 +01:00
|
|
|
|
"archivé #{archive}"
|
|
|
|
|
]
|
2017-09-25 14:57:55 +02:00
|
|
|
|
|
|
|
|
|
texts.each { |text| expect(page).to have_text(text) }
|
|
|
|
|
end
|
|
|
|
|
|
2018-12-24 17:56:04 +01:00
|
|
|
|
def avis_sign_up(avis, email)
|
2019-08-06 11:02:54 +02:00
|
|
|
|
visit sign_up_instructeur_avis_path(avis, email)
|
2019-10-21 11:24:43 +02:00
|
|
|
|
fill_in 'user_password', with: 'démarches-simplifiées-pwd'
|
2017-09-25 14:57:55 +02:00
|
|
|
|
click_on 'Créer un compte'
|
2019-08-06 11:02:54 +02:00
|
|
|
|
expect(page).to have_current_path(instructeur_avis_index_path)
|
2017-09-25 14:57:55 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def dossier_present?(id, statut)
|
|
|
|
|
within(:css, '.dossiers-table') do
|
|
|
|
|
expect(page).to have_text(id)
|
|
|
|
|
expect(page).to have_text(statut)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|