add bulk action feature for 'passer_en_instruction'
This commit is contained in:
parent
2e072702ce
commit
89730b485b
14 changed files with 256 additions and 76 deletions
|
@ -1,13 +1,25 @@
|
||||||
en:
|
en:
|
||||||
finish:
|
archiver:
|
||||||
title: The bulk action is finished
|
finish:
|
||||||
text:
|
title: The bulk action is finished
|
||||||
one: 1/1 file has been archived
|
text:
|
||||||
other: "%{success_count}/%{count} files have been archived"
|
one: 1/1 file has been archived
|
||||||
in_progress:
|
other: "%{success_count}/%{count} files have been archived"
|
||||||
title: A bulk action is processing
|
in_progress:
|
||||||
text_success:
|
title: A bulk action is processing
|
||||||
one: 1/1 is being archived
|
text_success:
|
||||||
other: "%{progress_count}/%{count} files have been archived"
|
one: 1/1 is being archived
|
||||||
|
other: "%{progress_count}/%{count} files have been archived"
|
||||||
|
passer_en_instruction:
|
||||||
|
finish:
|
||||||
|
title: The bulk action is finished
|
||||||
|
text:
|
||||||
|
one: 1/1 file has been changed to instructing
|
||||||
|
other: "%{success_count}/%{count} files have been changed to instructing"
|
||||||
|
in_progress:
|
||||||
|
title: A bulk action is processing
|
||||||
|
text_success:
|
||||||
|
one: 1/1 is being changed to instructing
|
||||||
|
other: "%{progress_count}/%{count} files have been changed to instructing"
|
||||||
link_text: Refresh this webpage
|
link_text: Refresh this webpage
|
||||||
after_link_text: to check if the process is over.
|
after_link_text: to check if the process is over.
|
||||||
|
|
|
@ -1,13 +1,25 @@
|
||||||
fr:
|
fr:
|
||||||
finish:
|
archiver:
|
||||||
title: L'action de masse est terminée
|
finish:
|
||||||
text_success:
|
title: L'action de masse est terminée
|
||||||
one: 1 dossier a été archivé
|
text_success:
|
||||||
other: "%{success_count}/%{count} dossiers ont été archivés"
|
one: 1 dossier a été archivé
|
||||||
in_progress:
|
other: "%{success_count}/%{count} dossiers ont été archivés"
|
||||||
title: Une action de masse est en cours
|
in_progress:
|
||||||
text_success:
|
title: Une action de masse est en cours
|
||||||
one: 1 dossier sera archivé
|
text_success:
|
||||||
other: "%{progress_count}/%{count} dossiers ont été archivés"
|
one: 1 dossier sera archivé
|
||||||
|
other: "%{progress_count}/%{count} dossiers ont été archivés"
|
||||||
|
passer_en_instruction:
|
||||||
|
finish:
|
||||||
|
title: L'action de masse est terminée
|
||||||
|
text_success:
|
||||||
|
one: 1 dossier a été passé en instruction
|
||||||
|
other: "%{success_count}/%{count} dossiers ont été passés en instruction"
|
||||||
|
in_progress:
|
||||||
|
title: Une action de masse est en cours
|
||||||
|
text_success:
|
||||||
|
one: 1 dossier sera passé en instruction
|
||||||
|
other: "%{progress_count}/%{count} dossiers ont été passés en instruction"
|
||||||
link_text: Recharger la page
|
link_text: Recharger la page
|
||||||
after_link_text: pour voir si l'opération est finie.
|
after_link_text: pour voir si l'opération est finie.
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
.fr-mb-5v
|
.fr-mb-5v
|
||||||
- if @batch.finished_at.present?
|
- if @batch.finished_at.present?
|
||||||
= render Dsfr::AlertComponent.new(title: t('.finish.title'), state: (@batch.failed_dossier_ids.size.positive? ? :warning : :success), heading_level: 'h2') do |c|
|
= render Dsfr::AlertComponent.new(title: t(".#{batch.operation}.finish.title"), state: (@batch.failed_dossier_ids.size.positive? ? :warning : :success), heading_level: 'h2') do |c|
|
||||||
- c.body do
|
- c.body do
|
||||||
%p
|
%p
|
||||||
= t('.finish.text_success', count: @batch.total_count, success_count: @batch.success_dossier_ids.size)
|
= t(".#{batch.operation}.finish.text_success", count: @batch.total_count, success_count: @batch.success_dossier_ids.size)
|
||||||
|
|
||||||
|
|
||||||
- else
|
- else
|
||||||
= render Dsfr::AlertComponent.new(title: t('.in_progress.title'), state: :info, heading_level: 'h2') do |c|
|
= render Dsfr::AlertComponent.new(title: t(".#{batch.operation}.in_progress.title"), state: :info, heading_level: 'h2') do |c|
|
||||||
- c.body do
|
- c.body do
|
||||||
%p= t('.in_progress.text_success', count: @batch.total_count, progress_count: @batch.progress_count)
|
%p= t(".#{batch.operation}.in_progress.text_success", count: @batch.total_count, progress_count: @batch.progress_count)
|
||||||
|
|
||||||
%p
|
%p
|
||||||
= link_to t('.link_text'), instructeur_procedure_path(@procedure, statut: params["statut"]), data: { action: 'turbo-poll#refresh' }
|
= link_to t('.link_text'), instructeur_procedure_path(@procedure, statut: params["statut"]), data: { action: 'turbo-poll#refresh' }
|
||||||
|
|
|
@ -7,7 +7,7 @@ class Dossiers::BatchOperationComponent < ApplicationComponent
|
||||||
end
|
end
|
||||||
|
|
||||||
def render?
|
def render?
|
||||||
@statut == 'traites'
|
@statut == 'traites' || 'suivis'
|
||||||
end
|
end
|
||||||
|
|
||||||
def available_operations
|
def available_operations
|
||||||
|
@ -15,9 +15,10 @@ class Dossiers::BatchOperationComponent < ApplicationComponent
|
||||||
case @statut
|
case @statut
|
||||||
when 'traites' then
|
when 'traites' then
|
||||||
options.push [t(".operations.archiver"), BatchOperation.operations.fetch(:archiver)]
|
options.push [t(".operations.archiver"), BatchOperation.operations.fetch(:archiver)]
|
||||||
|
when 'suivis' then
|
||||||
|
options.push [t(".operations.passer_en_instruction"), BatchOperation.operations.fetch(:passer_en_instruction)]
|
||||||
else
|
else
|
||||||
end
|
end
|
||||||
|
|
||||||
options
|
options
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
fr:
|
fr:
|
||||||
operations:
|
operations:
|
||||||
archiver: 'Archive selected files'
|
archiver: 'Archive selected files'
|
||||||
|
passer_en_instruction: 'Change selected files to instructing'
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
fr:
|
fr:
|
||||||
operations:
|
operations:
|
||||||
archiver: 'Archiver les dossiers sélectionnés'
|
archiver: 'Archiver les dossiers sélectionnés'
|
||||||
|
passer_en_instruction: 'Passer en instruction les dossiers sélectionnés'
|
||||||
|
|
|
@ -4,7 +4,8 @@ module Instructeurs
|
||||||
before_action :ensure_ownership!
|
before_action :ensure_ownership!
|
||||||
|
|
||||||
def create
|
def create
|
||||||
BatchOperation.safe_create!(batch_operation_params)
|
batch = BatchOperation.safe_create!(batch_operation_params)
|
||||||
|
flash[:alert] = "Le traitement de masse n'a pas été lancé. Vérifiez que l'action demandée est possible pour les dossiers sélectionnés" if batch.blank?
|
||||||
redirect_back(fallback_location: instructeur_procedure_url(@procedure.id))
|
redirect_back(fallback_location: instructeur_procedure_url(@procedure.id))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
|
|
||||||
class BatchOperation < ApplicationRecord
|
class BatchOperation < ApplicationRecord
|
||||||
enum operation: {
|
enum operation: {
|
||||||
archiver: 'archiver'
|
archiver: 'archiver',
|
||||||
|
passer_en_instruction: 'passer_en_instruction'
|
||||||
}
|
}
|
||||||
|
|
||||||
has_many :dossiers, dependent: :nullify
|
has_many :dossiers, dependent: :nullify
|
||||||
|
@ -47,6 +48,8 @@ class BatchOperation < ApplicationRecord
|
||||||
case operation
|
case operation
|
||||||
when BatchOperation.operations.fetch(:archiver) then
|
when BatchOperation.operations.fetch(:archiver) then
|
||||||
query.not_archived.state_termine
|
query.not_archived.state_termine
|
||||||
|
when BatchOperation.operations.fetch(:passer_en_instruction) then
|
||||||
|
query.state_en_construction
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -59,6 +62,8 @@ class BatchOperation < ApplicationRecord
|
||||||
case operation
|
case operation
|
||||||
when BatchOperation.operations.fetch(:archiver)
|
when BatchOperation.operations.fetch(:archiver)
|
||||||
dossier.archiver!(instructeur)
|
dossier.archiver!(instructeur)
|
||||||
|
when BatchOperation.operations.fetch(:passer_en_instruction)
|
||||||
|
dossier.passer_en_instruction(instructeur: instructeur)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -92,9 +97,11 @@ class BatchOperation < ApplicationRecord
|
||||||
instance = new(params)
|
instance = new(params)
|
||||||
instance.dossiers = instance.dossiers_safe_scope(params[:dossier_ids])
|
instance.dossiers = instance.dossiers_safe_scope(params[:dossier_ids])
|
||||||
.not_having_batch_operation
|
.not_having_batch_operation
|
||||||
instance.save!
|
if instance.dossiers.present?
|
||||||
BatchOperationEnqueueAllJob.perform_later(instance)
|
instance.save!
|
||||||
instance
|
BatchOperationEnqueueAllJob.perform_later(instance)
|
||||||
|
instance
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,58 +1,116 @@
|
||||||
RSpec.describe Dossiers::BatchAlertComponent, type: :component do
|
RSpec.describe Dossiers::BatchAlertComponent, type: :component do
|
||||||
let(:component) do
|
|
||||||
described_class.new(
|
|
||||||
batch: batch_operation,
|
|
||||||
procedure: procedure
|
|
||||||
)
|
|
||||||
end
|
|
||||||
let(:instructeur) { create(:instructeur) }
|
let(:instructeur) { create(:instructeur) }
|
||||||
let(:procedure) { create(:procedure) }
|
let(:procedure) { create(:procedure) }
|
||||||
let!(:dossier) { create(:dossier, :accepte, procedure: procedure) }
|
|
||||||
let!(:dossier_2) { create(:dossier, :accepte, procedure: procedure) }
|
|
||||||
let!(:batch_operation) { create(:batch_operation, operation: :archiver, dossiers: [dossier, dossier_2], instructeur: instructeur) }
|
|
||||||
|
|
||||||
subject { render_inline(component).to_html }
|
subject { render_inline(component).to_html }
|
||||||
|
|
||||||
context 'in_progress' do
|
describe 'archiver' do
|
||||||
before {
|
let(:component) do
|
||||||
batch_operation.track_processed_dossier(true, dossier)
|
described_class.new(
|
||||||
batch_operation.reload
|
batch: batch_operation,
|
||||||
}
|
procedure: procedure
|
||||||
|
)
|
||||||
|
end
|
||||||
|
let!(:dossier) { create(:dossier, :accepte, procedure: procedure) }
|
||||||
|
let!(:dossier_2) { create(:dossier, :accepte, procedure: procedure) }
|
||||||
|
let!(:batch_operation) { create(:batch_operation, operation: :archiver, dossiers: [dossier, dossier_2], instructeur: instructeur) }
|
||||||
|
context 'in_progress' do
|
||||||
|
before {
|
||||||
|
batch_operation.track_processed_dossier(true, dossier)
|
||||||
|
batch_operation.reload
|
||||||
|
}
|
||||||
|
|
||||||
it { is_expected.to have_selector('.fr-alert--info') }
|
it { is_expected.to have_selector('.fr-alert--info') }
|
||||||
it { is_expected.to have_text("Une action de masse est en cours") }
|
it { is_expected.to have_text("Une action de masse est en cours") }
|
||||||
it { is_expected.to have_text("1/2 dossiers ont été archivés") }
|
it { is_expected.to have_text("1/2 dossiers ont été archivés") }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'finished and success' do
|
||||||
|
before {
|
||||||
|
batch_operation.track_processed_dossier(true, dossier)
|
||||||
|
batch_operation.track_processed_dossier(true, dossier_2)
|
||||||
|
batch_operation.reload
|
||||||
|
}
|
||||||
|
|
||||||
|
it { is_expected.to have_selector('.fr-alert--success') }
|
||||||
|
it { is_expected.to have_text("L'action de masse est terminée") }
|
||||||
|
it { is_expected.to have_text("2 dossiers ont été archivés") }
|
||||||
|
it { expect(batch_operation.seen_at).to eq(nil) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'finished and fail' do
|
||||||
|
before {
|
||||||
|
batch_operation.track_processed_dossier(false, dossier)
|
||||||
|
batch_operation.track_processed_dossier(true, dossier_2)
|
||||||
|
batch_operation.reload
|
||||||
|
}
|
||||||
|
|
||||||
|
it { is_expected.to have_selector('.fr-alert--warning') }
|
||||||
|
it { is_expected.to have_text("L'action de masse est terminée") }
|
||||||
|
it { is_expected.to have_text("1/2 dossiers ont été archivés") }
|
||||||
|
it { expect(batch_operation.seen_at).to eq(nil) }
|
||||||
|
|
||||||
|
it 'does not display alert on the next render' do
|
||||||
|
render_inline(component).to_html
|
||||||
|
expect(batch_operation.seen_at).not_to eq(nil)
|
||||||
|
expect(subject).not_to have_text("1 dossier n'a pas été archivé")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'finished and success' do
|
describe 'passer_en_instruction' do
|
||||||
before {
|
let(:component) do
|
||||||
batch_operation.track_processed_dossier(true, dossier)
|
described_class.new(
|
||||||
batch_operation.track_processed_dossier(true, dossier_2)
|
batch: batch_operation,
|
||||||
batch_operation.reload
|
procedure: procedure
|
||||||
}
|
)
|
||||||
|
end
|
||||||
|
let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
||||||
|
let!(:dossier_2) { create(:dossier, :en_construction, procedure: procedure) }
|
||||||
|
let!(:batch_operation) { create(:batch_operation, operation: :passer_en_instruction, dossiers: [dossier, dossier_2], instructeur: instructeur) }
|
||||||
|
|
||||||
it { is_expected.to have_selector('.fr-alert--success') }
|
context 'in_progress' do
|
||||||
it { is_expected.to have_text("L'action de masse est terminée") }
|
before {
|
||||||
it { is_expected.to have_text("2 dossiers ont été archivés") }
|
batch_operation.track_processed_dossier(true, dossier)
|
||||||
it { expect(batch_operation.seen_at).to eq(nil) }
|
batch_operation.reload
|
||||||
end
|
}
|
||||||
|
|
||||||
context 'finished and fail' do
|
it { is_expected.to have_selector('.fr-alert--info') }
|
||||||
before {
|
it { is_expected.to have_text("Une action de masse est en cours") }
|
||||||
batch_operation.track_processed_dossier(false, dossier)
|
it { is_expected.to have_text("1/2 dossiers ont été passés en instruction") }
|
||||||
batch_operation.track_processed_dossier(true, dossier_2)
|
end
|
||||||
batch_operation.reload
|
|
||||||
}
|
|
||||||
|
|
||||||
it { is_expected.to have_selector('.fr-alert--warning') }
|
context 'finished and success' do
|
||||||
it { is_expected.to have_text("L'action de masse est terminée") }
|
before {
|
||||||
it { is_expected.to have_text("1/2 dossiers ont été archivés") }
|
batch_operation.track_processed_dossier(true, dossier)
|
||||||
it { expect(batch_operation.seen_at).to eq(nil) }
|
batch_operation.track_processed_dossier(true, dossier_2)
|
||||||
|
batch_operation.reload
|
||||||
|
}
|
||||||
|
|
||||||
it 'does not display alert on the next render' do
|
it { is_expected.to have_selector('.fr-alert--success') }
|
||||||
render_inline(component).to_html
|
it { is_expected.to have_text("L'action de masse est terminée") }
|
||||||
expect(batch_operation.seen_at).not_to eq(nil)
|
it { is_expected.to have_text("2 dossiers ont été passés en instruction") }
|
||||||
expect(subject).not_to have_text("1 dossier n'a pas été archivé")
|
it { expect(batch_operation.seen_at).to eq(nil) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'finished and fail' do
|
||||||
|
before {
|
||||||
|
batch_operation.track_processed_dossier(false, dossier)
|
||||||
|
batch_operation.track_processed_dossier(true, dossier_2)
|
||||||
|
batch_operation.reload
|
||||||
|
}
|
||||||
|
|
||||||
|
it { is_expected.to have_selector('.fr-alert--warning') }
|
||||||
|
it { is_expected.to have_text("L'action de masse est terminée") }
|
||||||
|
it { is_expected.to have_text("1/2 dossiers ont été passés en instruction") }
|
||||||
|
it { expect(batch_operation.seen_at).to eq(nil) }
|
||||||
|
|
||||||
|
it 'does not display alert on the next render' do
|
||||||
|
render_inline(component).to_html
|
||||||
|
expect(batch_operation.seen_at).not_to eq(nil)
|
||||||
|
expect(subject).not_to have_text("1 dossier n'a pas passé en instruction")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,6 +17,12 @@ RSpec.describe Dossiers::BatchOperationComponent, type: :component do
|
||||||
it { is_expected.to have_selector('button') }
|
it { is_expected.to have_selector('button') }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
subject { render_inline(component).to_html }
|
||||||
|
context 'statut suivis' do
|
||||||
|
let(:statut) { 'suivis' }
|
||||||
|
it { is_expected.to have_selector('button') }
|
||||||
|
end
|
||||||
|
|
||||||
context 'statut tous' do
|
context 'statut tous' do
|
||||||
let(:statut) { 'tous' }
|
let(:statut) { 'tous' }
|
||||||
it { is_expected.not_to have_selector('button') }
|
it { is_expected.not_to have_selector('button') }
|
||||||
|
|
|
@ -43,5 +43,14 @@ describe Instructeurs::BatchOperationsController, type: :controller do
|
||||||
expect { subject }.to have_enqueued_job(BatchOperationEnqueueAllJob).with(BatchOperation.last)
|
expect { subject }.to have_enqueued_job(BatchOperationEnqueueAllJob).with(BatchOperation.last)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,5 +17,16 @@ FactoryBot.define do
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :passer_en_instruction do
|
||||||
|
operation { BatchOperation.operations.fetch(:passer_en_instruction) }
|
||||||
|
after(:build) do |batch_operation, evaluator|
|
||||||
|
procedure = create(:simple_procedure, :published, instructeurs: [evaluator.invalid_instructeur.presence || batch_operation.instructeur], administrateurs: [create(:administrateur)])
|
||||||
|
batch_operation.dossiers = [
|
||||||
|
create(:dossier, :with_individual, :en_construction, procedure: procedure),
|
||||||
|
create(:dossier, :with_individual, :en_construction, procedure: procedure)
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,6 +23,29 @@ describe BatchOperationProcessOneJob, type: :job do
|
||||||
expect(batch_operation.reload.failed_dossier_ids).to eq([dossier_job.id])
|
expect(batch_operation.reload.failed_dossier_ids).to eq([dossier_job.id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when operation is "archiver"' do
|
||||||
|
it 'archives the dossier in the batch' do
|
||||||
|
expect { subject.perform_now }
|
||||||
|
.to change { dossier_job.reload.archived? }
|
||||||
|
.from(false)
|
||||||
|
.to(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when operation is "passer_en_instruction"' do
|
||||||
|
let(:batch_operation) do
|
||||||
|
create(:batch_operation, :passer_en_instruction,
|
||||||
|
options.merge(instructeur: create(:instructeur)))
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'changes the dossier to en_instruction in the batch' do
|
||||||
|
expect { subject.perform_now }
|
||||||
|
.to change { dossier_job.reload.en_instruction? }
|
||||||
|
.from(false)
|
||||||
|
.to(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when the dossier is out of sync (ie: someone applied a transition somewhere we do not know)' do
|
context 'when the dossier is out of sync (ie: someone applied a transition somewhere we do not know)' do
|
||||||
let(:instructeur) { create(:instructeur) }
|
let(:instructeur) { create(:instructeur) }
|
||||||
let(:procedure) { create(:simple_procedure, instructeurs: [instructeur]) }
|
let(:procedure) { create(:simple_procedure, instructeurs: [instructeur]) }
|
||||||
|
|
|
@ -60,6 +60,13 @@ describe BatchOperation, type: :model do
|
||||||
.from([])
|
.from([])
|
||||||
.to([dossier.id])
|
.to([dossier.id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'changes the state' do
|
||||||
|
expect { batch_operation.track_processed_dossier(true, dossier) }
|
||||||
|
.to change { dossier.state }
|
||||||
|
.from('accepte')
|
||||||
|
.to('archive')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when it succeed after a failure' do
|
context 'when it succeed after a failure' do
|
||||||
|
@ -120,10 +127,10 @@ describe BatchOperation, type: :model do
|
||||||
expect(batch_operation.dossiers_safe_scope).to include(dossier)
|
expect(batch_operation.dossiers_safe_scope).to include(dossier)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context 'when dossier is already arcvhied' do
|
context 'when dossier is already archived' do
|
||||||
let(:dossier) { create(:dossier, :accepte, :with_individual, archived: true, procedure: procedure) }
|
let(:dossier) { create(:dossier, :accepte, :with_individual, archived: true, procedure: procedure) }
|
||||||
|
|
||||||
it 'skips dosssier is already archived' do
|
it 'skips dossier is already archived' do
|
||||||
expect(batch_operation.dossiers_safe_scope).not_to include(dossier)
|
expect(batch_operation.dossiers_safe_scope).not_to include(dossier)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -145,10 +152,41 @@ describe BatchOperation, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#dossiers_safe_scope (with passer_en_instruction)' do
|
||||||
|
let(:instructeur) { create(:instructeur) }
|
||||||
|
let(:procedure) { create(:simple_procedure, instructeurs: [instructeur]) }
|
||||||
|
let(:batch_operation) { create(:batch_operation, operation: :passer_en_instruction, instructeur: instructeur, dossiers: [dossier]) }
|
||||||
|
|
||||||
|
context 'when dossier is valid' do
|
||||||
|
let(:dossier) { create(:dossier, :en_construction, :with_individual, procedure: procedure) }
|
||||||
|
|
||||||
|
it 'find dosssier' do
|
||||||
|
expect(batch_operation.dossiers_safe_scope).to include(dossier)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when dossier is already en instruction' do
|
||||||
|
let(:dossier) { create(:dossier, :en_instruction, :with_individual, archived: true, procedure: procedure) }
|
||||||
|
|
||||||
|
it 'skips dossier is already en instruction' do
|
||||||
|
expect(batch_operation.dossiers_safe_scope).not_to include(dossier)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when dossier is not in state en construction' do
|
||||||
|
let(:dossier) { create(:dossier, :accepte, :with_individual, procedure: procedure) }
|
||||||
|
|
||||||
|
it 'does not enqueue any job' do
|
||||||
|
expect(batch_operation.dossiers_safe_scope).not_to include(dossier)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#safe_create!' do
|
describe '#safe_create!' do
|
||||||
let(:instructeur) { create(:instructeur) }
|
let(:instructeur) { create(:instructeur) }
|
||||||
let(:procedure) { create(:simple_procedure, instructeurs: [instructeur]) }
|
let(:procedure) { create(:simple_procedure, instructeurs: [instructeur]) }
|
||||||
subject { BatchOperation.safe_create!(instructeur: instructeur, operation: :archiver, dossier_ids: [dossier.id]) }
|
let(:dossier_2) { create(:dossier, :accepte, procedure: procedure) }
|
||||||
|
subject { BatchOperation.safe_create!(instructeur: instructeur, operation: :archiver, dossier_ids: [dossier.id, dossier_2.id,]) }
|
||||||
|
|
||||||
context 'success with divergent list of dossier_ids' do
|
context 'success with divergent list of dossier_ids' do
|
||||||
let(:dossier) { create(:dossier, :accepte, :with_individual, archived: true, procedure: procedure) }
|
let(:dossier) { create(:dossier, :accepte, :with_individual, archived: true, procedure: procedure) }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue