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) }
|
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
|
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: {
|
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
|
|
|
|
|
|
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) }
|
|
|
|
|
|
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)
|
2019-12-19 13:25:32 +01:00
|
|
|
|
expect(response.body).to have_text('Le dossier est déjà en instruction.')
|
|
|
|
|
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)
|
|
|
|
|
expect(response.body).to have_text('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
|
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-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)
|
2019-12-19 13:25:32 +01:00
|
|
|
|
expect(response.body).to have_text('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
|
|
|
|
|
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
|
|
|
|
|
2021-11-29 11:34:42 +01:00
|
|
|
|
subject do
|
|
|
|
|
post :repasser_en_instruction,
|
|
|
|
|
params: { procedure_id: procedure.id, dossier_id: dossier.id },
|
|
|
|
|
format: 'js'
|
|
|
|
|
end
|
|
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
2021-11-29 11:34:42 +01:00
|
|
|
|
context 'when the dossier is refuse' do
|
|
|
|
|
before { subject }
|
|
|
|
|
|
|
|
|
|
it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) }
|
|
|
|
|
it { expect(response).to have_http_status(:ok) }
|
|
|
|
|
it { expect(response.body).to include('.header-actions') }
|
|
|
|
|
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) }
|
|
|
|
|
|
2021-11-29 11:34:42 +01:00
|
|
|
|
before { subject }
|
|
|
|
|
|
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)
|
2019-12-19 13:25:32 +01:00
|
|
|
|
expect(response.body).to have_text('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) }
|
|
|
|
|
|
2021-11-29 11:34:42 +01:00
|
|
|
|
before { subject }
|
|
|
|
|
|
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
|
|
|
|
|
let!(:dossier) { create(:dossier, :accepte, procedure: procedure, user: current_user) }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
dossier.update!(hidden_by_user_at: Time.zone.now)
|
|
|
|
|
subject
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
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
|
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
|
|
|
|
|
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
|
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
|
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
|
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
|
|
|
|
|
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
|
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
|
|
|
|
|
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
|
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
|
|
|
|
|
|
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
|
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
|
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) }
|
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" }
|
2018-09-13 17:13:09 +02:00
|
|
|
|
}, format: 'js'
|
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
|
|
|
|
|
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) }
|
|
|
|
|
|
2019-12-19 13:25:32 +01:00
|
|
|
|
before { allow(dossier).to receive(:after_accepter) }
|
2019-07-11 11:37:59 +02:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
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)
|
2019-12-19 13:25:32 +01:00
|
|
|
|
expect(response.body).to have_text('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
|
|
|
|
|
|
2021-11-15 11:30:41 +01:00
|
|
|
|
describe '#messagerie' do
|
|
|
|
|
subject { get :messagerie, params: { procedure_id: procedure.id, dossier_id: dossier.id } }
|
|
|
|
|
it { expect(response).to have_http_status(:ok) }
|
|
|
|
|
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
|
|
|
|
|
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
|
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
|
|
|
|
|
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
|
|
|
|
|
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 }
|
|
|
|
|
it { expect(flash.alert).to eq(["emaila.com : Email n'est pas valide"]) }
|
|
|
|
|
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
|
|
|
|
|
|
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 }
|
|
|
|
|
it { expect(flash.alert).to eq(["toto.fr : Email n'est pas valide"]) }
|
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 }
|
2021-06-10 15:24:15 +02:00
|
|
|
|
let(:linked_dossier) { Dossier.find_by(id: dossier.reload.champs.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
|
|
|
|
|
|
2020-07-06 11:27:03 +02:00
|
|
|
|
before { subject }
|
|
|
|
|
|
2019-12-16 15:32:59 +01:00
|
|
|
|
it { expect(assigns(:include_infos_administration)).to eq(true) }
|
|
|
|
|
it { expect(response).to render_template 'dossiers/show' }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-08-02 15:33:23 +02:00
|
|
|
|
describe "#update_annotations" do
|
2020-08-27 19:56:48 +02:00
|
|
|
|
let(:procedure) do
|
|
|
|
|
create(:procedure, :published, types_de_champ_private: [
|
|
|
|
|
build(:type_de_champ_multiple_drop_down_list, position: 0),
|
|
|
|
|
build(:type_de_champ_linked_drop_down_list, position: 1),
|
|
|
|
|
build(:type_de_champ_datetime, position: 2),
|
|
|
|
|
build(:type_de_champ_repetition, :with_types_de_champ, position: 3)
|
|
|
|
|
], 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') }
|
|
|
|
|
|
2017-08-02 15:33:23 +02:00
|
|
|
|
let(:champ_multiple_drop_down_list) do
|
2020-08-27 19:56:48 +02:00
|
|
|
|
dossier.champs_private.first
|
2017-08-02 15:33:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2018-07-12 10:37:27 +02:00
|
|
|
|
let(:champ_linked_drop_down_list) do
|
2020-08-27 19:56:48 +02:00
|
|
|
|
dossier.champs_private.second
|
2018-07-12 10:37:27 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-08-02 15:33:23 +02:00
|
|
|
|
let(:champ_datetime) do
|
2020-08-27 19:56:48 +02:00
|
|
|
|
dossier.champs_private.third
|
2017-08-02 15:33:23 +02:00
|
|
|
|
end
|
|
|
|
|
|
2019-03-25 11:08:41 +01:00
|
|
|
|
let(:champ_repetition) do
|
2020-08-27 19:56:48 +02:00
|
|
|
|
dossier.champs_private.fourth
|
2019-03-25 11:08:41 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-08-02 15:33:23 +02:00
|
|
|
|
before do
|
2020-09-07 16:25:40 +02:00
|
|
|
|
another_instructeur.follow(dossier)
|
2020-07-22 17:11:33 +02:00
|
|
|
|
Timecop.freeze(now)
|
|
|
|
|
patch :update_annotations, params: params
|
|
|
|
|
|
|
|
|
|
champ_multiple_drop_down_list.reload
|
|
|
|
|
champ_linked_drop_down_list.reload
|
|
|
|
|
champ_datetime.reload
|
|
|
|
|
champ_repetition.reload
|
|
|
|
|
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,
|
|
|
|
|
value: ['', 'un', 'deux']
|
|
|
|
|
},
|
|
|
|
|
'1': {
|
|
|
|
|
id: champ_datetime.id,
|
|
|
|
|
'value(1i)': 2019,
|
|
|
|
|
'value(2i)': 12,
|
|
|
|
|
'value(3i)': 21,
|
|
|
|
|
'value(4i)': 13,
|
|
|
|
|
'value(5i)': 17
|
|
|
|
|
},
|
|
|
|
|
'2': {
|
|
|
|
|
id: champ_linked_drop_down_list.id,
|
|
|
|
|
primary_value: 'primary',
|
|
|
|
|
secondary_value: 'secondary'
|
|
|
|
|
},
|
|
|
|
|
'3': {
|
|
|
|
|
id: champ_repetition.id,
|
|
|
|
|
champs_attributes: {
|
|
|
|
|
id: champ_repetition.champs.first.id,
|
|
|
|
|
value: 'text'
|
|
|
|
|
}
|
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 {
|
|
|
|
|
expect(champ_multiple_drop_down_list.value).to eq('["un", "deux"]')
|
|
|
|
|
expect(champ_linked_drop_down_list.primary_value).to eq('primary')
|
|
|
|
|
expect(champ_linked_drop_down_list.secondary_value).to eq('secondary')
|
|
|
|
|
expect(champ_datetime.value).to eq('21/12/2019 13:17')
|
|
|
|
|
expect(champ_repetition.champs.first.value).to eq('text')
|
|
|
|
|
expect(dossier.reload.last_champ_private_updated_at).to eq(now)
|
|
|
|
|
expect(response).to redirect_to(annotations_privees_instructeur_dossier_path(dossier.procedure, dossier))
|
|
|
|
|
}
|
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: {},
|
|
|
|
|
champs_attributes: {
|
|
|
|
|
'0': {
|
|
|
|
|
id: champ_multiple_drop_down_list.id,
|
|
|
|
|
value: ['', 'un', 'deux']
|
|
|
|
|
}
|
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)
|
|
|
|
|
expect(response).to redirect_to(annotations_privees_instructeur_dossier_path(dossier.procedure, dossier))
|
|
|
|
|
}
|
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
|
|
|
|
|
end
|
2020-11-17 13:25:35 +01:00
|
|
|
|
|
|
|
|
|
describe "#delete_dossier" do
|
|
|
|
|
subject do
|
|
|
|
|
patch :delete_dossier, params: {
|
|
|
|
|
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
|
|
|
|
allow(DossierMailer).to receive(:notify_instructeur_deletion_to_user).and_return(double(deliver_later: nil))
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
it 'send an email to the user' do
|
2020-11-23 17:29:41 +01:00
|
|
|
|
expect(DossierMailer).to have_received(:notify_instructeur_deletion_to_user).with(DeletedDossier.where(dossier_id: dossier.id).first, dossier.user.email)
|
2020-11-17 13:25:35 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'add a record into deleted_dossiers table' do
|
|
|
|
|
expect(DeletedDossier.where(dossier_id: dossier.id).count).to eq(1)
|
|
|
|
|
expect(DeletedDossier.where(dossier_id: dossier.id).first.revision_id).to eq(dossier.revision_id)
|
|
|
|
|
expect(DeletedDossier.where(dossier_id: dossier.id).first.user_id).to eq(dossier.user_id)
|
|
|
|
|
expect(DeletedDossier.where(dossier_id: dossier.id).first.groupe_instructeur_id).to eq(dossier.groupe_instructeur_id)
|
|
|
|
|
end
|
|
|
|
|
|
2020-11-26 15:13:32 +01:00
|
|
|
|
it 'discard the dossier' do
|
|
|
|
|
expect(dossier.reload.hidden_at).not_to eq(nil)
|
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")
|
|
|
|
|
allow(DossierMailer).to receive(:notify_instructeur_deletion_to_user).and_return(double(deliver_later: nil))
|
|
|
|
|
subject
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'does not deletes previous logs and does not add a suppression log' do
|
|
|
|
|
expect(DossierOperationLog.where(dossier_id: dossier.id).count).to eq(2)
|
|
|
|
|
expect(DossierOperationLog.where(dossier_id: dossier.id).last.operation).not_to eq('supprimer')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'does not send an email to the user' do
|
|
|
|
|
expect(DossierMailer).not_to have_received(:notify_instructeur_deletion_to_user).with(DeletedDossier.where(dossier_id: dossier.id).first, dossier.user.email)
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
end
|
2017-06-29 15:31:29 +02:00
|
|
|
|
end
|