add specs

This commit is contained in:
Lisa Durand 2023-07-04 11:40:11 +02:00
parent 3577bcbffa
commit b2ba15a277
5 changed files with 172 additions and 0 deletions

View file

@ -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:

View file

@ -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:

View file

@ -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("Laction 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("Laction 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(

View file

@ -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|

View file

@ -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]) }