2019-08-06 11:02:54 +02:00
|
|
|
|
describe Instructeurs::DossiersController, type: :controller do
|
2017-09-20 10:42:16 +02:00
|
|
|
|
render_views
|
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
let(:instructeur) { create(:instructeur) }
|
2019-07-29 10:57:21 +02:00
|
|
|
|
let(:administrateur) { create(:administrateur) }
|
|
|
|
|
let(:administration) { create(:administration) }
|
2019-08-06 11:02:54 +02:00
|
|
|
|
let(:instructeurs) { [instructeur] }
|
2021-01-28 13:53:18 +01:00
|
|
|
|
let(:procedure) { create(:procedure, :published, :for_individual, instructeurs: instructeurs) }
|
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, :with_individual, procedure: procedure) }
|
2023-11-23 10:35:31 +01:00
|
|
|
|
let(:dossier_for_tiers) { create(:dossier, :en_construction, :for_tiers_with_notification, procedure: procedure) }
|
|
|
|
|
let(:dossier_for_tiers_without_notif) { create(:dossier, :en_construction, :for_tiers_without_notification, procedure: procedure) }
|
2020-06-30 17:53:54 +02:00
|
|
|
|
let(:fake_justificatif) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
|
2017-06-29 15:31:29 +02:00
|
|
|
|
|
2019-08-07 11:15:16 +02:00
|
|
|
|
before { sign_in(instructeur.user) }
|
2017-07-06 16:33:36 +02:00
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
describe '#attestation' do
|
2017-06-29 15:31:29 +02:00
|
|
|
|
context 'when a dossier has an attestation' do
|
2019-09-10 11:09:51 +02:00
|
|
|
|
let(:dossier) { create(:dossier, :accepte, attestation: create(:attestation, :with_pdf), procedure: procedure) }
|
2017-06-29 15:31:29 +02:00
|
|
|
|
|
2019-12-19 18:29:01 +01:00
|
|
|
|
it 'redirects to a service tmp_url' do
|
2017-06-29 15:31:29 +02:00
|
|
|
|
get :attestation, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
2019-12-19 18:29:01 +01:00
|
|
|
|
expect(response.location).to match '/rails/active_storage/disk/'
|
2017-06-29 15:31:29 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-07-11 15:45:20 +02:00
|
|
|
|
|
2018-09-10 17:52:49 +02:00
|
|
|
|
describe '#send_to_instructeurs' do
|
2018-01-30 19:11:07 +01:00
|
|
|
|
let(:mail) { double("mail") }
|
|
|
|
|
|
|
|
|
|
before do
|
2023-01-17 16:33:48 +01:00
|
|
|
|
allow(mail).to receive(:deliver_later)
|
2018-01-30 19:11:07 +01:00
|
|
|
|
|
2023-01-17 16:33:48 +01:00
|
|
|
|
allow(InstructeurMailer)
|
2018-01-30 19:11:07 +01:00
|
|
|
|
.to receive(:send_dossier)
|
2019-08-06 11:02:54 +02:00
|
|
|
|
.with(instructeur, dossier, recipient)
|
2018-01-30 19:11:07 +01:00
|
|
|
|
.and_return(mail)
|
|
|
|
|
|
|
|
|
|
post(
|
2018-09-10 17:52:49 +02:00
|
|
|
|
:send_to_instructeurs,
|
2018-01-30 19:11:07 +01:00
|
|
|
|
params: {
|
2021-02-11 15:31:10 +01:00
|
|
|
|
recipients: [recipient.id].to_json,
|
2018-01-30 19:11:07 +01:00
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
2023-01-17 16:33:48 +01:00
|
|
|
|
context 'when the recipient belongs to the dossier groupe instructeur' do
|
|
|
|
|
let(:recipient) { instructeur }
|
|
|
|
|
|
|
|
|
|
it do
|
|
|
|
|
expect(InstructeurMailer).to have_received(:send_dossier)
|
|
|
|
|
expect(response).to redirect_to(personnes_impliquees_instructeur_dossier_url)
|
|
|
|
|
expect(recipient.followed_dossiers).to include(dossier)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when the recipient is random' do
|
|
|
|
|
let(:recipient) { create(:instructeur) }
|
|
|
|
|
|
|
|
|
|
it do
|
|
|
|
|
expect(InstructeurMailer).not_to have_received(:send_dossier)
|
|
|
|
|
expect(response).to redirect_to(personnes_impliquees_instructeur_dossier_url)
|
|
|
|
|
expect(recipient.followed_dossiers).not_to include(dossier)
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-01-30 19:11:07 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
describe '#follow' do
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
let(:batch_operation) {}
|
2017-07-26 14:33:48 +02:00
|
|
|
|
before do
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
batch_operation
|
2017-07-26 14:33:48 +02:00
|
|
|
|
patch :follow, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
2017-07-11 15:45:20 +02:00
|
|
|
|
end
|
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
it { expect(instructeur.followed_dossiers).to match([dossier]) }
|
2017-07-26 14:33:48 +02:00
|
|
|
|
it { expect(flash.notice).to eq('Dossier suivi') }
|
2022-03-11 13:55:36 +01:00
|
|
|
|
it { expect(response).to redirect_to(instructeur_procedure_path(dossier.procedure)) }
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
|
|
|
|
|
context 'with dossier in batch_operation' do
|
|
|
|
|
let(:batch_operation) { create(:batch_operation, operation: :archiver, dossiers: [dossier], instructeur: instructeur) }
|
|
|
|
|
it { expect(instructeur.followed_dossiers).to eq([]) }
|
|
|
|
|
it { expect(response).to redirect_to(instructeur_dossier_path(dossier.procedure, dossier)) }
|
2022-12-01 12:15:29 +01:00
|
|
|
|
it { expect(flash.alert).to eq("Votre action n'a pas été effectuée, ce dossier fait parti d'un traitement de masse.") }
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
end
|
2017-07-26 14:33:48 +02:00
|
|
|
|
end
|
2017-07-11 15:56:23 +02:00
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
describe '#unfollow' do
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
let(:batch_operation) {}
|
2017-07-26 14:33:48 +02:00
|
|
|
|
before do
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
batch_operation
|
2019-08-06 11:02:54 +02:00
|
|
|
|
instructeur.followed_dossiers << dossier
|
2017-07-26 14:33:48 +02:00
|
|
|
|
patch :unfollow, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
2019-08-06 11:02:54 +02:00
|
|
|
|
instructeur.reload
|
2017-07-11 15:56:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
it { expect(instructeur.followed_dossiers).to match([]) }
|
2017-07-26 14:33:48 +02:00
|
|
|
|
it { expect(flash.notice).to eq("Vous ne suivez plus le dossier nº #{dossier.id}") }
|
2022-03-11 13:55:36 +01:00
|
|
|
|
it { expect(response).to redirect_to(instructeur_procedure_path(dossier.procedure)) }
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
context 'with dossier in batch_operation' do
|
|
|
|
|
let(:batch_operation) { create(:batch_operation, operation: :archiver, dossiers: [dossier], instructeur: instructeur) }
|
|
|
|
|
it { expect(instructeur.followed_dossiers).to eq([dossier]) }
|
|
|
|
|
it { expect(response).to redirect_to(instructeur_dossier_path(dossier.procedure, dossier)) }
|
2022-12-01 12:15:29 +01:00
|
|
|
|
it { expect(flash.alert).to eq("Votre action n'a pas été effectuée, ce dossier fait parti d'un traitement de masse.") }
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
end
|
2017-07-26 14:33:48 +02:00
|
|
|
|
end
|
2017-07-06 16:33:36 +02:00
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
describe '#archive' do
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
let(:batch_operation) {}
|
2017-07-26 14:33:48 +02:00
|
|
|
|
before do
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
batch_operation
|
2017-07-26 14:33:48 +02:00
|
|
|
|
patch :archive, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
|
|
|
|
dossier.reload
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
instructeur.follow(dossier)
|
2017-07-06 16:33:36 +02:00
|
|
|
|
end
|
|
|
|
|
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
it { expect(dossier.archived).to eq(true) }
|
2022-03-11 13:55:36 +01:00
|
|
|
|
it { expect(response).to redirect_to(instructeur_procedure_path(dossier.procedure)) }
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
|
|
|
|
|
context 'with dossier in batch_operation' do
|
|
|
|
|
let(:batch_operation) { create(:batch_operation, operation: :archiver, dossiers: [dossier], instructeur: instructeur) }
|
|
|
|
|
it { expect(dossier.archived).to eq(false) }
|
|
|
|
|
it { expect(response).to redirect_to(instructeur_dossier_path(dossier.procedure, dossier)) }
|
2022-12-01 12:15:29 +01:00
|
|
|
|
it { expect(flash.alert).to eq("Votre action n'a pas été effectuée, ce dossier fait parti d'un traitement de masse.") }
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
end
|
2017-07-11 15:56:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
describe '#unarchive' do
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
let(:batch_operation) {}
|
2017-07-26 14:33:48 +02:00
|
|
|
|
before do
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
batch_operation
|
2018-03-02 16:27:03 +01:00
|
|
|
|
dossier.update(archived: true)
|
2017-07-26 14:33:48 +02:00
|
|
|
|
patch :unarchive, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
2017-07-11 15:56:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
it { expect(dossier.reload.archived).to eq(false) }
|
2022-03-11 13:55:36 +01:00
|
|
|
|
it { expect(response).to redirect_to(instructeur_procedure_path(dossier.procedure)) }
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
|
|
|
|
|
context 'with dossier in batch_operation' do
|
|
|
|
|
let!(:batch_operation) { create(:batch_operation, operation: :archiver, dossiers: [dossier], instructeur: instructeur) }
|
|
|
|
|
it { expect(dossier.reload.archived).to eq(true) }
|
|
|
|
|
it { expect(response).to redirect_to(instructeur_dossier_path(dossier.procedure, dossier)) }
|
2022-12-01 12:15:29 +01:00
|
|
|
|
it { expect(flash.alert).to eq("Votre action n'a pas été effectuée, ce dossier fait parti d'un traitement de masse.") }
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
end
|
2017-07-26 14:33:48 +02:00
|
|
|
|
end
|
2017-07-06 16:33:36 +02:00
|
|
|
|
|
2017-11-30 17:11:46 +01:00
|
|
|
|
describe '#passer_en_instruction' do
|
2019-07-08 17:58:45 +02:00
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
let(:batch_operation) {}
|
2017-11-30 17:11:46 +01:00
|
|
|
|
before do
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
batch_operation
|
2019-08-07 11:15:16 +02:00
|
|
|
|
sign_in(instructeur.user)
|
2022-05-06 11:59:28 +02:00
|
|
|
|
post :passer_en_instruction, params: { procedure_id: procedure.id, dossier_id: dossier.id }, format: :turbo_stream
|
2017-11-30 17:11:46 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-07-08 17:58:45 +02:00
|
|
|
|
it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) }
|
2019-08-06 11:02:54 +02:00
|
|
|
|
it { expect(instructeur.follow?(dossier)).to be true }
|
2019-07-08 17:58:45 +02:00
|
|
|
|
it { expect(response).to have_http_status(:ok) }
|
2023-02-28 17:28:17 +01:00
|
|
|
|
it { expect(response.body).to include('header-top') }
|
2019-07-08 17:58:45 +02:00
|
|
|
|
|
|
|
|
|
context 'when the dossier has already been put en_instruction' do
|
|
|
|
|
let(:dossier) { create(:dossier, :en_instruction, procedure: procedure) }
|
|
|
|
|
|
2019-12-19 13:25:32 +01:00
|
|
|
|
it 'warns about the error' do
|
2019-07-08 17:58:45 +02:00
|
|
|
|
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction))
|
|
|
|
|
expect(response).to have_http_status(:ok)
|
2023-04-18 13:09:22 +02:00
|
|
|
|
expect(response.body).to include('Le dossier est déjà en instruction.')
|
2019-12-19 13:25:32 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when the dossier has already been closed' do
|
|
|
|
|
let(:dossier) { create(:dossier, :accepte, procedure: procedure) }
|
|
|
|
|
|
|
|
|
|
it 'doesn’t change the dossier state' do
|
|
|
|
|
expect(dossier.reload.state).to eq(Dossier.states.fetch(:accepte))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'warns about the error' do
|
|
|
|
|
expect(response).to have_http_status(:ok)
|
2023-04-18 13:09:22 +02:00
|
|
|
|
expect(response.body).to include('Le dossier est en ce moment accepté : il n’est pas possible de le passer en instruction.')
|
2019-07-08 17:58:45 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
|
|
|
|
|
context 'with dossier in batch_operation' do
|
|
|
|
|
let(:batch_operation) { create(:batch_operation, operation: :archiver, dossiers: [dossier], instructeur: instructeur) }
|
|
|
|
|
|
|
|
|
|
it { expect(response).to redirect_to(instructeur_dossier_path(dossier.procedure, dossier)) }
|
2022-12-01 12:15:29 +01:00
|
|
|
|
it { expect(flash.alert).to eq("Votre action n'a pas été effectuée, ce dossier fait parti d'un traitement de masse.") }
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
end
|
2017-11-30 17:11:46 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-11-30 17:18:06 +01:00
|
|
|
|
describe '#repasser_en_construction' do
|
2019-07-11 11:47:37 +02:00
|
|
|
|
let(:dossier) { create(:dossier, :en_instruction, procedure: procedure) }
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
let(:batch_operation) {}
|
2017-11-30 17:18:06 +01:00
|
|
|
|
before do
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
batch_operation
|
2019-08-07 11:15:16 +02:00
|
|
|
|
sign_in(instructeur.user)
|
2019-07-11 11:47:37 +02:00
|
|
|
|
post :repasser_en_construction,
|
|
|
|
|
params: { procedure_id: procedure.id, dossier_id: dossier.id },
|
2022-05-06 11:59:28 +02:00
|
|
|
|
format: :turbo_stream
|
2017-11-30 17:18:06 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-07-11 11:47:37 +02:00
|
|
|
|
it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_construction)) }
|
|
|
|
|
it { expect(response).to have_http_status(:ok) }
|
2023-02-28 17:28:17 +01:00
|
|
|
|
it { expect(response.body).to include('header-top') }
|
2017-11-30 17:18:06 +01:00
|
|
|
|
|
2019-07-11 11:47:37 +02:00
|
|
|
|
context 'when the dossier has already been put en_construction' do
|
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
2017-11-30 17:18:06 +01:00
|
|
|
|
|
2019-12-19 13:25:32 +01:00
|
|
|
|
it 'warns about the error' do
|
2019-07-11 11:47:37 +02:00
|
|
|
|
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_construction))
|
|
|
|
|
expect(response).to have_http_status(:ok)
|
2023-04-18 13:09:22 +02:00
|
|
|
|
expect(response.body).to include('Le dossier est déjà en construction.')
|
2019-07-11 11:47:37 +02:00
|
|
|
|
end
|
2017-11-30 17:18:06 +01:00
|
|
|
|
end
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
|
|
|
|
|
context 'with dossier in batch_operation' do
|
|
|
|
|
let(:batch_operation) { create(:batch_operation, operation: :archiver, dossiers: [dossier], instructeur: instructeur) }
|
|
|
|
|
it { expect(dossier.reload.state).to eq('en_instruction') }
|
|
|
|
|
it { expect(response).to redirect_to(instructeur_dossier_path(dossier.procedure, dossier)) }
|
2022-12-01 12:15:29 +01:00
|
|
|
|
it { expect(flash.alert).to eq("Votre action n'a pas été effectuée, ce dossier fait parti d'un traitement de masse.") }
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
end
|
2017-11-30 17:18:06 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-07-11 11:52:24 +02:00
|
|
|
|
describe '#repasser_en_instruction' do
|
|
|
|
|
let(:dossier) { create(:dossier, :refuse, procedure: procedure) }
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
let(:batch_operation) {}
|
2019-08-07 11:15:16 +02:00
|
|
|
|
let(:current_user) { instructeur.user }
|
2019-07-11 11:52:24 +02:00
|
|
|
|
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
before do
|
|
|
|
|
sign_in current_user
|
|
|
|
|
batch_operation
|
2021-11-29 11:34:42 +01:00
|
|
|
|
post :repasser_en_instruction,
|
|
|
|
|
params: { procedure_id: procedure.id, dossier_id: dossier.id },
|
2022-05-06 11:59:28 +02:00
|
|
|
|
format: :turbo_stream
|
2021-11-29 11:34:42 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when the dossier is refuse' do
|
|
|
|
|
it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) }
|
|
|
|
|
it { expect(response).to have_http_status(:ok) }
|
2023-02-28 17:28:17 +01:00
|
|
|
|
it { expect(response.body).to include('header-top') }
|
2021-11-29 11:34:42 +01:00
|
|
|
|
end
|
2019-07-11 11:52:24 +02:00
|
|
|
|
|
|
|
|
|
context 'when the dossier has already been put en_instruction' do
|
|
|
|
|
let(:dossier) { create(:dossier, :en_instruction, procedure: procedure) }
|
|
|
|
|
|
2019-12-19 13:25:32 +01:00
|
|
|
|
it 'warns about the error' do
|
2019-07-11 11:52:24 +02:00
|
|
|
|
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction))
|
|
|
|
|
expect(response).to have_http_status(:ok)
|
2023-04-18 13:09:22 +02:00
|
|
|
|
expect(response.body).to include('Le dossier est déjà en instruction.')
|
2019-07-11 11:52:24 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2019-07-29 10:57:21 +02:00
|
|
|
|
|
|
|
|
|
context 'when the dossier is accepte' do
|
|
|
|
|
let(:dossier) { create(:dossier, :accepte, procedure: procedure) }
|
|
|
|
|
|
2019-10-02 11:29:30 +02:00
|
|
|
|
it 'it is possible to go back to en_instruction as instructeur' do
|
|
|
|
|
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction))
|
2019-07-29 10:57:21 +02:00
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
|
end
|
|
|
|
|
end
|
2021-11-29 11:34:42 +01:00
|
|
|
|
|
|
|
|
|
context 'when the dossier is done and the user delete it' do
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
let!(:dossier) { create(:dossier, :accepte, procedure: procedure, user: current_user, hidden_by_user_at: Time.zone.now) }
|
2021-11-29 11:34:42 +01:00
|
|
|
|
|
|
|
|
|
it 'reveals the dossier' do
|
|
|
|
|
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction))
|
|
|
|
|
expect(dossier.reload.hidden_by_user_at).to be_nil
|
|
|
|
|
end
|
|
|
|
|
end
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
|
|
|
|
|
context 'with dossier in batch_operation' do
|
|
|
|
|
let(:batch_operation) { create(:batch_operation, operation: :archiver, dossiers: [dossier], instructeur: instructeur) }
|
|
|
|
|
it { expect(dossier.reload.state).to eq('refuse') }
|
|
|
|
|
it { expect(response).to redirect_to(instructeur_dossier_path(dossier.procedure, dossier)) }
|
2022-12-01 12:15:29 +01:00
|
|
|
|
it { expect(flash.alert).to eq("Votre action n'a pas été effectuée, ce dossier fait parti d'un traitement de masse.") }
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
end
|
2019-07-11 11:52:24 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-12-01 12:57:01 +01:00
|
|
|
|
describe '#terminer' do
|
2017-11-30 17:29:26 +01:00
|
|
|
|
context "with refuser" do
|
2017-12-01 12:57:01 +01:00
|
|
|
|
before do
|
2021-11-26 12:19:40 +01:00
|
|
|
|
dossier.passer_en_instruction!(instructeur: instructeur)
|
2019-08-07 11:15:16 +02:00
|
|
|
|
sign_in(instructeur.user)
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-02-18 17:52:15 +01:00
|
|
|
|
context 'simple refusal' do
|
2022-05-06 11:59:28 +02:00
|
|
|
|
subject { post :terminer, params: { process_action: "refuser", procedure_id: procedure.id, dossier_id: dossier.id }, format: :turbo_stream }
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
2019-02-18 17:52:15 +01:00
|
|
|
|
it 'change state to refuse' do
|
|
|
|
|
subject
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
2019-02-18 17:52:15 +01:00
|
|
|
|
dossier.reload
|
|
|
|
|
expect(dossier.state).to eq(Dossier.states.fetch(:refuse))
|
|
|
|
|
expect(dossier.justificatif_motivation).to_not be_attached
|
|
|
|
|
end
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
2019-02-18 17:52:15 +01:00
|
|
|
|
it 'Notification email is sent' do
|
2021-04-29 19:10:22 +02:00
|
|
|
|
expect(NotificationMailer).to receive(:send_refuse_notification)
|
2019-02-18 17:52:15 +01:00
|
|
|
|
.with(dossier).and_return(NotificationMailer)
|
|
|
|
|
expect(NotificationMailer).to receive(:deliver_later)
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
2019-02-18 17:52:15 +01:00
|
|
|
|
subject
|
|
|
|
|
end
|
2023-07-07 14:06:10 +02:00
|
|
|
|
|
|
|
|
|
it 'creates a commentaire' do
|
|
|
|
|
expect { subject }.to change { Commentaire.count }.by(1)
|
|
|
|
|
end
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-02-18 17:52:15 +01:00
|
|
|
|
context 'refusal with a justificatif' do
|
2022-05-06 11:59:28 +02:00
|
|
|
|
subject { post :terminer, params: { process_action: "refuser", procedure_id: procedure.id, dossier_id: dossier.id, dossier: { justificatif_motivation: fake_justificatif } }, format: :turbo_stream }
|
2019-02-18 17:52:15 +01:00
|
|
|
|
|
|
|
|
|
it 'attachs a justificatif' do
|
|
|
|
|
subject
|
|
|
|
|
|
|
|
|
|
dossier.reload
|
|
|
|
|
expect(dossier.state).to eq(Dossier.states.fetch(:refuse))
|
|
|
|
|
expect(dossier.justificatif_motivation).to be_attached
|
|
|
|
|
end
|
|
|
|
|
|
2023-02-28 17:28:17 +01:00
|
|
|
|
it { expect(subject.body).to include('header-top') }
|
2019-02-18 17:52:15 +01:00
|
|
|
|
end
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
|
|
|
|
|
context 'with dossier in batch_operation' do
|
|
|
|
|
let!(:batch_operation) { create(:batch_operation, operation: :archiver, dossiers: [dossier], instructeur: instructeur) }
|
|
|
|
|
subject { post :terminer, params: { process_action: "refuser", procedure_id: procedure.id, dossier_id: dossier.id }, format: :turbo_stream }
|
|
|
|
|
|
|
|
|
|
it { expect { subject }.not_to change { dossier.reload.state } }
|
|
|
|
|
it { is_expected.to redirect_to(instructeur_dossier_path(dossier.procedure, dossier)) }
|
|
|
|
|
it 'flashes message' do
|
|
|
|
|
subject
|
2022-12-01 12:15:29 +01:00
|
|
|
|
expect(flash.alert).to eq("Votre action n'a pas été effectuée, ce dossier fait parti d'un traitement de masse.")
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
2023-11-23 10:35:31 +01:00
|
|
|
|
context "with for_tiers" do
|
|
|
|
|
before do
|
|
|
|
|
dossier_for_tiers.passer_en_instruction!(instructeur: instructeur)
|
|
|
|
|
sign_in(instructeur.user)
|
|
|
|
|
end
|
|
|
|
|
context 'without continuation' do
|
|
|
|
|
subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure.id, dossier_id: dossier_for_tiers.id }, format: :turbo_stream }
|
|
|
|
|
|
|
|
|
|
it 'Notification email is sent' do
|
|
|
|
|
expect(NotificationMailer).to receive(:send_sans_suite_notification)
|
|
|
|
|
.with(dossier_for_tiers).and_return(NotificationMailer)
|
|
|
|
|
expect(NotificationMailer).to receive(:deliver_later)
|
|
|
|
|
|
|
|
|
|
expect(NotificationMailer).to receive(:send_notification_for_tiers)
|
|
|
|
|
.with(dossier_for_tiers).and_return(NotificationMailer)
|
|
|
|
|
expect(NotificationMailer).to receive(:deliver_later)
|
|
|
|
|
|
|
|
|
|
subject
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it '2 emails are sent' do
|
|
|
|
|
expect { perform_enqueued_jobs { subject } }.to change { ActionMailer::Base.deliveries.count }.by(2)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "with for_tiers_without_notif" do
|
|
|
|
|
before do
|
|
|
|
|
dossier_for_tiers_without_notif.passer_en_instruction!(instructeur: instructeur)
|
|
|
|
|
sign_in(instructeur.user)
|
|
|
|
|
end
|
|
|
|
|
context 'without continuation' do
|
|
|
|
|
subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure.id, dossier_id: dossier_for_tiers_without_notif.id }, format: :turbo_stream }
|
|
|
|
|
|
|
|
|
|
it 'Notification email is sent' do
|
|
|
|
|
expect(NotificationMailer).to receive(:send_sans_suite_notification)
|
|
|
|
|
.with(dossier_for_tiers_without_notif).and_return(NotificationMailer)
|
|
|
|
|
expect(NotificationMailer).to receive(:deliver_later)
|
|
|
|
|
|
|
|
|
|
expect(NotificationMailer).to receive(:send_notification_for_tiers)
|
|
|
|
|
.with(dossier_for_tiers_without_notif).and_return(NotificationMailer)
|
|
|
|
|
expect(NotificationMailer).to receive(:deliver_later)
|
|
|
|
|
|
|
|
|
|
subject
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'only one email is sent' do
|
|
|
|
|
expect { perform_enqueued_jobs { subject } }.to change { ActionMailer::Base.deliveries.count }.by(1)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-11-30 17:29:26 +01:00
|
|
|
|
context "with classer_sans_suite" do
|
2017-12-01 12:57:01 +01:00
|
|
|
|
before do
|
2021-11-26 12:19:40 +01:00
|
|
|
|
dossier.passer_en_instruction!(instructeur: instructeur)
|
2019-08-07 11:15:16 +02:00
|
|
|
|
sign_in(instructeur.user)
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
2019-02-18 17:52:15 +01:00
|
|
|
|
context 'without attachment' do
|
2022-05-06 11:59:28 +02:00
|
|
|
|
subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure.id, dossier_id: dossier.id }, format: :turbo_stream }
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
2019-02-18 17:52:15 +01:00
|
|
|
|
it 'change state to sans_suite' do
|
|
|
|
|
subject
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
2019-02-18 17:52:15 +01:00
|
|
|
|
dossier.reload
|
|
|
|
|
expect(dossier.state).to eq(Dossier.states.fetch(:sans_suite))
|
|
|
|
|
expect(dossier.justificatif_motivation).to_not be_attached
|
|
|
|
|
end
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
2019-02-18 17:52:15 +01:00
|
|
|
|
it 'Notification email is sent' do
|
2021-04-29 19:10:22 +02:00
|
|
|
|
expect(NotificationMailer).to receive(:send_sans_suite_notification)
|
2019-02-18 17:52:15 +01:00
|
|
|
|
.with(dossier).and_return(NotificationMailer)
|
|
|
|
|
expect(NotificationMailer).to receive(:deliver_later)
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
2023-11-23 10:35:31 +01:00
|
|
|
|
expect(NotificationMailer).not_to receive(:send_notification_for_tiers)
|
|
|
|
|
.with(dossier)
|
|
|
|
|
|
2019-02-18 17:52:15 +01:00
|
|
|
|
subject
|
|
|
|
|
end
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
2023-02-28 17:28:17 +01:00
|
|
|
|
it { expect(subject.body).to include('header-top') }
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-02-18 17:52:15 +01:00
|
|
|
|
context 'with attachment' do
|
2022-05-06 11:59:28 +02:00
|
|
|
|
subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure.id, dossier_id: dossier.id, dossier: { justificatif_motivation: fake_justificatif } }, format: :turbo_stream }
|
2019-02-18 17:52:15 +01:00
|
|
|
|
|
|
|
|
|
it 'change state to sans_suite' do
|
|
|
|
|
subject
|
|
|
|
|
|
|
|
|
|
dossier.reload
|
|
|
|
|
expect(dossier.state).to eq(Dossier.states.fetch(:sans_suite))
|
|
|
|
|
expect(dossier.justificatif_motivation).to be_attached
|
|
|
|
|
end
|
|
|
|
|
|
2023-02-28 17:28:17 +01:00
|
|
|
|
it { expect(subject.body).to include('header-top') }
|
2019-02-18 17:52:15 +01:00
|
|
|
|
end
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-11-30 17:29:26 +01:00
|
|
|
|
context "with accepter" do
|
2017-12-01 12:57:01 +01:00
|
|
|
|
before do
|
2021-11-26 12:19:40 +01:00
|
|
|
|
dossier.passer_en_instruction!(instructeur: instructeur)
|
2019-08-07 11:15:16 +02:00
|
|
|
|
sign_in(instructeur.user)
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
2021-04-29 19:10:22 +02:00
|
|
|
|
expect(NotificationMailer).to receive(:send_accepte_notification)
|
2018-05-25 23:08:47 +02:00
|
|
|
|
.with(dossier)
|
2017-12-01 12:57:01 +01:00
|
|
|
|
.and_return(NotificationMailer)
|
|
|
|
|
|
2018-05-25 18:05:28 +02:00
|
|
|
|
expect(NotificationMailer).to receive(:deliver_later)
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
2022-05-06 11:59:28 +02:00
|
|
|
|
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id }, format: :turbo_stream }
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
2017-12-04 18:00:12 +01:00
|
|
|
|
it 'change state to accepte' do
|
2017-12-01 12:57:01 +01:00
|
|
|
|
subject
|
|
|
|
|
|
|
|
|
|
dossier.reload
|
2018-08-28 14:10:55 +02:00
|
|
|
|
expect(dossier.state).to eq(Dossier.states.fetch(:accepte))
|
2019-02-18 17:52:15 +01:00
|
|
|
|
expect(dossier.justificatif_motivation).to_not be_attached
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when the dossier does not have any attestation' do
|
|
|
|
|
it 'Notification email is sent' do
|
|
|
|
|
subject
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when the dossier has an attestation' do
|
|
|
|
|
before do
|
|
|
|
|
attestation = Attestation.new
|
2020-12-08 16:34:38 +01:00
|
|
|
|
allow(attestation).to receive(:pdf).and_return(double(read: 'pdf', size: 2.megabytes, attached?: false))
|
2020-09-14 22:31:09 +02:00
|
|
|
|
allow(attestation).to receive(:pdf_url).and_return('http://some_document_url')
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
|
|
|
|
allow_any_instance_of(Dossier).to receive(:build_attestation).and_return(attestation)
|
|
|
|
|
end
|
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
it 'The instructeur is sent back to the dossier page' do
|
2023-02-28 17:28:17 +01:00
|
|
|
|
expect(subject.body).to include('header-top')
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
2018-07-25 17:16:24 +02:00
|
|
|
|
|
|
|
|
|
context 'and the dossier has already an attestation' do
|
|
|
|
|
it 'should not crash' do
|
|
|
|
|
dossier.attestation = Attestation.new
|
|
|
|
|
dossier.save
|
2023-02-28 17:28:17 +01:00
|
|
|
|
expect(subject.body).to include('header-top')
|
2018-07-25 17:16:24 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
2017-12-21 17:21:31 +01:00
|
|
|
|
|
2017-12-22 16:42:21 +01:00
|
|
|
|
context 'when the attestation template uses the motivation field' do
|
2017-12-21 17:21:31 +01:00
|
|
|
|
let(:emailable) { false }
|
|
|
|
|
let(:template) { create(:attestation_template) }
|
2021-01-28 13:53:18 +01:00
|
|
|
|
let(:procedure) { create(:procedure, :published, :for_individual, attestation_template: template, instructeurs: [instructeur]) }
|
2017-12-21 17:21:31 +01:00
|
|
|
|
|
|
|
|
|
subject do
|
2018-01-15 15:34:26 +01:00
|
|
|
|
post :terminer, params: {
|
|
|
|
|
process_action: "accepter",
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id,
|
|
|
|
|
dossier: { motivation: "Yallah" }
|
2022-05-06 11:59:28 +02:00
|
|
|
|
}, format: :turbo_stream
|
2017-12-21 17:21:31 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
expect_any_instance_of(AttestationTemplate)
|
|
|
|
|
.to receive(:attestation_for)
|
2021-11-04 19:05:04 +01:00
|
|
|
|
.with(have_attributes(motivation: "Yallah"))
|
2017-12-21 17:21:31 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { subject }
|
|
|
|
|
end
|
2019-02-18 17:52:15 +01:00
|
|
|
|
|
|
|
|
|
context 'with an attachment' do
|
2022-05-06 11:59:28 +02:00
|
|
|
|
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id, dossier: { justificatif_motivation: fake_justificatif } }, format: :turbo_stream }
|
2019-02-18 17:52:15 +01:00
|
|
|
|
|
|
|
|
|
it 'change state to accepte' do
|
|
|
|
|
subject
|
|
|
|
|
|
|
|
|
|
dossier.reload
|
|
|
|
|
expect(dossier.state).to eq(Dossier.states.fetch(:accepte))
|
|
|
|
|
expect(dossier.justificatif_motivation).to be_attached
|
|
|
|
|
end
|
|
|
|
|
|
2023-02-28 17:28:17 +01:00
|
|
|
|
it { expect(subject.body).to include('header-top') }
|
2019-02-18 17:52:15 +01:00
|
|
|
|
end
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
2019-07-11 11:37:59 +02:00
|
|
|
|
|
2022-09-21 15:05:54 +02:00
|
|
|
|
context 'when related etablissement is still in degraded_mode' do
|
|
|
|
|
let(:procedure) { create(:procedure, :published, for_individual: false, instructeurs: instructeurs) }
|
|
|
|
|
let(:dossier) { create(:dossier, :en_instruction, :with_entreprise, procedure: procedure, as_degraded_mode: true) }
|
|
|
|
|
|
|
|
|
|
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id }, format: :turbo_stream }
|
|
|
|
|
|
|
|
|
|
context "with accepter" do
|
|
|
|
|
it 'warns about the error' do
|
|
|
|
|
subject
|
|
|
|
|
dossier.reload
|
|
|
|
|
expect(dossier.state).to eq(Dossier.states.fetch(:en_instruction))
|
|
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
|
expect(response.body).to match(/Les données relatives au SIRET .+ de le passer accepté/)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-07-11 11:37:59 +02:00
|
|
|
|
context 'when a dossier is already closed' do
|
|
|
|
|
let(:dossier) { create(:dossier, :accepte, procedure: procedure) }
|
|
|
|
|
|
2019-12-19 13:25:32 +01:00
|
|
|
|
before { allow(dossier).to receive(:after_accepter) }
|
2019-07-11 11:37:59 +02:00
|
|
|
|
|
2022-05-06 11:59:28 +02:00
|
|
|
|
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id, dossier: { justificatif_motivation: fake_justificatif } }, format: :turbo_stream }
|
2019-07-11 11:37:59 +02:00
|
|
|
|
|
|
|
|
|
it 'does not close it again' do
|
|
|
|
|
subject
|
|
|
|
|
|
2019-12-19 13:25:32 +01:00
|
|
|
|
expect(dossier).not_to have_received(:after_accepter)
|
|
|
|
|
expect(dossier.state).to eq(Dossier.states.fetch(:accepte))
|
|
|
|
|
|
2019-07-11 11:37:59 +02:00
|
|
|
|
expect(response).to have_http_status(:ok)
|
2022-05-06 11:59:28 +02:00
|
|
|
|
expect(response.body).to include('Le dossier est déjà accepté.')
|
2019-07-11 11:37:59 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
2023-04-13 19:10:09 +02:00
|
|
|
|
describe '#pending_correction' do
|
2023-03-14 17:23:17 +01:00
|
|
|
|
let(:message) { 'do that' }
|
|
|
|
|
let(:justificatif) { nil }
|
2023-07-12 12:00:52 +02:00
|
|
|
|
let(:reason) { nil }
|
2023-03-14 17:23:17 +01:00
|
|
|
|
|
|
|
|
|
subject do
|
2023-04-13 19:10:09 +02:00
|
|
|
|
post :pending_correction, params: {
|
2023-03-14 17:23:17 +01:00
|
|
|
|
procedure_id: procedure.id, dossier_id: dossier.id,
|
2023-06-14 13:14:19 +02:00
|
|
|
|
dossier: { motivation: message, justificatif_motivation: justificatif },
|
2023-07-12 12:00:52 +02:00
|
|
|
|
reason:
|
2023-03-14 17:23:17 +01:00
|
|
|
|
}, format: :turbo_stream
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-14 18:48:19 +01:00
|
|
|
|
before do
|
|
|
|
|
sign_in(instructeur.user)
|
2023-06-20 18:14:34 +02:00
|
|
|
|
expect(controller.current_instructeur).to receive(:mark_tab_as_seen).with(dossier, :messagerie)
|
|
|
|
|
end
|
2023-03-14 18:48:19 +01:00
|
|
|
|
|
2023-06-20 18:14:34 +02:00
|
|
|
|
context "dossier en instruction sends an email to user" do
|
|
|
|
|
let(:dossier) { create(:dossier, :en_instruction, :with_individual, procedure:) }
|
2023-04-04 10:32:36 +02:00
|
|
|
|
|
2023-06-20 18:14:34 +02:00
|
|
|
|
it { expect { subject }.to have_enqueued_mail(DossierMailer, :notify_pending_correction) }
|
2023-03-14 18:48:19 +01:00
|
|
|
|
end
|
2023-03-14 17:23:17 +01:00
|
|
|
|
|
|
|
|
|
context "dossier en instruction" do
|
|
|
|
|
let(:dossier) { create(:dossier, :en_instruction, :with_individual, procedure: procedure) }
|
|
|
|
|
|
|
|
|
|
before { subject }
|
|
|
|
|
|
2023-04-03 17:05:54 +02:00
|
|
|
|
it 'pass en_construction and create a pending correction' do
|
2023-03-14 17:23:17 +01:00
|
|
|
|
expect(response).to have_http_status(:ok)
|
2023-04-13 19:10:09 +02:00
|
|
|
|
expect(response.body).to include('en attente de correction')
|
2023-03-14 17:23:17 +01:00
|
|
|
|
|
|
|
|
|
expect(dossier.reload).to be_en_construction
|
2023-04-03 17:05:54 +02:00
|
|
|
|
expect(dossier).to be_pending_correction
|
2023-07-12 12:00:52 +02:00
|
|
|
|
expect(dossier.corrections.last).to be_dossier_incorrect
|
2023-03-14 17:23:17 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'create a comment with text body' do
|
|
|
|
|
expect(dossier.commentaires.last.body).to eq("do that")
|
2023-04-13 19:10:09 +02:00
|
|
|
|
expect(dossier.commentaires.last).to be_flagged_pending_correction
|
2023-03-14 17:23:17 +01:00
|
|
|
|
end
|
|
|
|
|
|
2023-06-14 13:14:19 +02:00
|
|
|
|
context 'flagged as incomplete' do
|
2023-07-12 12:00:52 +02:00
|
|
|
|
let(:reason) { 'incomplete' }
|
2023-06-14 13:14:19 +02:00
|
|
|
|
|
2023-07-12 12:00:52 +02:00
|
|
|
|
it 'create a correction of incomplete reason' do
|
|
|
|
|
expect(dossier.corrections.last).to be_dossier_incomplete
|
2023-06-14 13:14:19 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-14 17:23:17 +01:00
|
|
|
|
context 'with an attachment' do
|
|
|
|
|
let(:justificatif) { fake_justificatif }
|
|
|
|
|
|
|
|
|
|
it 'attach file to comment' do
|
|
|
|
|
expect(dossier.commentaires.last.piece_jointe).to be_attached
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-06-02 12:43:08 +02:00
|
|
|
|
context 'with an invalid comment / attachment' do
|
|
|
|
|
let(:justificatif) { Rack::Test::UploadedFile.new(Rails.root.join('Gemfile.lock'), 'text/lock') }
|
|
|
|
|
|
|
|
|
|
it 'does not save anything' do
|
|
|
|
|
expect(dossier.reload).not_to be_pending_correction
|
|
|
|
|
expect(dossier.commentaires.count).to eq(0)
|
|
|
|
|
expect(response.body).to include('pas d’un type accepté')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-14 17:23:17 +01:00
|
|
|
|
context 'with an empty message' do
|
|
|
|
|
let(:message) { '' }
|
|
|
|
|
|
|
|
|
|
it 'requires a message' do
|
2023-04-03 17:05:54 +02:00
|
|
|
|
expect(dossier.reload).not_to be_pending_correction
|
2023-03-14 17:23:17 +01:00
|
|
|
|
expect(dossier.commentaires.count).to eq(0)
|
|
|
|
|
expect(response.body).to include('Vous devez préciser')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'dossier already having pending corrections' do
|
|
|
|
|
before do
|
2023-04-03 17:05:54 +02:00
|
|
|
|
create(:dossier_correction, dossier:)
|
2023-03-14 17:23:17 +01:00
|
|
|
|
end
|
|
|
|
|
|
2023-04-03 17:05:54 +02:00
|
|
|
|
it 'does not create an new pending correction' do
|
|
|
|
|
expect { subject }.not_to change { DossierCorrection.count }
|
2023-03-14 17:23:17 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'shows a flash alert' do
|
|
|
|
|
subject
|
|
|
|
|
|
|
|
|
|
expect(response.body).to include('')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'dossier en_construction' do
|
2023-04-03 17:05:54 +02:00
|
|
|
|
it 'can create a pending correction' do
|
2023-03-14 17:23:17 +01:00
|
|
|
|
subject
|
2023-04-03 17:05:54 +02:00
|
|
|
|
expect(dossier.reload).to be_pending_correction
|
2023-04-13 19:10:09 +02:00
|
|
|
|
expect(dossier.commentaires.last).to be_flagged_pending_correction
|
2023-03-14 17:23:17 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'dossier is termine' do
|
|
|
|
|
let(:dossier) { create(:dossier, :accepte, :with_individual, procedure: procedure) }
|
|
|
|
|
|
2023-04-03 17:05:54 +02:00
|
|
|
|
it 'does not create a pending correction' do
|
|
|
|
|
expect { subject }.not_to change { DossierCorrection.count }
|
2023-03-14 17:23:17 +01:00
|
|
|
|
expect(response.body).to include('Impossible')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-11-15 11:30:41 +01:00
|
|
|
|
describe '#messagerie' do
|
2022-03-18 11:28:18 +01:00
|
|
|
|
before { expect(controller.current_instructeur).to receive(:mark_tab_as_seen).with(dossier, :messagerie) }
|
2021-11-15 11:30:41 +01:00
|
|
|
|
subject { get :messagerie, params: { procedure_id: procedure.id, dossier_id: dossier.id } }
|
2022-03-18 11:28:18 +01:00
|
|
|
|
it { expect(subject).to have_http_status(:ok) }
|
2021-11-15 11:30:41 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-24 11:45:03 +02:00
|
|
|
|
describe "#create_commentaire" do
|
2017-07-19 14:04:49 +02:00
|
|
|
|
let(:saved_commentaire) { dossier.commentaires.first }
|
2017-11-29 17:11:50 +01:00
|
|
|
|
let(:body) { "avant\napres" }
|
2020-06-30 17:53:54 +02:00
|
|
|
|
let(:file) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
|
2017-11-08 16:37:04 +01:00
|
|
|
|
let(:scan_result) { true }
|
2020-07-22 16:34:33 +02:00
|
|
|
|
let(:now) { Timecop.freeze("09/11/1989") }
|
2017-07-19 14:04:49 +02:00
|
|
|
|
|
2017-11-08 16:37:04 +01:00
|
|
|
|
subject {
|
2017-07-19 14:04:49 +02:00
|
|
|
|
post :create_commentaire, params: {
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id,
|
2017-10-30 16:16:20 +01:00
|
|
|
|
commentaire: {
|
2017-11-07 20:40:00 +01:00
|
|
|
|
body: body,
|
2017-10-30 16:16:20 +01:00
|
|
|
|
file: file
|
|
|
|
|
}
|
2017-07-19 14:04:49 +02:00
|
|
|
|
}
|
2017-11-08 16:37:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
before do
|
2022-03-18 11:28:18 +01:00
|
|
|
|
expect(controller.current_instructeur).to receive(:mark_tab_as_seen).with(dossier, :messagerie)
|
2017-11-08 16:37:04 +01:00
|
|
|
|
allow(ClamavService).to receive(:safe_file?).and_return(scan_result)
|
2020-07-22 16:34:33 +02:00
|
|
|
|
Timecop.freeze(now)
|
2017-07-19 14:04:49 +02:00
|
|
|
|
end
|
|
|
|
|
|
2020-07-22 16:34:33 +02:00
|
|
|
|
after { Timecop.return }
|
|
|
|
|
|
2018-09-04 18:19:29 +02:00
|
|
|
|
it "creates a commentaire" do
|
|
|
|
|
expect { subject }.to change(Commentaire, :count).by(1)
|
2019-08-06 11:02:54 +02:00
|
|
|
|
expect(instructeur.followed_dossiers).to include(dossier)
|
2017-10-30 16:16:20 +01:00
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
expect(response).to redirect_to(messagerie_instructeur_dossier_path(dossier.procedure, dossier))
|
2018-09-04 18:19:29 +02:00
|
|
|
|
expect(flash.notice).to be_present
|
2020-07-22 16:34:33 +02:00
|
|
|
|
expect(dossier.reload.last_commentaire_updated_at).to eq(now)
|
2017-11-07 20:40:00 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-06-25 17:12:44 +02:00
|
|
|
|
context "when the commentaire created with virus file" do
|
2018-09-04 18:19:29 +02:00
|
|
|
|
let(:scan_result) { false }
|
2017-11-08 16:37:04 +01:00
|
|
|
|
|
2019-06-25 17:12:44 +02:00
|
|
|
|
it "creates a commentaire (shows message that file have a virus)" do
|
|
|
|
|
expect { subject }.to change(Commentaire, :count).by(1)
|
2019-08-06 11:02:54 +02:00
|
|
|
|
expect(instructeur.followed_dossiers).to include(dossier)
|
2017-11-08 16:37:04 +01:00
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
expect(response).to redirect_to(messagerie_instructeur_dossier_path(dossier.procedure, dossier))
|
2019-06-25 17:12:44 +02:00
|
|
|
|
expect(flash.notice).to be_present
|
2017-11-08 16:37:04 +01:00
|
|
|
|
end
|
2017-10-30 16:16:20 +01:00
|
|
|
|
end
|
2022-03-17 11:21:45 +01:00
|
|
|
|
|
|
|
|
|
context "when the dossier is deleted by user" do
|
|
|
|
|
let(:dossier) { create(:dossier, :accepte, procedure: procedure) }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
dossier.update!(hidden_by_user_at: 1.hour.ago)
|
|
|
|
|
subject
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "does not create a commentaire" do
|
|
|
|
|
expect { subject }.to change(Commentaire, :count).by(0)
|
|
|
|
|
expect(flash.alert).to be_present
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-07-19 14:04:49 +02:00
|
|
|
|
end
|
2017-08-28 14:16:13 +02:00
|
|
|
|
|
|
|
|
|
describe "#create_avis" do
|
2021-02-28 22:20:24 +01:00
|
|
|
|
let(:expert) { create(:expert) }
|
2021-03-23 12:25:57 +01:00
|
|
|
|
let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: dossier.procedure) }
|
2020-02-11 17:18:49 +01:00
|
|
|
|
let(:invite_linked_dossiers) { false }
|
2017-08-28 14:16:13 +02:00
|
|
|
|
let(:saved_avis) { dossier.avis.first }
|
2018-10-31 20:38:32 +01:00
|
|
|
|
let!(:old_avis_count) { Avis.count }
|
2017-08-28 14:16:13 +02:00
|
|
|
|
|
2022-03-18 11:28:18 +01:00
|
|
|
|
before do
|
|
|
|
|
expect(controller.current_instructeur).to receive(:mark_tab_as_seen).with(dossier, :avis)
|
|
|
|
|
end
|
|
|
|
|
|
2018-02-27 16:58:22 +01:00
|
|
|
|
subject do
|
2017-08-28 14:16:13 +02:00
|
|
|
|
post :create_avis, params: {
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id,
|
2021-02-28 22:20:24 +01:00
|
|
|
|
avis: { emails: emails, introduction: 'intro', confidentiel: true, invite_linked_dossiers: invite_linked_dossiers, claimant: instructeur, experts_procedure: experts_procedure }
|
2017-08-28 14:16:13 +02:00
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2021-03-30 17:55:35 +02:00
|
|
|
|
let(:emails) { "[\"email@a.com\"]" }
|
2018-02-27 16:58:22 +01:00
|
|
|
|
|
2020-09-07 14:55:15 +02:00
|
|
|
|
context "notifications updates" do
|
|
|
|
|
context 'when an instructeur follows the dossier' do
|
|
|
|
|
let(:follower) { create(:instructeur) }
|
|
|
|
|
before { follower.follow(dossier) }
|
2018-02-27 16:58:22 +01:00
|
|
|
|
|
2020-09-07 14:55:15 +02:00
|
|
|
|
it 'the follower has a notification' do
|
2020-09-18 15:40:26 +02:00
|
|
|
|
expect(follower.followed_dossiers.with_notifications).to eq([])
|
2020-09-07 14:55:15 +02:00
|
|
|
|
subject
|
2020-09-18 15:40:26 +02:00
|
|
|
|
expect(follower.followed_dossiers.with_notifications).to eq([dossier.reload])
|
2020-09-07 14:55:15 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2018-02-27 16:58:22 +01:00
|
|
|
|
end
|
2018-10-31 20:38:32 +01:00
|
|
|
|
|
2022-04-06 15:01:07 +02:00
|
|
|
|
context 'as an instructeur, i auto follow the dossier so I get the notifications' do
|
|
|
|
|
it 'works' do
|
|
|
|
|
subject
|
2022-04-06 15:05:03 +02:00
|
|
|
|
expect(instructeur.followed_dossiers).to match_array([dossier])
|
2022-04-06 15:01:07 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2020-09-07 14:55:15 +02:00
|
|
|
|
context 'email sending' do
|
|
|
|
|
before do
|
|
|
|
|
subject
|
|
|
|
|
end
|
2018-10-31 20:38:32 +01:00
|
|
|
|
|
2021-02-28 22:20:24 +01:00
|
|
|
|
it { expect(saved_avis.expert.email).to eq('email@a.com') }
|
2020-09-07 14:55:15 +02:00
|
|
|
|
it { expect(saved_avis.introduction).to eq('intro') }
|
|
|
|
|
it { expect(saved_avis.confidentiel).to eq(true) }
|
|
|
|
|
it { expect(saved_avis.dossier).to eq(dossier) }
|
|
|
|
|
it { expect(saved_avis.claimant).to eq(instructeur) }
|
|
|
|
|
it { expect(response).to redirect_to(avis_instructeur_dossier_path(dossier.procedure, dossier)) }
|
2020-02-11 17:18:49 +01:00
|
|
|
|
|
2020-09-07 14:55:15 +02:00
|
|
|
|
context "with an invalid email" do
|
2021-03-30 17:55:35 +02:00
|
|
|
|
let(:emails) { "[\"emaila.com\"]" }
|
2020-02-11 17:18:49 +01:00
|
|
|
|
|
2020-09-07 14:55:15 +02:00
|
|
|
|
before { subject }
|
2020-02-11 17:18:49 +01:00
|
|
|
|
|
2020-09-07 14:55:15 +02:00
|
|
|
|
it { expect(response).to render_template :avis }
|
2024-02-13 10:37:03 +01:00
|
|
|
|
it { expect(flash.alert).to eq(["emaila.com : Le champ « Email » est invalide. Saisir une adresse électronique valide, exemple : john.doe@exemple.fr"]) }
|
2020-09-07 14:55:15 +02:00
|
|
|
|
it { expect { subject }.not_to change(Avis, :count) }
|
|
|
|
|
it { expect(dossier.last_avis_updated_at).to eq(nil) }
|
2020-02-11 17:18:49 +01:00
|
|
|
|
end
|
|
|
|
|
|
2023-03-10 12:31:49 +01:00
|
|
|
|
context "with no email" do
|
|
|
|
|
let(:emails) { "" }
|
|
|
|
|
|
|
|
|
|
before { subject }
|
|
|
|
|
|
|
|
|
|
it { expect(response).to render_template :avis }
|
2023-03-14 15:05:19 +01:00
|
|
|
|
it { expect(flash.alert).to eq("Le champ « Emails » doit être rempli") }
|
2023-03-10 12:31:49 +01:00
|
|
|
|
it { expect { subject }.not_to change(Avis, :count) }
|
|
|
|
|
it { expect(dossier.last_avis_updated_at).to eq(nil) }
|
|
|
|
|
end
|
|
|
|
|
|
2020-09-07 14:55:15 +02:00
|
|
|
|
context 'with multiple emails' do
|
2021-03-30 17:55:35 +02:00
|
|
|
|
let(:emails) { "[\"toto.fr\",\"titi@titimail.com\"]" }
|
2020-02-11 17:18:49 +01:00
|
|
|
|
|
2020-09-07 14:55:15 +02:00
|
|
|
|
before { subject }
|
2020-02-11 17:18:49 +01:00
|
|
|
|
|
2020-09-07 14:55:15 +02:00
|
|
|
|
it { expect(response).to render_template :avis }
|
2024-02-13 10:37:03 +01:00
|
|
|
|
it { expect(flash.alert).to eq(["toto.fr : Le champ « Email » est invalide. Saisir une adresse électronique valide, exemple : john.doe@exemple.fr"]) }
|
2021-05-26 15:16:30 +02:00
|
|
|
|
it { expect(flash.notice).to eq("Une demande d’avis a été envoyée à titi@titimail.com") }
|
2020-09-07 14:55:15 +02:00
|
|
|
|
it { expect(Avis.count).to eq(old_avis_count + 1) }
|
2021-02-28 22:20:24 +01:00
|
|
|
|
it { expect(saved_avis.expert.email).to eq("titi@titimail.com") }
|
2020-09-07 14:55:15 +02:00
|
|
|
|
end
|
2020-02-11 17:18:49 +01:00
|
|
|
|
|
2020-09-07 14:55:15 +02:00
|
|
|
|
context 'with linked dossiers' do
|
|
|
|
|
let(:asked_confidentiel) { false }
|
|
|
|
|
let(:previous_avis_confidentiel) { false }
|
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, :with_dossier_link, procedure: procedure) }
|
|
|
|
|
before { subject }
|
|
|
|
|
context 'when the expert doesn’t share linked dossiers' do
|
|
|
|
|
let(:invite_linked_dossiers) { false }
|
2020-02-11 17:18:49 +01:00
|
|
|
|
|
|
|
|
|
it 'sends a single avis for the main dossier, but doesn’t give access to the linked dossiers' do
|
2021-05-26 15:16:30 +02:00
|
|
|
|
expect(flash.notice).to eq("Une demande d’avis a été envoyée à email@a.com")
|
2020-02-11 17:18:49 +01:00
|
|
|
|
expect(Avis.count).to eq(old_avis_count + 1)
|
2021-02-28 22:20:24 +01:00
|
|
|
|
expect(saved_avis.expert.email).to eq("email@a.com")
|
2020-02-11 17:18:49 +01:00
|
|
|
|
expect(saved_avis.dossier).to eq(dossier)
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-09-07 14:55:15 +02:00
|
|
|
|
|
|
|
|
|
context 'when the expert also shares the linked dossiers' do
|
|
|
|
|
let(:invite_linked_dossiers) { true }
|
|
|
|
|
|
|
|
|
|
context 'and the expert can access the linked dossiers' do
|
|
|
|
|
let(:saved_avis) { Avis.last(2).first }
|
|
|
|
|
let(:linked_avis) { Avis.last }
|
2022-11-10 22:21:14 +01:00
|
|
|
|
let(:linked_dossier) { Dossier.find_by(id: dossier.reload.champs_public.filter(&:dossier_link?).filter_map(&:value)) }
|
2020-09-07 14:55:15 +02:00
|
|
|
|
let(:invite_linked_dossiers) do
|
|
|
|
|
instructeur.assign_to_procedure(linked_dossier.procedure)
|
|
|
|
|
true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'sends one avis for the main dossier' do
|
2021-05-26 15:16:30 +02:00
|
|
|
|
expect(flash.notice).to eq("Une demande d’avis a été envoyée à email@a.com")
|
2021-02-28 22:20:24 +01:00
|
|
|
|
expect(saved_avis.expert.email).to eq("email@a.com")
|
2020-09-07 14:55:15 +02:00
|
|
|
|
expect(saved_avis.dossier).to eq(dossier)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'sends another avis for the linked dossiers' do
|
|
|
|
|
expect(Avis.count).to eq(old_avis_count + 2)
|
|
|
|
|
expect(linked_avis.dossier).to eq(linked_dossier)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'but the expert can’t access the linked dossier' do
|
|
|
|
|
it 'sends a single avis for the main dossier, but doesn’t give access to the linked dossiers' do
|
2021-05-26 15:16:30 +02:00
|
|
|
|
expect(flash.notice).to eq("Une demande d’avis a été envoyée à email@a.com")
|
2020-09-07 14:55:15 +02:00
|
|
|
|
expect(Avis.count).to eq(old_avis_count + 1)
|
2021-02-28 22:20:24 +01:00
|
|
|
|
expect(saved_avis.expert.email).to eq("email@a.com")
|
2020-09-07 14:55:15 +02:00
|
|
|
|
expect(saved_avis.dossier).to eq(dossier)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-02-11 17:18:49 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2017-08-28 14:16:13 +02:00
|
|
|
|
end
|
2017-08-02 15:33:23 +02:00
|
|
|
|
|
2019-12-16 15:32:59 +01:00
|
|
|
|
describe "#show" do
|
|
|
|
|
context "when the dossier is exported as PDF" do
|
|
|
|
|
let(:instructeur) { create(:instructeur) }
|
2021-02-28 22:20:24 +01:00
|
|
|
|
let(:expert) { create(:expert) }
|
2021-01-28 13:53:18 +01:00
|
|
|
|
let(:procedure) { create(:procedure, :published, instructeurs: instructeurs) }
|
2021-03-23 12:25:57 +01:00
|
|
|
|
let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
|
2020-07-06 11:27:03 +02:00
|
|
|
|
let(:dossier) do
|
|
|
|
|
create(:dossier,
|
|
|
|
|
:accepte,
|
2021-11-03 15:52:53 +01:00
|
|
|
|
:with_populated_champs,
|
|
|
|
|
:with_populated_annotations,
|
2020-07-06 11:27:03 +02:00
|
|
|
|
:with_motivation,
|
|
|
|
|
:with_entreprise,
|
|
|
|
|
:with_commentaires, procedure: procedure)
|
|
|
|
|
end
|
2021-02-28 22:20:24 +01:00
|
|
|
|
let!(:avis) { create(:avis, dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure) }
|
2020-07-06 11:27:03 +02:00
|
|
|
|
|
2019-12-16 15:32:59 +01:00
|
|
|
|
subject do
|
2020-07-06 11:27:03 +02:00
|
|
|
|
avis
|
2019-12-16 15:32:59 +01:00
|
|
|
|
get :show, params: {
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id,
|
|
|
|
|
format: :pdf
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2022-03-18 11:28:18 +01:00
|
|
|
|
before do
|
|
|
|
|
expect(controller.current_instructeur).to receive(:mark_tab_as_seen).with(dossier, :demande)
|
|
|
|
|
subject
|
|
|
|
|
end
|
2020-07-06 11:27:03 +02:00
|
|
|
|
|
2024-03-07 08:39:32 +01:00
|
|
|
|
it { expect(assigns(:acls)).to eq(PiecesJustificativesService.new(user_profile: instructeur).acl_for_dossier_export(dossier.procedure)) }
|
2022-12-01 12:15:29 +01:00
|
|
|
|
it { expect(assigns(:is_dossier_in_batch_operation)).to eq(false) }
|
2019-12-16 15:32:59 +01:00
|
|
|
|
it { expect(response).to render_template 'dossiers/show' }
|
2023-04-04 14:54:29 +02:00
|
|
|
|
|
|
|
|
|
context 'empty champs commune' do
|
2024-01-23 09:52:20 +01:00
|
|
|
|
let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :communes }], instructeurs:) }
|
2023-04-04 14:54:29 +02:00
|
|
|
|
let(:dossier) { create(:dossier, :accepte, procedure:) }
|
|
|
|
|
|
|
|
|
|
it { expect(response).to render_template 'dossiers/show' }
|
|
|
|
|
end
|
2019-12-16 15:32:59 +01:00
|
|
|
|
end
|
2022-12-01 12:15:29 +01:00
|
|
|
|
|
|
|
|
|
context 'with dossier in batch_operation' do
|
|
|
|
|
let!(:batch_operation) { create(:batch_operation, operation: :archiver, dossiers: [dossier], instructeur: instructeur) }
|
|
|
|
|
it 'assigns variable with true value' do
|
|
|
|
|
get :show, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
|
|
|
|
expect(assigns(:is_dossier_in_batch_operation)).to eq(true)
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-12-16 15:32:59 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-08-02 15:33:23 +02:00
|
|
|
|
describe "#update_annotations" do
|
2020-08-27 19:56:48 +02:00
|
|
|
|
let(:procedure) do
|
2022-08-04 11:39:07 +02:00
|
|
|
|
create(:procedure, :published, types_de_champ_private: [
|
|
|
|
|
{ type: :multiple_drop_down_list },
|
|
|
|
|
{ type: :linked_drop_down_list },
|
|
|
|
|
{ type: :datetime },
|
2023-04-21 09:35:16 +02:00
|
|
|
|
{ type: :repetition, children: [{}] },
|
|
|
|
|
{ type: :drop_down_list, options: [:a, :b, :other] }
|
2020-08-27 19:56:48 +02:00
|
|
|
|
], instructeurs: instructeurs)
|
|
|
|
|
end
|
2021-11-03 15:52:53 +01:00
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, :with_populated_annotations, procedure: procedure) }
|
2020-09-07 16:25:40 +02:00
|
|
|
|
let(:another_instructeur) { create(:instructeur) }
|
2020-08-27 19:56:48 +02:00
|
|
|
|
let(:now) { Time.zone.parse('01/01/2100') }
|
|
|
|
|
|
2023-04-21 09:35:16 +02:00
|
|
|
|
let(:champ_multiple_drop_down_list) { dossier.champs_private.first }
|
|
|
|
|
let(:champ_linked_drop_down_list) { dossier.champs_private.second }
|
|
|
|
|
let(:champ_datetime) { dossier.champs_private.third }
|
|
|
|
|
let(:champ_repetition) { dossier.champs_private.fourth }
|
|
|
|
|
let(:champ_drop_down_list) { dossier.champs_private.fifth }
|
2019-03-25 11:08:41 +01:00
|
|
|
|
|
2017-08-02 15:33:23 +02:00
|
|
|
|
before do
|
2022-03-18 11:28:18 +01:00
|
|
|
|
expect(controller.current_instructeur).to receive(:mark_tab_as_seen).with(dossier, :annotations_privees)
|
2020-09-07 16:25:40 +02:00
|
|
|
|
another_instructeur.follow(dossier)
|
2020-07-22 17:11:33 +02:00
|
|
|
|
Timecop.freeze(now)
|
2023-03-01 18:30:10 +01:00
|
|
|
|
patch :update_annotations, params: params, format: :turbo_stream
|
2020-07-22 17:11:33 +02:00
|
|
|
|
|
|
|
|
|
champ_multiple_drop_down_list.reload
|
|
|
|
|
champ_linked_drop_down_list.reload
|
|
|
|
|
champ_datetime.reload
|
|
|
|
|
champ_repetition.reload
|
2023-04-21 09:35:16 +02:00
|
|
|
|
champ_drop_down_list.reload
|
2020-07-22 17:11:33 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
after do
|
|
|
|
|
Timecop.return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "with new values for champs_private" do
|
|
|
|
|
let(:params) do
|
|
|
|
|
{
|
|
|
|
|
procedure_id: procedure.id,
|
2020-08-27 19:56:48 +02:00
|
|
|
|
dossier_id: dossier.id,
|
|
|
|
|
dossier: {
|
|
|
|
|
champs_private_attributes: {
|
|
|
|
|
'0': {
|
|
|
|
|
id: champ_multiple_drop_down_list.id,
|
2023-01-24 15:10:25 +01:00
|
|
|
|
value: ['', 'val1', 'val2']
|
2020-08-27 19:56:48 +02:00
|
|
|
|
},
|
|
|
|
|
'1': {
|
|
|
|
|
id: champ_datetime.id,
|
2023-02-09 15:18:38 +01:00
|
|
|
|
value: '2019-12-21T13:17'
|
2020-08-27 19:56:48 +02:00
|
|
|
|
},
|
|
|
|
|
'2': {
|
|
|
|
|
id: champ_linked_drop_down_list.id,
|
|
|
|
|
primary_value: 'primary',
|
|
|
|
|
secondary_value: 'secondary'
|
|
|
|
|
},
|
|
|
|
|
'3': {
|
2022-11-29 11:30:06 +01:00
|
|
|
|
id: champ_repetition.champs.first.id,
|
|
|
|
|
value: 'text'
|
2023-04-21 09:35:16 +02:00
|
|
|
|
},
|
|
|
|
|
'4': {
|
|
|
|
|
id: champ_drop_down_list.id,
|
|
|
|
|
value: '__other__',
|
|
|
|
|
value_other: 'other value'
|
2019-03-25 11:08:41 +01:00
|
|
|
|
}
|
2017-08-02 15:33:23 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-22 17:11:33 +02:00
|
|
|
|
end
|
2020-08-27 19:56:48 +02:00
|
|
|
|
|
|
|
|
|
it {
|
2023-03-29 23:31:13 +02:00
|
|
|
|
expect(champ_multiple_drop_down_list.value).to eq('["val1","val2"]')
|
2020-08-27 19:56:48 +02:00
|
|
|
|
expect(champ_linked_drop_down_list.primary_value).to eq('primary')
|
|
|
|
|
expect(champ_linked_drop_down_list.secondary_value).to eq('secondary')
|
2023-07-06 02:53:57 +02:00
|
|
|
|
expect(champ_datetime.value).to eq(Time.zone.parse('2019-12-21T13:17:00').iso8601)
|
2020-08-27 19:56:48 +02:00
|
|
|
|
expect(champ_repetition.champs.first.value).to eq('text')
|
2023-04-21 09:35:16 +02:00
|
|
|
|
expect(champ_drop_down_list.value).to eq('other value')
|
2020-08-27 19:56:48 +02:00
|
|
|
|
expect(dossier.reload.last_champ_private_updated_at).to eq(now)
|
2023-03-01 18:30:10 +01:00
|
|
|
|
expect(response).to have_http_status(200)
|
2020-08-27 19:56:48 +02:00
|
|
|
|
}
|
2020-09-07 16:25:40 +02:00
|
|
|
|
|
|
|
|
|
it 'updates the annotations' do
|
|
|
|
|
Timecop.travel(now + 1.hour)
|
2020-09-18 15:40:26 +02:00
|
|
|
|
expect(instructeur.followed_dossiers.with_notifications).to eq([])
|
|
|
|
|
expect(another_instructeur.followed_dossiers.with_notifications).to eq([dossier.reload])
|
2020-09-07 16:25:40 +02:00
|
|
|
|
end
|
2020-07-22 17:11:33 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "without new values for champs_private" do
|
|
|
|
|
let(:params) do
|
|
|
|
|
{
|
|
|
|
|
procedure_id: procedure.id,
|
2020-08-27 19:56:48 +02:00
|
|
|
|
dossier_id: dossier.id,
|
|
|
|
|
dossier: {
|
|
|
|
|
champs_private_attributes: {},
|
2022-11-10 22:21:14 +01:00
|
|
|
|
champs_public_attributes: {
|
2020-08-27 19:56:48 +02:00
|
|
|
|
'0': {
|
|
|
|
|
id: champ_multiple_drop_down_list.id,
|
2023-01-24 15:10:25 +01:00
|
|
|
|
value: ['', 'val1', 'val2']
|
2020-08-27 19:56:48 +02:00
|
|
|
|
}
|
2020-07-22 17:11:33 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
end
|
2020-08-27 19:56:48 +02:00
|
|
|
|
|
|
|
|
|
it {
|
|
|
|
|
expect(dossier.reload.last_champ_private_updated_at).to eq(nil)
|
2023-03-01 18:30:10 +01:00
|
|
|
|
expect(response).to have_http_status(200)
|
2020-08-27 19:56:48 +02:00
|
|
|
|
}
|
2017-08-02 15:33:23 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2019-07-01 15:55:37 +02:00
|
|
|
|
|
|
|
|
|
describe "#telecharger_pjs" do
|
|
|
|
|
subject do
|
|
|
|
|
get :telecharger_pjs, params: {
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id
|
|
|
|
|
}
|
|
|
|
|
end
|
2022-09-05 11:20:30 +02:00
|
|
|
|
|
2023-01-30 18:38:54 +01:00
|
|
|
|
before do
|
2024-02-07 17:33:34 +01:00
|
|
|
|
allow_any_instance_of(PiecesJustificativesService).to receive(:generate_dossiers_export).with([dossier]).and_call_original
|
2023-01-30 18:38:54 +01:00
|
|
|
|
end
|
|
|
|
|
|
2022-09-05 11:20:30 +02:00
|
|
|
|
it 'includes an attachment' do
|
|
|
|
|
expect(subject.headers['Content-Disposition']).to start_with('attachment; ')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'the attachment.zip is extractable' do
|
|
|
|
|
content = ZipTricks::FileReader.read_zip_structure(io: StringIO.new(subject.body))
|
|
|
|
|
file_names = content.map(&:filename)
|
|
|
|
|
expect(file_names.size).to eq(1)
|
|
|
|
|
expect(file_names.first).to start_with("dossier-#{dossier.id}/export-")
|
|
|
|
|
end
|
2019-07-01 15:55:37 +02:00
|
|
|
|
end
|
2020-11-17 13:25:35 +01:00
|
|
|
|
|
2022-03-11 13:57:09 +01:00
|
|
|
|
describe "#destroy" do
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
let(:batch_operation) {}
|
2020-11-17 13:25:35 +01:00
|
|
|
|
subject do
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
batch_operation
|
2022-03-11 13:57:09 +01:00
|
|
|
|
delete :destroy, params: {
|
2020-11-17 13:25:35 +01:00
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
before do
|
2021-11-26 12:19:40 +01:00
|
|
|
|
dossier.passer_en_instruction(instructeur: instructeur)
|
2020-11-17 13:25:35 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'just before delete the dossier, the operation must be equal to 2' do
|
|
|
|
|
before do
|
2021-11-26 12:19:40 +01:00
|
|
|
|
dossier.accepter!(instructeur: instructeur, motivation: 'le dossier est correct')
|
2020-11-17 13:25:35 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'has 2 operations logs before deletion' do
|
|
|
|
|
expect(DossierOperationLog.where(dossier_id: dossier.id).count).to eq(2)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-12-08 12:27:12 +01:00
|
|
|
|
context 'when the instructeur want to delete a dossier with a decision and already hidden by user' do
|
2020-11-17 13:25:35 +01:00
|
|
|
|
before do
|
2021-11-26 12:19:40 +01:00
|
|
|
|
dossier.accepter!(instructeur: instructeur, motivation: "le dossier est correct")
|
2021-12-08 12:27:12 +01:00
|
|
|
|
dossier.update!(hidden_by_user_at: Time.zone.now.beginning_of_day.utc)
|
2020-11-17 13:25:35 +01:00
|
|
|
|
subject
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'deletes previous logs and add a suppression log' do
|
2020-11-26 15:13:32 +01:00
|
|
|
|
expect(DossierOperationLog.where(dossier_id: dossier.id).count).to eq(3)
|
|
|
|
|
expect(DossierOperationLog.where(dossier_id: dossier.id).last.operation).to eq('supprimer')
|
2020-11-17 13:25:35 +01:00
|
|
|
|
end
|
|
|
|
|
|
2022-02-08 11:19:50 +01:00
|
|
|
|
it 'does not add a record into deleted_dossiers table' do
|
|
|
|
|
expect(DeletedDossier.where(dossier_id: dossier.id).count).to eq(0)
|
2020-11-17 13:25:35 +01:00
|
|
|
|
end
|
|
|
|
|
|
2022-03-09 10:29:16 +01:00
|
|
|
|
it 'is not visible by administration' do
|
|
|
|
|
expect(dossier.reload.visible_by_administration?).to be_falsy
|
2020-11-17 13:25:35 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-12-08 12:27:12 +01:00
|
|
|
|
context 'when the instructeur want to delete a dossier with a decision and not hidden by user' do
|
|
|
|
|
before do
|
|
|
|
|
dossier.accepter!(instructeur: instructeur, motivation: "le dossier est correct")
|
|
|
|
|
subject
|
|
|
|
|
end
|
|
|
|
|
|
2022-03-09 10:29:16 +01:00
|
|
|
|
it 'does not deletes previous logs and adds a suppression log' do
|
|
|
|
|
expect(DossierOperationLog.where(dossier_id: dossier.id).count).to eq(3)
|
|
|
|
|
expect(DossierOperationLog.where(dossier_id: dossier.id).last.operation).to eq('supprimer')
|
2021-12-08 12:27:12 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'add a record into deleted_dossiers table' do
|
|
|
|
|
expect(DeletedDossier.where(dossier_id: dossier.id).count).to eq(0)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'does not discard the dossier' do
|
|
|
|
|
expect(dossier.reload.hidden_at).to eq(nil)
|
|
|
|
|
end
|
2022-02-08 11:19:50 +01:00
|
|
|
|
|
|
|
|
|
it 'fill hidden by reason' do
|
|
|
|
|
expect(dossier.reload.hidden_by_reason).not_to eq(nil)
|
|
|
|
|
expect(dossier.reload.hidden_by_reason).to eq("instructeur_request")
|
|
|
|
|
end
|
2021-12-08 12:27:12 +01:00
|
|
|
|
end
|
|
|
|
|
|
2020-11-17 13:25:35 +01:00
|
|
|
|
context 'when the instructeur want to delete a dossier without a decision' do
|
|
|
|
|
before do
|
|
|
|
|
subject
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'does not delete the dossier' do
|
2021-02-23 08:25:24 +01:00
|
|
|
|
expect { dossier.reload }.not_to raise_error # A deleted dossier would raise an ActiveRecord::RecordNotFound
|
2020-11-17 13:25:35 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'does not add a record into deleted_dossiers table' do
|
|
|
|
|
expect(DeletedDossier.where(dossier_id: dossier.id).count).to eq(0)
|
|
|
|
|
end
|
|
|
|
|
end
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
|
|
|
|
|
context 'with dossier in batch_operation' do
|
|
|
|
|
let(:batch_operation) { create(:batch_operation, operation: :archiver, dossiers: [dossier], instructeur: instructeur) }
|
|
|
|
|
it { expect { subject }.not_to change { dossier.reload.hidden_at } }
|
|
|
|
|
it { is_expected.to redirect_to(instructeur_dossier_path(dossier.procedure, dossier)) }
|
|
|
|
|
it 'flashes message' do
|
|
|
|
|
subject
|
2022-12-01 12:15:29 +01:00
|
|
|
|
expect(flash.alert).to eq("Votre action n'a pas été effectuée, ce dossier fait parti d'un traitement de masse.")
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2020-11-17 13:25:35 +01:00
|
|
|
|
end
|
2021-12-03 16:09:51 +01:00
|
|
|
|
|
|
|
|
|
describe '#extend_conservation' do
|
|
|
|
|
subject { post :extend_conservation, params: { procedure_id: procedure.id, dossier_id: dossier.id } }
|
|
|
|
|
context 'when user logged in' do
|
|
|
|
|
it 'works' do
|
|
|
|
|
expect(subject).to redirect_to(instructeur_dossier_path(procedure, dossier))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'extends conservation_extension by 1 month' do
|
|
|
|
|
subject
|
|
|
|
|
expect(dossier.reload.conservation_extension).to eq(1.month)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'flashed notice success' do
|
|
|
|
|
subject
|
|
|
|
|
expect(flash[:notice]).to eq(I18n.t('views.instructeurs.dossiers.archived_dossier'))
|
|
|
|
|
end
|
|
|
|
|
end
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
|
|
|
|
|
context 'with dossier in batch_operation' do
|
|
|
|
|
let!(:batch_operation) { create(:batch_operation, operation: :archiver, dossiers: [dossier], instructeur: instructeur) }
|
|
|
|
|
it { expect { subject }.not_to change { dossier.reload.conservation_extension } }
|
|
|
|
|
it { is_expected.to redirect_to(instructeur_dossier_path(dossier.procedure, dossier)) }
|
|
|
|
|
it 'flashes message' do
|
|
|
|
|
subject
|
2022-12-01 12:15:29 +01:00
|
|
|
|
expect(flash.alert).to eq("Votre action n'a pas été effectuée, ce dossier fait parti d'un traitement de masse.")
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2021-12-03 16:09:51 +01:00
|
|
|
|
end
|
2022-01-28 15:08:08 +01:00
|
|
|
|
|
|
|
|
|
describe '#restore' do
|
|
|
|
|
let(:instructeur) { create(:instructeur) }
|
|
|
|
|
let!(:gi_p1_1) { GroupeInstructeur.create(label: '1', procedure: procedure) }
|
2022-03-09 10:29:16 +01:00
|
|
|
|
let!(:procedure) { create(:procedure, :published, :for_individual, instructeurs: [instructeur]) }
|
|
|
|
|
let!(:dossier) { create(:dossier, :accepte, :with_individual, procedure: procedure, groupe_instructeur: procedure.groupe_instructeurs.first, hidden_by_administration_at: 1.hour.ago) }
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
let(:batch_operation) {}
|
2022-01-28 15:08:08 +01:00
|
|
|
|
before do
|
|
|
|
|
sign_in(instructeur.user)
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
batch_operation
|
2022-01-28 15:08:08 +01:00
|
|
|
|
instructeur.groupe_instructeurs << gi_p1_1
|
|
|
|
|
patch :restore,
|
|
|
|
|
params: {
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "puts hidden_by_administration_at to nil" do
|
|
|
|
|
expect(dossier.reload.hidden_by_administration_at).to eq(nil)
|
|
|
|
|
end
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
|
|
|
|
|
context 'with dossier in batch_operation' do
|
|
|
|
|
let(:batch_operation) { create(:batch_operation, operation: :archiver, dossiers: [dossier], instructeur: instructeur) }
|
|
|
|
|
it { expect(dossier.hidden_by_administration_at).not_to eq(nil) }
|
|
|
|
|
it { expect(response).to redirect_to(instructeur_dossier_path(dossier.procedure, dossier)) }
|
2022-12-01 12:15:29 +01:00
|
|
|
|
it { expect(flash.alert).to eq("Votre action n'a pas été effectuée, ce dossier fait parti d'un traitement de masse.") }
|
poc(batch_operation): quand un dossier est dans un batch, impossible de faire les actions : archive, unarchive, follow, unfollow, passer_en_instruction, repasser_en_construction, repasser_en_instruction, terminer, restore, destroy, extend_conservation
2022-11-25 10:24:00 +01:00
|
|
|
|
end
|
2022-01-28 15:08:08 +01:00
|
|
|
|
end
|
2023-05-17 14:02:44 +02:00
|
|
|
|
|
2023-05-17 14:49:20 +02:00
|
|
|
|
describe '#reaffectation' do
|
|
|
|
|
let!(:gi_2) { GroupeInstructeur.create(label: 'deuxième groupe', procedure: procedure) }
|
|
|
|
|
let!(:gi_3) { GroupeInstructeur.create(label: 'troisième groupe', procedure: procedure) }
|
|
|
|
|
let!(:dossier) { create(:dossier, :en_construction, procedure: procedure, groupe_instructeur: procedure.groupe_instructeurs.first) }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
post :reaffectation,
|
|
|
|
|
params: {
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it do
|
|
|
|
|
expect(response).to have_http_status(:ok)
|
2023-07-06 14:25:46 +02:00
|
|
|
|
expect(response.body).to include("Vous pouvez réaffecter le dossier nº #{dossier.id} à l’un des groupes d’instructeurs suivants.")
|
2023-05-17 14:49:20 +02:00
|
|
|
|
expect(response.body).to include('2 groupes existent')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '#reaffecter' do
|
2023-06-30 14:52:20 +02:00
|
|
|
|
let!(:gi_1) { procedure.groupe_instructeurs.first }
|
2023-05-17 14:02:44 +02:00
|
|
|
|
let!(:gi_2) { GroupeInstructeur.create(label: 'deuxième groupe', procedure: procedure) }
|
2023-07-05 17:48:18 +02:00
|
|
|
|
let!(:dossier) { create(:dossier, :en_construction, :with_individual, procedure: procedure, groupe_instructeur: gi_1) }
|
2023-06-30 14:52:20 +02:00
|
|
|
|
let!(:new_instructeur) { create(:instructeur) }
|
2023-05-17 14:02:44 +02:00
|
|
|
|
|
|
|
|
|
before do
|
2023-06-30 14:52:20 +02:00
|
|
|
|
gi_1.instructeurs << new_instructeur
|
|
|
|
|
new_instructeur.followed_dossiers << dossier
|
|
|
|
|
|
2023-05-17 14:02:44 +02:00
|
|
|
|
post :reaffecter,
|
|
|
|
|
params: {
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id,
|
|
|
|
|
groupe_instructeur_id: gi_2.id
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it do
|
|
|
|
|
expect(dossier.reload.groupe_instructeur.id).to eq(gi_2.id)
|
|
|
|
|
expect(dossier.forced_groupe_instructeur).to be_truthy
|
2023-06-30 14:52:20 +02:00
|
|
|
|
expect(dossier.followers_instructeurs).to eq []
|
|
|
|
|
expect(dossier.dossier_assignment.previous_groupe_instructeur_id).to eq(gi_1.id)
|
|
|
|
|
expect(dossier.dossier_assignment.previous_groupe_instructeur_label).to eq(gi_1.label)
|
|
|
|
|
expect(dossier.dossier_assignment.groupe_instructeur_id).to eq(gi_2.id)
|
|
|
|
|
expect(dossier.dossier_assignment.groupe_instructeur_label).to eq(gi_2.label)
|
|
|
|
|
expect(dossier.dossier_assignment.mode).to eq('manual')
|
|
|
|
|
expect(dossier.dossier_assignment.assigned_by).to eq(instructeur.email)
|
2023-05-17 14:02:44 +02:00
|
|
|
|
expect(response).to redirect_to(instructeur_procedure_path(procedure))
|
|
|
|
|
expect(flash.notice).to eq("Le dossier nº #{dossier.id} a été réaffecté au groupe d’instructeurs « deuxième groupe ».")
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-06-30 15:27:38 +02:00
|
|
|
|
|
|
|
|
|
describe '#personnes_impliquees' do
|
2023-12-21 14:42:09 +01:00
|
|
|
|
let(:routed_procedure) { create(:procedure, :routee, :published, :for_individual) }
|
|
|
|
|
let(:gi_1) { routed_procedure.groupe_instructeurs.first }
|
|
|
|
|
let(:gi_2) { routed_procedure.groupe_instructeurs.last }
|
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, :with_individual, procedure: routed_procedure, groupe_instructeur: gi_1) }
|
|
|
|
|
let(:new_instructeur) { create(:instructeur) }
|
2023-06-30 15:27:38 +02:00
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
gi_1.instructeurs << new_instructeur
|
|
|
|
|
gi_2.instructeurs << instructeur
|
|
|
|
|
new_instructeur.followed_dossiers << dossier
|
2023-07-05 17:48:18 +02:00
|
|
|
|
dossier.assign_to_groupe_instructeur(gi_2, DossierAssignment.modes.fetch(:manual), new_instructeur)
|
2023-06-30 15:27:38 +02:00
|
|
|
|
|
|
|
|
|
get :personnes_impliquees,
|
|
|
|
|
params: {
|
2023-12-21 14:42:09 +01:00
|
|
|
|
procedure_id: routed_procedure.id,
|
2023-06-30 15:27:38 +02:00
|
|
|
|
dossier_id: dossier.id
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it do
|
|
|
|
|
expect(response.body).to include('a réaffecté ce dossier du groupe « défaut » au groupe « deuxième groupe »')
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-12-18 09:51:41 +01:00
|
|
|
|
|
|
|
|
|
describe '#print' do
|
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
|
|
|
|
|
|
|
|
|
subject do
|
|
|
|
|
get :print, params: {
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(subject).to have_http_status(:ok) }
|
|
|
|
|
end
|
2017-06-29 15:31:29 +02:00
|
|
|
|
end
|