2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2021-11-25 16:26:55 +01:00
|
|
|
|
require 'system/administrateurs/procedure_spec_helper'
|
2020-03-13 15:32:30 +01:00
|
|
|
|
|
2023-11-06 15:15:51 +01:00
|
|
|
|
describe 'Publishing a procedure', js: true do
|
2020-03-13 15:32:30 +01:00
|
|
|
|
include ProcedureSpecHelper
|
|
|
|
|
|
2024-06-01 22:50:48 +02:00
|
|
|
|
let(:administrateur) { administrateurs(:default_admin) }
|
2024-03-14 17:17:47 +01:00
|
|
|
|
let(:other_administrateur) { create(:administrateur) }
|
|
|
|
|
|
2020-03-13 15:32:30 +01:00
|
|
|
|
let(:instructeurs) { [administrateur.user.instructeur] }
|
|
|
|
|
let!(:procedure) do
|
|
|
|
|
create(:procedure_with_dossiers,
|
|
|
|
|
:with_path,
|
|
|
|
|
:with_type_de_champ,
|
|
|
|
|
:with_service,
|
2022-12-20 11:21:52 +01:00
|
|
|
|
:with_zone,
|
2020-03-13 15:32:30 +01:00
|
|
|
|
instructeurs: instructeurs,
|
|
|
|
|
administrateur: administrateur)
|
|
|
|
|
end
|
2024-03-14 17:17:47 +01:00
|
|
|
|
let!(:other_procedure) do
|
|
|
|
|
create(:procedure_with_dossiers,
|
|
|
|
|
:published,
|
|
|
|
|
:with_path,
|
|
|
|
|
:with_type_de_champ,
|
|
|
|
|
:with_service,
|
|
|
|
|
:with_zone,
|
|
|
|
|
instructeurs: instructeurs,
|
|
|
|
|
administrateur: other_administrateur)
|
|
|
|
|
end
|
2020-03-13 15:32:30 +01:00
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
login_as administrateur.user, scope: :user
|
|
|
|
|
end
|
|
|
|
|
|
2021-11-23 13:34:48 +01:00
|
|
|
|
context 'when using a deprecated back-office URL' do
|
|
|
|
|
scenario 'the admin is redirected to the draft procedure' do
|
2020-09-17 13:53:48 +02:00
|
|
|
|
visit admin_procedures_draft_path
|
|
|
|
|
expect(page).to have_current_path(admin_procedures_path(statut: "brouillons"))
|
|
|
|
|
end
|
|
|
|
|
|
2021-11-23 13:34:48 +01:00
|
|
|
|
scenario 'the admin is redirected to the archived procedures' do
|
2020-09-17 13:53:48 +02:00
|
|
|
|
visit admin_procedures_archived_path
|
|
|
|
|
expect(page).to have_current_path(admin_procedures_path(statut: "archivees"))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-11-23 13:34:48 +01:00
|
|
|
|
context 'when a procedure isn’t published yet' do
|
2024-06-03 07:44:27 +02:00
|
|
|
|
scenario 'an admin can publish it' do
|
|
|
|
|
visit admin_procedure_path(procedure)
|
2020-07-15 10:48:11 +02:00
|
|
|
|
find('#publish-procedure-link').click
|
2021-11-24 11:09:58 +01:00
|
|
|
|
|
2020-09-08 12:35:44 +02:00
|
|
|
|
expect(find_field('procedure_path').value).to eq procedure.path
|
|
|
|
|
fill_in 'lien_site_web', with: 'http://some.website'
|
2023-10-10 16:51:06 +02:00
|
|
|
|
within('form') { click_on 'Publier' }
|
2020-03-13 15:32:30 +01:00
|
|
|
|
|
2023-11-06 17:46:22 +01:00
|
|
|
|
expect(page).to have_text('Votre démarche est désormais publiée !')
|
|
|
|
|
expect(page).to have_button(title: 'Copiez le lien de la procédure')
|
2020-03-13 15:32:30 +01:00
|
|
|
|
end
|
2021-11-24 11:09:58 +01:00
|
|
|
|
|
|
|
|
|
context 'when the procedure has invalid champs' do
|
|
|
|
|
let!(:procedure) do
|
|
|
|
|
create(:procedure,
|
|
|
|
|
:with_path,
|
|
|
|
|
:with_service,
|
2022-12-20 11:21:52 +01:00
|
|
|
|
:with_zone,
|
2021-11-24 11:09:58 +01:00
|
|
|
|
instructeurs: instructeurs,
|
|
|
|
|
administrateur: administrateur,
|
2022-08-04 11:39:07 +02:00
|
|
|
|
types_de_champ_public: [{ type: :repetition, libelle: 'Enfants', children: [] }, { type: :drop_down_list, libelle: 'Civilité', options: [] }],
|
|
|
|
|
types_de_champ_private: [{ type: :drop_down_list, libelle: 'Civilité', options: [] }])
|
2021-11-24 11:09:58 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'an error message prevents the publication' do
|
2024-06-03 07:44:27 +02:00
|
|
|
|
visit admin_procedure_path(procedure)
|
|
|
|
|
|
2021-11-24 11:09:58 +01:00
|
|
|
|
expect(page).to have_content('Des problèmes empêchent la publication de la démarche')
|
2024-06-05 18:00:19 +02:00
|
|
|
|
expect(page).to have_content("Enfants doit comporter au moins un champ répétable")
|
|
|
|
|
expect(page).to have_content("Civilité doit comporter au moins un choix sélectionnable")
|
2021-11-24 11:09:58 +01:00
|
|
|
|
|
2024-06-03 07:44:27 +02:00
|
|
|
|
visit admin_procedure_publication_path(procedure)
|
2021-11-24 11:09:58 +01:00
|
|
|
|
expect(find_field('procedure_path').value).to eq procedure.path
|
|
|
|
|
fill_in 'lien_site_web', with: 'http://some.website'
|
|
|
|
|
|
|
|
|
|
expect(page).to have_button('Publier', disabled: true)
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-03-14 17:17:47 +01:00
|
|
|
|
|
|
|
|
|
context 'when the procedure has the same path as another procedure from another admin ' do
|
|
|
|
|
scenario 'an error message prevents the publication' do
|
2024-06-03 07:44:27 +02:00
|
|
|
|
visit admin_procedure_publication_path(procedure)
|
2024-03-14 17:17:47 +01:00
|
|
|
|
fill_in 'procedure_path', with: other_procedure.path
|
2024-06-03 07:44:27 +02:00
|
|
|
|
|
2024-03-14 17:17:47 +01:00
|
|
|
|
expect(page).to have_content 'vous devez la modifier afin de pouvoir publier votre démarche'
|
|
|
|
|
|
|
|
|
|
fill_in 'lien_site_web', with: 'http://some.website'
|
|
|
|
|
within('form') { click_on 'Publier' }
|
|
|
|
|
|
|
|
|
|
expect(page).to have_text('Le champ « Lien public » est déjà utilisé par une démarche.')
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-03-13 15:32:30 +01:00
|
|
|
|
end
|
|
|
|
|
|
2021-11-23 13:34:48 +01:00
|
|
|
|
context 'when a procedure is closed' do
|
2020-03-13 15:32:30 +01:00
|
|
|
|
let!(:procedure) do
|
|
|
|
|
create(:procedure_with_dossiers,
|
|
|
|
|
:closed,
|
|
|
|
|
:with_path,
|
|
|
|
|
:with_type_de_champ,
|
|
|
|
|
:with_service,
|
|
|
|
|
instructeurs: instructeurs,
|
|
|
|
|
administrateur: administrateur)
|
|
|
|
|
end
|
|
|
|
|
|
2021-11-23 13:34:48 +01:00
|
|
|
|
scenario 'an admin can publish it again' do
|
2020-09-08 12:35:44 +02:00
|
|
|
|
visit admin_procedures_path(statut: "archivees")
|
2020-03-13 15:32:30 +01:00
|
|
|
|
click_on procedure.libelle
|
2020-07-15 10:48:11 +02:00
|
|
|
|
find('#publish-procedure-link').click
|
2020-03-13 15:32:30 +01:00
|
|
|
|
|
2020-09-08 12:35:44 +02:00
|
|
|
|
expect(find_field('procedure_path').value).to eq procedure.path
|
|
|
|
|
fill_in 'lien_site_web', with: 'http://some.website'
|
|
|
|
|
click_on 'publish'
|
2020-03-13 15:32:30 +01:00
|
|
|
|
|
2023-11-06 17:46:22 +01:00
|
|
|
|
expect(page).to have_text('Votre démarche est désormais publiée !')
|
2020-03-13 15:32:30 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-06-07 13:54:11 +02:00
|
|
|
|
context 'when a procedure is closed with revision changes' do
|
|
|
|
|
let!(:tdc) { { type_champ: :text, libelle: 'nouveau champ' } }
|
2020-03-13 15:32:30 +01:00
|
|
|
|
let!(:procedure) do
|
|
|
|
|
create(:procedure_with_dossiers,
|
2022-06-07 13:54:11 +02:00
|
|
|
|
:closed,
|
2020-03-13 15:32:30 +01:00
|
|
|
|
:with_path,
|
|
|
|
|
:with_type_de_champ,
|
|
|
|
|
:with_service,
|
|
|
|
|
instructeurs: instructeurs,
|
|
|
|
|
administrateur: administrateur)
|
|
|
|
|
end
|
|
|
|
|
|
2022-06-07 13:54:11 +02:00
|
|
|
|
before do
|
|
|
|
|
Flipper.enable(:procedure_revisions, procedure)
|
|
|
|
|
procedure.draft_revision.add_type_de_champ(tdc)
|
|
|
|
|
end
|
|
|
|
|
|
2021-11-23 13:34:48 +01:00
|
|
|
|
scenario 'an admin can publish it again' do
|
2020-09-08 12:35:44 +02:00
|
|
|
|
visit admin_procedures_path(statut: "archivees")
|
2020-03-13 15:32:30 +01:00
|
|
|
|
click_on procedure.libelle
|
2020-07-15 10:48:11 +02:00
|
|
|
|
find('#publish-procedure-link').click
|
2020-03-13 15:32:30 +01:00
|
|
|
|
|
2022-06-07 13:54:11 +02:00
|
|
|
|
expect(page).to have_text('Les modifications suivantes seront appliquées')
|
2020-09-08 12:35:44 +02:00
|
|
|
|
expect(find_field('procedure_path').value).to eq procedure.path
|
|
|
|
|
fill_in 'lien_site_web', with: 'http://some.website'
|
2022-06-07 13:54:11 +02:00
|
|
|
|
find('#publish').click
|
2020-03-13 15:32:30 +01:00
|
|
|
|
|
2023-11-06 17:46:22 +01:00
|
|
|
|
expect(page).to have_text('Votre démarche est désormais publiée !')
|
2020-03-13 15:32:30 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2022-04-25 14:28:52 +02:00
|
|
|
|
|
|
|
|
|
context 'when a procedure has dubious champs' do
|
|
|
|
|
let(:dubious_champs) do
|
|
|
|
|
[
|
2022-08-04 11:39:07 +02:00
|
|
|
|
{ libelle: 'NIR' },
|
|
|
|
|
{ libelle: 'carte bancaire' }
|
2022-04-25 14:28:52 +02:00
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
let(:not_dubious_champs) do
|
2022-08-04 11:39:07 +02:00
|
|
|
|
[{ libelle: 'Prénom' }]
|
2022-04-25 14:28:52 +02:00
|
|
|
|
end
|
|
|
|
|
let!(:procedure) do
|
|
|
|
|
create(:procedure,
|
|
|
|
|
:with_service,
|
|
|
|
|
instructeurs: instructeurs,
|
|
|
|
|
administrateur: administrateur,
|
2022-08-04 11:39:07 +02:00
|
|
|
|
types_de_champ_public: not_dubious_champs + dubious_champs)
|
2022-04-25 14:28:52 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'an admin can publish it, but a warning appears' do
|
|
|
|
|
visit admin_procedures_path(statut: "brouillons")
|
|
|
|
|
click_on procedure.libelle
|
|
|
|
|
find('#publish-procedure-link').click
|
|
|
|
|
|
2023-06-08 10:03:34 +02:00
|
|
|
|
expect(page).to have_content("Attention, certains champs ne peuvent être demandés par l’administration.")
|
2022-04-25 14:28:52 +02:00
|
|
|
|
expect(page).to have_selector(".dubious-champs", count: dubious_champs.size)
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-12-05 18:31:20 +01:00
|
|
|
|
|
|
|
|
|
context 'when the procedure has other validation error' do
|
|
|
|
|
let(:procedure) { create(:procedure, :published, :with_service, :with_type_de_champ, administrateur:) }
|
|
|
|
|
let(:initiated_mail) { create(:initiated_mail, procedure:, body: "Hey!") }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
initiated_mail.body += "\n--invalid balise--"
|
|
|
|
|
initiated_mail.save!(validate: false)
|
|
|
|
|
|
|
|
|
|
procedure.draft_revision.add_type_de_champ(type_champ: :text, libelle: "Nouveau champ")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'an error message prevents the publication' do
|
|
|
|
|
visit admin_procedure_path(procedure)
|
2023-12-05 18:31:42 +01:00
|
|
|
|
expect(page).to have_content('Des problèmes empêchent la publication des modifications')
|
2024-06-05 18:00:19 +02:00
|
|
|
|
expect(page).to have_link(href: edit_admin_procedure_mail_template_path(procedure, Mails::InitiatedMail::SLUG))
|
2023-12-05 18:31:20 +01:00
|
|
|
|
expect(page).to have_button('Publier les modifications', disabled: true)
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-03-13 15:32:30 +01:00
|
|
|
|
end
|