2017-06-29 15:31:29 +02:00
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
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] }
|
|
|
|
|
let(:procedure) { create(:procedure, :published, instructeurs: instructeurs) }
|
2017-12-14 15:51:45 +01:00
|
|
|
|
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
2019-02-18 17:52:15 +01:00
|
|
|
|
let(:fake_justificatif) { Rack::Test::UploadedFile.new("./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-09-10 11:09:51 +02:00
|
|
|
|
it 'redirects to attestation pdf' do
|
2017-06-29 15:31:29 +02:00
|
|
|
|
get :attestation, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
2019-09-10 11:09:51 +02:00
|
|
|
|
expect(response).to redirect_to(dossier.attestation.pdf_url.gsub('http://localhost:3000', ''))
|
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
|
2019-08-06 11:02:54 +02:00
|
|
|
|
let(:recipient) { create(:instructeur) }
|
|
|
|
|
let(:instructeurs) { [instructeur, recipient] }
|
2018-01-30 19:11:07 +01:00
|
|
|
|
let(:mail) { double("mail") }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
expect(mail).to receive(:deliver_later)
|
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
expect(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: {
|
2018-09-10 17:52:49 +02:00
|
|
|
|
recipients: [recipient],
|
2018-01-30 19:11:07 +01:00
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
it { expect(response).to redirect_to(personnes_impliquees_instructeur_dossier_url) }
|
2019-11-19 16:01:43 +01:00
|
|
|
|
it { expect(recipient.followed_dossiers).to include(dossier) }
|
2018-01-30 19:11:07 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
describe '#follow' do
|
|
|
|
|
before do
|
|
|
|
|
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') }
|
2019-08-06 11:02:54 +02:00
|
|
|
|
it { expect(response).to redirect_to(instructeur_procedures_url) }
|
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
|
|
|
|
|
before do
|
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}") }
|
2019-08-06 11:02:54 +02:00
|
|
|
|
it { expect(response).to redirect_to(instructeur_procedures_url) }
|
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
|
|
|
|
|
before do
|
2019-08-06 11:02:54 +02:00
|
|
|
|
instructeur.follow(dossier)
|
2017-07-26 14:33:48 +02:00
|
|
|
|
patch :archive, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
|
|
|
|
dossier.reload
|
2019-08-06 11:02:54 +02:00
|
|
|
|
instructeur.reload
|
2017-07-06 16:33:36 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
it { expect(dossier.archived).to be true }
|
2019-08-06 11:02:54 +02:00
|
|
|
|
it { expect(response).to redirect_to(instructeur_procedures_url) }
|
2017-07-11 15:56:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
describe '#unarchive' do
|
|
|
|
|
before do
|
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 }
|
|
|
|
|
dossier.reload
|
2017-07-11 15:56:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-07-26 14:33:48 +02:00
|
|
|
|
it { expect(dossier.archived).to be false }
|
2019-08-06 11:02:54 +02:00
|
|
|
|
it { expect(response).to redirect_to(instructeur_procedures_url) }
|
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) }
|
|
|
|
|
|
2017-11-30 17:11:46 +01:00
|
|
|
|
before do
|
2019-08-07 11:15:16 +02:00
|
|
|
|
sign_in(instructeur.user)
|
2018-09-13 17:13:09 +02:00
|
|
|
|
post :passer_en_instruction, params: { procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js'
|
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) }
|
2019-08-12 16:46:38 +02:00
|
|
|
|
it { expect(response.body).to include('.header-actions') }
|
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) }
|
|
|
|
|
|
|
|
|
|
it 'warns about the error, but doesn’t raise' do
|
|
|
|
|
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction))
|
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
|
end
|
|
|
|
|
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) }
|
|
|
|
|
|
2017-11-30 17:18:06 +01:00
|
|
|
|
before do
|
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 },
|
|
|
|
|
format: 'js'
|
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) }
|
2019-08-12 16:46:38 +02:00
|
|
|
|
it { expect(response.body).to include('.header-actions') }
|
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-07-11 11:47:37 +02:00
|
|
|
|
it 'warns about the error, but doesn’t raise' do
|
|
|
|
|
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_construction))
|
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
|
end
|
2017-11-30 17:18:06 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-07-11 11:52:24 +02:00
|
|
|
|
describe '#repasser_en_instruction' do
|
|
|
|
|
let(:dossier) { create(:dossier, :refuse, procedure: procedure) }
|
2019-08-07 11:15:16 +02:00
|
|
|
|
let(:current_user) { instructeur.user }
|
2019-07-11 11:52:24 +02:00
|
|
|
|
|
|
|
|
|
before do
|
2019-07-29 10:57:21 +02:00
|
|
|
|
sign_in current_user
|
2019-07-11 11:52:24 +02:00
|
|
|
|
post :repasser_en_instruction,
|
|
|
|
|
params: { procedure_id: procedure.id, dossier_id: dossier.id },
|
|
|
|
|
format: 'js'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) }
|
|
|
|
|
it { expect(response).to have_http_status(:ok) }
|
2019-08-12 16:46:38 +02:00
|
|
|
|
it { expect(response.body).to include('.header-actions') }
|
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) }
|
|
|
|
|
|
|
|
|
|
it 'warns about the error, but doesn’t raise' do
|
|
|
|
|
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction))
|
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
|
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
|
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
|
2017-12-14 15:53:02 +01:00
|
|
|
|
dossier.en_instruction!
|
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
|
|
|
|
|
subject { post :terminer, params: { process_action: "refuser", procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js' }
|
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
|
|
|
|
|
expect(NotificationMailer).to receive(:send_refused_notification)
|
|
|
|
|
.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
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-02-18 17:52:15 +01:00
|
|
|
|
context 'refusal with a justificatif' do
|
|
|
|
|
subject { post :terminer, params: { process_action: "refuser", procedure_id: procedure.id, dossier_id: dossier.id, dossier: { justificatif_motivation: fake_justificatif } }, format: 'js' }
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2019-08-12 16:46:38 +02:00
|
|
|
|
it { expect(subject.body).to include('.header-actions') }
|
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 classer_sans_suite" do
|
2017-12-01 12:57:01 +01:00
|
|
|
|
before do
|
2017-12-14 15:53:02 +01:00
|
|
|
|
dossier.en_instruction!
|
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
|
|
|
|
|
subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js' }
|
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
|
|
|
|
|
expect(NotificationMailer).to receive(:send_without_continuation_notification)
|
|
|
|
|
.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
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
2019-08-12 16:46:38 +02:00
|
|
|
|
it { expect(subject.body).to include('.header-actions') }
|
2017-12-01 12:57:01 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-02-18 17:52:15 +01:00
|
|
|
|
context 'with attachment' do
|
|
|
|
|
subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure.id, dossier_id: dossier.id, dossier: { justificatif_motivation: fake_justificatif } }, format: 'js' }
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2019-08-12 16:46:38 +02:00
|
|
|
|
it { expect(subject.body).to include('.header-actions') }
|
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
|
2017-12-14 15:53:02 +01:00
|
|
|
|
dossier.en_instruction!
|
2019-08-07 11:15:16 +02:00
|
|
|
|
sign_in(instructeur.user)
|
2017-12-01 12:57:01 +01:00
|
|
|
|
|
2018-05-25 23:08:47 +02:00
|
|
|
|
expect(NotificationMailer).to receive(:send_closed_notification)
|
|
|
|
|
.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
|
|
|
|
|
|
2018-09-13 17:13:09 +02:00
|
|
|
|
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js' }
|
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
|
|
|
|
|
allow(attestation).to receive(:pdf).and_return(double(read: 'pdf', size: 2.megabytes))
|
|
|
|
|
|
|
|
|
|
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
|
2019-08-12 16:46:38 +02:00
|
|
|
|
expect(subject.body).to include('.header-actions')
|
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
|
2019-08-12 16:46:38 +02:00
|
|
|
|
expect(subject.body).to include('.header-actions')
|
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) }
|
2019-08-06 11:02:54 +02:00
|
|
|
|
let(:procedure) { create(:procedure, :published, 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" }
|
2018-09-13 17:13:09 +02:00
|
|
|
|
}, format: 'js'
|
2017-12-21 17:21:31 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
before do
|
2018-10-25 15:07:15 +02:00
|
|
|
|
Timecop.freeze(Time.zone.now)
|
2017-12-22 11:31:38 +01:00
|
|
|
|
|
2017-12-21 17:21:31 +01:00
|
|
|
|
expect_any_instance_of(AttestationTemplate)
|
|
|
|
|
.to receive(:attestation_for)
|
2018-10-25 15:07:15 +02:00
|
|
|
|
.with(have_attributes(motivation: "Yallah", processed_at: Time.zone.now))
|
2017-12-21 17:21:31 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-12-22 11:31:38 +01:00
|
|
|
|
after { Timecop.return }
|
|
|
|
|
|
2017-12-21 17:21:31 +01:00
|
|
|
|
it { subject }
|
|
|
|
|
end
|
2019-02-18 17:52:15 +01:00
|
|
|
|
|
|
|
|
|
context 'with an attachment' do
|
|
|
|
|
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id, dossier: { justificatif_motivation: fake_justificatif } }, format: 'js' }
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2019-08-12 16:46:38 +02:00
|
|
|
|
it { expect(subject.body).to include('.header-actions') }
|
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
|
|
|
|
|
|
|
|
|
context 'when a dossier is already closed' do
|
|
|
|
|
let(:dossier) { create(:dossier, :accepte, procedure: procedure) }
|
|
|
|
|
|
|
|
|
|
before { allow(dossier).to receive(:accepter!) }
|
|
|
|
|
|
|
|
|
|
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id, dossier: { justificatif_motivation: fake_justificatif } }, format: 'js' }
|
|
|
|
|
|
|
|
|
|
it 'does not close it again' do
|
|
|
|
|
subject
|
|
|
|
|
|
|
|
|
|
expect(dossier).not_to have_received(:accepter!)
|
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-12-01 12:57:01 +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" }
|
2018-10-16 00:01:53 +02:00
|
|
|
|
let(:file) { Rack::Test::UploadedFile.new("./spec/fixtures/files/piece_justificative_0.pdf", 'application/pdf') }
|
2017-11-08 16:37:04 +01:00
|
|
|
|
let(:scan_result) { true }
|
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
|
|
|
|
|
allow(ClamavService).to receive(:safe_file?).and_return(scan_result)
|
2017-07-19 14:04:49 +02:00
|
|
|
|
end
|
|
|
|
|
|
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
|
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
|
2017-07-19 14:04:49 +02:00
|
|
|
|
end
|
2017-08-28 14:16:13 +02:00
|
|
|
|
|
|
|
|
|
describe "#create_avis" do
|
|
|
|
|
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
|
|
|
|
|
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,
|
2018-10-31 20:38:32 +01:00
|
|
|
|
avis: { emails: emails, introduction: 'intro', confidentiel: true }
|
2017-08-28 14:16:13 +02:00
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2018-02-27 16:58:22 +01:00
|
|
|
|
before do
|
|
|
|
|
subject
|
|
|
|
|
end
|
|
|
|
|
|
2018-10-31 20:38:32 +01:00
|
|
|
|
let(:emails) { ['email@a.com'] }
|
2018-02-27 16:58:22 +01:00
|
|
|
|
|
2017-08-28 14:16:13 +02:00
|
|
|
|
it { expect(saved_avis.email).to eq('email@a.com') }
|
|
|
|
|
it { expect(saved_avis.introduction).to eq('intro') }
|
2017-09-20 10:42:16 +02:00
|
|
|
|
it { expect(saved_avis.confidentiel).to eq(true) }
|
2017-08-28 14:16:13 +02:00
|
|
|
|
it { expect(saved_avis.dossier).to eq(dossier) }
|
2019-08-06 11:02:54 +02:00
|
|
|
|
it { expect(saved_avis.claimant).to eq(instructeur) }
|
|
|
|
|
it { expect(response).to redirect_to(avis_instructeur_dossier_path(dossier.procedure, dossier)) }
|
2018-02-27 16:58:22 +01:00
|
|
|
|
|
|
|
|
|
context "with an invalid email" do
|
2018-10-31 20:38:32 +01:00
|
|
|
|
let(:emails) { ['emaila.com'] }
|
2018-02-27 16:58:22 +01:00
|
|
|
|
|
|
|
|
|
it { expect(response).to render_template :avis }
|
2018-10-31 20:38:32 +01:00
|
|
|
|
it { expect(flash.alert).to eq(["emaila.com : Email n'est pas valide"]) }
|
2018-02-27 16:58:22 +01:00
|
|
|
|
it { expect { subject }.not_to change(Avis, :count) }
|
|
|
|
|
end
|
2018-10-31 20:38:32 +01:00
|
|
|
|
|
|
|
|
|
context 'with multiple emails' do
|
|
|
|
|
let(:emails) { ["toto.fr,titi@titimail.com"] }
|
|
|
|
|
|
|
|
|
|
it { expect(response).to render_template :avis }
|
|
|
|
|
it { expect(flash.alert).to eq(["toto.fr : Email n'est pas valide"]) }
|
|
|
|
|
it { expect(flash.notice).to eq("Une demande d'avis a été envoyée à titi@titimail.com") }
|
|
|
|
|
it { expect(Avis.count).to eq(old_avis_count + 1) }
|
|
|
|
|
it { expect(saved_avis.email).to eq("titi@titimail.com") }
|
|
|
|
|
end
|
2017-08-28 14:16:13 +02:00
|
|
|
|
end
|
2017-08-02 15:33:23 +02:00
|
|
|
|
|
|
|
|
|
describe "#update_annotations" do
|
|
|
|
|
let(:champ_multiple_drop_down_list) do
|
2018-02-14 15:12:57 +01:00
|
|
|
|
create(:type_de_champ_multiple_drop_down_list, :private, libelle: 'libelle').champ.create
|
2017-08-02 15:33:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2018-07-12 10:37:27 +02:00
|
|
|
|
let(:champ_linked_drop_down_list) do
|
|
|
|
|
create(:type_de_champ_linked_drop_down_list, :private, libelle: 'libelle').champ.create
|
|
|
|
|
end
|
|
|
|
|
|
2017-08-02 15:33:23 +02:00
|
|
|
|
let(:champ_datetime) do
|
2018-02-14 15:12:57 +01:00
|
|
|
|
create(:type_de_champ_datetime, :private, libelle: 'libelle').champ.create
|
2017-08-02 15:33:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2019-03-25 11:08:41 +01:00
|
|
|
|
let(:champ_repetition) do
|
|
|
|
|
tdc = create(:type_de_champ_repetition, :private, libelle: 'libelle')
|
|
|
|
|
tdc.types_de_champ << create(:type_de_champ_text, libelle: 'libelle')
|
|
|
|
|
champ = tdc.champ.create
|
|
|
|
|
champ.add_row
|
|
|
|
|
champ
|
|
|
|
|
end
|
|
|
|
|
|
2017-08-02 15:33:23 +02:00
|
|
|
|
let(:dossier) do
|
2019-03-25 11:08:41 +01:00
|
|
|
|
create(:dossier, :en_construction, procedure: procedure, champs_private: [champ_multiple_drop_down_list, champ_linked_drop_down_list, champ_datetime, champ_repetition])
|
2017-08-02 15:33:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
patch :update_annotations, params: {
|
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
|
dossier_id: dossier.id,
|
|
|
|
|
dossier: {
|
|
|
|
|
champs_private_attributes: {
|
|
|
|
|
'0': {
|
|
|
|
|
id: champ_multiple_drop_down_list.id,
|
|
|
|
|
value: ['', 'un', 'deux']
|
|
|
|
|
},
|
|
|
|
|
'1': {
|
|
|
|
|
id: champ_datetime.id,
|
|
|
|
|
'value(1i)': 2019,
|
|
|
|
|
'value(2i)': 12,
|
|
|
|
|
'value(3i)': 21,
|
|
|
|
|
'value(4i)': 13,
|
|
|
|
|
'value(5i)': 17
|
2018-07-12 10:37:27 +02:00
|
|
|
|
},
|
|
|
|
|
'2': {
|
|
|
|
|
id: champ_linked_drop_down_list.id,
|
|
|
|
|
primary_value: 'primary',
|
|
|
|
|
secondary_value: 'secondary'
|
2019-03-25 11:08:41 +01:00
|
|
|
|
},
|
|
|
|
|
'3': {
|
|
|
|
|
id: champ_repetition.id,
|
|
|
|
|
champs_attributes: {
|
|
|
|
|
id: champ_repetition.champs.first.id,
|
|
|
|
|
value: 'text'
|
|
|
|
|
}
|
2017-08-02 15:33:23 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
champ_multiple_drop_down_list.reload
|
2018-07-12 10:37:27 +02:00
|
|
|
|
champ_linked_drop_down_list.reload
|
2017-08-02 15:33:23 +02:00
|
|
|
|
champ_datetime.reload
|
2019-03-25 11:08:41 +01:00
|
|
|
|
champ_repetition.reload
|
2017-08-02 15:33:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(champ_multiple_drop_down_list.value).to eq('["un", "deux"]') }
|
2018-07-12 10:37:27 +02:00
|
|
|
|
it { expect(champ_linked_drop_down_list.primary_value).to eq('primary') }
|
|
|
|
|
it { expect(champ_linked_drop_down_list.secondary_value).to eq('secondary') }
|
2017-08-02 15:33:23 +02:00
|
|
|
|
it { expect(champ_datetime.value).to eq('21/12/2019 13:17') }
|
2019-03-25 11:08:41 +01:00
|
|
|
|
it { expect(champ_repetition.champs.first.value).to eq('text') }
|
2019-08-06 11:02:54 +02:00
|
|
|
|
it { expect(response).to redirect_to(annotations_privees_instructeur_dossier_path(dossier.procedure, dossier)) }
|
2017-08-02 15:33:23 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
context 'when zip download is disabled through flipflop' do
|
|
|
|
|
it 'is forbidden' do
|
|
|
|
|
subject
|
|
|
|
|
expect(response).to have_http_status(:forbidden)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-06-29 15:31:29 +02:00
|
|
|
|
end
|