2022-11-19 06:03:59 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
describe Instructeurs::BatchOperationsController, type: :controller do
|
|
|
|
let(:instructeur) { create(:instructeur) }
|
2022-11-25 15:43:00 +01:00
|
|
|
let(:procedure) { create(:simple_procedure, instructeurs: [instructeur]) }
|
|
|
|
let(:dossier) { create(:dossier, :accepte, :with_individual, procedure: procedure) }
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
procedure_id: procedure.id,
|
|
|
|
batch_operation: {
|
|
|
|
operation: BatchOperation.operations.fetch(:archiver),
|
|
|
|
dossier_ids: [dossier.id]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2022-11-19 06:03:59 +01:00
|
|
|
|
|
|
|
describe '#POST create' do
|
|
|
|
before { sign_in(instructeur.user) }
|
2022-11-25 15:43:00 +01:00
|
|
|
subject { post :create, params: params }
|
2022-11-19 06:03:59 +01:00
|
|
|
|
|
|
|
context 'ACL' do
|
2022-11-25 15:43:00 +01:00
|
|
|
let(:params) do
|
|
|
|
{ procedure_id: create(:procedure).id }
|
|
|
|
end
|
|
|
|
|
2022-11-19 06:03:59 +01:00
|
|
|
it 'fails when procedure does not belongs to instructeur' do
|
|
|
|
expect(subject).to have_http_status(302)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-25 15:43:00 +01:00
|
|
|
context 'success with valid dossier_ids' do
|
2022-11-19 06:03:59 +01:00
|
|
|
it 'creates a batch operation for our signed in instructeur' do
|
|
|
|
expect { subject }.to change { instructeur.batch_operations.count }.by(1)
|
|
|
|
end
|
2022-12-01 10:51:10 +01:00
|
|
|
it 'created a batch operation contains dossiers, instructeur, groupe_instructeur' do
|
2022-11-19 06:03:59 +01:00
|
|
|
subject
|
2022-12-01 10:51:10 +01:00
|
|
|
batch_operation = BatchOperation.first
|
|
|
|
expect(batch_operation.dossiers).to include(dossier)
|
|
|
|
expect(batch_operation.instructeur).to eq(instructeur)
|
|
|
|
expect(batch_operation.groupe_instructeurs.to_a).to eq(instructeur.groupe_instructeurs.to_a)
|
2022-11-19 06:03:59 +01:00
|
|
|
end
|
|
|
|
it 'enqueues a BatchOperationJob' do
|
2022-11-21 16:32:17 +01:00
|
|
|
expect { subject }.to have_enqueued_job(BatchOperationEnqueueAllJob).with(BatchOperation.last)
|
2022-11-19 06:03:59 +01:00
|
|
|
end
|
|
|
|
end
|
2022-12-12 10:02:33 +01:00
|
|
|
|
|
|
|
context 'fails with no dossiers' do
|
|
|
|
let(:dossier) { create(:dossier, :en_instruction, procedure: procedure) }
|
|
|
|
|
|
|
|
it 'does not create a batch operation if no dossiers' do
|
|
|
|
expect { subject }.not_to change { instructeur.batch_operations.count }
|
|
|
|
expect(flash.alert).to eq("Le traitement de masse n'a pas été lancé. Vérifiez que l'action demandée est possible pour les dossiers sélectionnés")
|
|
|
|
end
|
|
|
|
end
|
2022-11-19 06:03:59 +01:00
|
|
|
end
|
|
|
|
end
|