diff --git a/app/components/dossiers/batch_alert_component/batch_alert_component.en.yml b/app/components/dossiers/batch_alert_component/batch_alert_component.en.yml index 4895eaa8c..b75ccb66d 100644 --- a/app/components/dossiers/batch_alert_component/batch_alert_component.en.yml +++ b/app/components/dossiers/batch_alert_component/batch_alert_component.en.yml @@ -26,6 +26,24 @@ en: text_success: one: 1/1 is being accepted other: "%{success_count}/%{count} files have been accepted" + refuser: + finish: + text_success: + one: 1/1 file has been refused + other: "%{success_count}/%{count} files have been refused" + in_progress: + text_success: + one: 1/1 is being refused + other: "%{success_count}/%{count} files have been refused" + classer_sans_suite: + finish: + text_success: + one: 1/1 file has been closed without continuation + other: "%{success_count}/%{count} files have been closed without continuation" + in_progress: + text_success: + one: 1/1 is being closed without continuation + other: "%{success_count}/%{count} files have been closed without continuation" follow: finish: text_success: diff --git a/app/components/dossiers/batch_alert_component/batch_alert_component.fr.yml b/app/components/dossiers/batch_alert_component/batch_alert_component.fr.yml index 88bab8187..005bf6e43 100644 --- a/app/components/dossiers/batch_alert_component/batch_alert_component.fr.yml +++ b/app/components/dossiers/batch_alert_component/batch_alert_component.fr.yml @@ -26,6 +26,24 @@ fr: text_success: one: 1 dossier sera accepté other: "%{success_count}/%{count} dossiers ont été acceptés" + refuser: + finish: + text_success: + one: 1 dossier a été refusé + other: "%{success_count}/%{count} dossiers ont été refusés" + in_progress: + text_success: + one: 1 dossier sera refusé + other: "%{success_count}/%{count} dossiers ont été refusés" + classer_sans_suite: + finish: + text_success: + one: 1 dossier a été classé sans suite + other: "%{success_count}/%{count} dossiers ont été classés sans suite" + in_progress: + text_success: + one: 1 dossier sera classé sans suite + other: "%{success_count}/%{count} dossiers ont été classés sans suite" follow: finish: text_success: diff --git a/spec/components/dossiers/batch_alert_component_spec.rb b/spec/components/dossiers/batch_alert_component_spec.rb index 303e004cd..d43c3bf40 100644 --- a/spec/components/dossiers/batch_alert_component_spec.rb +++ b/spec/components/dossiers/batch_alert_component_spec.rb @@ -166,6 +166,78 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do end end + describe 'refuser' do + let(:component) do + described_class.new( + batch: batch_operation, + procedure: procedure + ) + end + let!(:dossier) { create(:dossier, :en_instruction, procedure: procedure) } + let!(:dossier_2) { create(:dossier, :en_instruction, procedure: procedure) } + let!(:batch_operation) { create(:batch_operation, operation: :refuser, 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_text("Une action de masse est en cours") } + it { is_expected.to have_text("1/2 dossiers ont été refusé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é refusés") } + it { expect(batch_operation.seen_at).to eq(nil) } + end + end + + describe 'classer_sans_suite' do + let(:component) do + described_class.new( + batch: batch_operation, + procedure: procedure + ) + end + let!(:dossier) { create(:dossier, :en_instruction, procedure: procedure) } + let!(:dossier_2) { create(:dossier, :en_instruction, procedure: procedure) } + let!(:batch_operation) { create(:batch_operation, operation: :classer_sans_suite, 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_text("Une action de masse est en cours") } + it { is_expected.to have_text("1/2 dossiers ont été classés sans suite") } + 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é classés sans suite") } + it { expect(batch_operation.seen_at).to eq(nil) } + end + end + describe 'follow' do let(:component) do described_class.new( diff --git a/spec/factories/batch_operation.rb b/spec/factories/batch_operation.rb index e82e396b7..9d91cfb05 100644 --- a/spec/factories/batch_operation.rb +++ b/spec/factories/batch_operation.rb @@ -40,6 +40,28 @@ FactoryBot.define do end end + trait :refuser do + operation { BatchOperation.operations.fetch(:refuser) } + 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_instruction, procedure: procedure), + create(:dossier, :with_individual, :en_instruction, procedure: procedure) + ] + end + end + + trait :classer_sans_suite do + operation { BatchOperation.operations.fetch(:classer_sans_suite) } + 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_instruction, procedure: procedure), + create(:dossier, :with_individual, :en_instruction, procedure: procedure) + ] + end + end + trait :follow do operation { BatchOperation.operations.fetch(:follow) } after(:build) do |batch_operation, evaluator| diff --git a/spec/jobs/batch_operation_process_one_job_spec.rb b/spec/jobs/batch_operation_process_one_job_spec.rb index 24946cd09..e808ac59f 100644 --- a/spec/jobs/batch_operation_process_one_job_spec.rb +++ b/spec/jobs/batch_operation_process_one_job_spec.rb @@ -154,6 +154,48 @@ describe BatchOperationProcessOneJob, type: :job do end end + context 'when operation is "refuser"' do + let(:batch_operation) do + create(:batch_operation, :refuser, + options.merge(instructeur: create(:instructeur), motivation: 'motivation')) + end + + it 'refuses the dossier in the batch' do + expect { subject.perform_now } + .to change { dossier_job.reload.refuse? } + .from(false) + .to(true) + end + + it 'refuses the dossier in the batch with a motivation' do + expect { subject.perform_now } + .to change { dossier_job.reload.motivation } + .from(nil) + .to('motivation') + end + end + + context 'when operation is "classer_sans_suite"' do + let(:batch_operation) do + create(:batch_operation, :classer_sans_suite, + options.merge(instructeur: create(:instructeur), motivation: 'motivation')) + end + + it 'closes without continuation the dossier in the batch' do + expect { subject.perform_now } + .to change { dossier_job.reload.sans_suite? } + .from(false) + .to(true) + end + + it 'closes without continuation the dossier in the batch with a motivation' do + expect { subject.perform_now } + .to change { dossier_job.reload.motivation } + .from(nil) + .to('motivation') + end + end + context 'when the dossier is out of sync (ie: someone applied a transition somewhere we do not know)' do let(:instructeur) { create(:instructeur) } let(:procedure) { create(:simple_procedure, instructeurs: [instructeur]) }