Merge pull request #9772 from adullact/feature-ouidou/batch_action_on_dossiers_repousser_date_suppression
Feature ouidou/batch action on dossiers repousser date suppression
This commit is contained in:
commit
417f70f961
9 changed files with 475 additions and 14 deletions
|
@ -8,6 +8,15 @@ en:
|
|||
text_success:
|
||||
one: "1 is being archived"
|
||||
other: "%{success_count}/%{count} files have been archived"
|
||||
desarchiver:
|
||||
finish:
|
||||
text_success:
|
||||
one: "%{success_count}/1 file has been unarchived"
|
||||
other: "%{success_count}/%{count} files have been unarchived"
|
||||
in_progress:
|
||||
text_success:
|
||||
one: "1 is being unarchived"
|
||||
other: "%{success_count}/%{count} files have been unarchived"
|
||||
passer_en_instruction:
|
||||
finish:
|
||||
text_success:
|
||||
|
@ -17,6 +26,15 @@ en:
|
|||
text_success:
|
||||
one: "1 is being changed to instructing"
|
||||
other: "%{success_count}/%{count} files have been changed to instructing"
|
||||
repousser_expiration:
|
||||
finish:
|
||||
text_success:
|
||||
one: "%{success_count}/1 file will be kept for an additional month"
|
||||
other: "%{success_count}/%{count} files will be kept for an additional month"
|
||||
in_progress:
|
||||
text_success:
|
||||
one: "1 is being kept for an additional month"
|
||||
other: "%{success_count}/%{count} files will be kept for an additional month"
|
||||
accepter:
|
||||
finish:
|
||||
text_success:
|
||||
|
@ -35,6 +53,24 @@ en:
|
|||
text_success:
|
||||
one: "1 is being refused"
|
||||
other: "%{success_count}/%{count} files have been refused"
|
||||
supprimer:
|
||||
finish:
|
||||
text_success:
|
||||
one: "%{success_count}/1 file has been deleted"
|
||||
other: "%{success_count}/%{count} files have been deleted"
|
||||
in_progress:
|
||||
text_success:
|
||||
one: "1 is being deleted"
|
||||
other: "%{success_count}/%{count} files have been deleted"
|
||||
restaurer:
|
||||
finish:
|
||||
text_success:
|
||||
one: "%{success_count}/1 file has been restored"
|
||||
other: "%{success_count}/%{count} files have been restored"
|
||||
in_progress:
|
||||
text_success:
|
||||
one: "1 is being restored"
|
||||
other: "%{success_count}/%{count} files have been restored"
|
||||
classer_sans_suite:
|
||||
finish:
|
||||
text_success:
|
||||
|
|
|
@ -8,6 +8,15 @@ fr:
|
|||
text_success:
|
||||
one: "1 dossier est en cours d'archivage"
|
||||
other: "%{success_count}/%{count} dossiers ont été archivés"
|
||||
desarchiver:
|
||||
finish:
|
||||
text_success:
|
||||
one: "%{success_count}/1 dossier a été désarchivé"
|
||||
other: "%{success_count}/%{count} dossiers ont été désarchivés"
|
||||
in_progress:
|
||||
text_success:
|
||||
one: "1 dossier est en cours d'désarchivage"
|
||||
other: "%{success_count}/%{count} dossiers ont été désarchivés"
|
||||
passer_en_instruction:
|
||||
finish:
|
||||
text_success:
|
||||
|
@ -17,6 +26,15 @@ fr:
|
|||
text_success:
|
||||
one: "1 dossier est en cours d'instruction"
|
||||
other: "%{success_count}/%{count} dossiers ont été passés en instruction"
|
||||
repousser_expiration:
|
||||
finish:
|
||||
text_success:
|
||||
one: "%{success_count}/1 dossier sera conservé 1 mois supplémentaire"
|
||||
other: "%{success_count}/%{count} dossiers seront conservé 1 mois supplémentaire"
|
||||
in_progress:
|
||||
text_success:
|
||||
one: "1 dossier est en cours d'être conservé 1 mois supplémentaire"
|
||||
other: "%{success_count}/%{count} dossiers seront conservé 1 mois supplémentaire"
|
||||
accepter:
|
||||
finish:
|
||||
text_success:
|
||||
|
@ -35,6 +53,24 @@ fr:
|
|||
text_success:
|
||||
one: "1 dossier est en cours de refus"
|
||||
other: "%{success_count}/%{count} dossiers ont été refusés"
|
||||
supprimer:
|
||||
finish:
|
||||
text_success:
|
||||
one: "%{success_count}/1 dossier a été supprimé"
|
||||
other: "%{success_count}/%{count} dossiers ont été supprimés"
|
||||
in_progress:
|
||||
text_success:
|
||||
one: "1 dossier est en cours de suppression"
|
||||
other: "%{success_count}/%{count} dossiers ont été supprimés"
|
||||
restaurer:
|
||||
finish:
|
||||
text_success:
|
||||
one: "%{success_count}/1 dossier a été restauré"
|
||||
other: "%{success_count}/%{count} dossiers ont été restaurés"
|
||||
in_progress:
|
||||
text_success:
|
||||
one: "1 dossier est en cours de restauration"
|
||||
other: "%{success_count}/%{count} dossiers ont été restaurés"
|
||||
classer_sans_suite:
|
||||
finish:
|
||||
text_success:
|
||||
|
|
|
@ -7,17 +7,23 @@ class Dossiers::BatchOperationComponent < ApplicationComponent
|
|||
end
|
||||
|
||||
def render?
|
||||
['a-suivre', 'traites', 'suivis'].include?(@statut)
|
||||
['a-suivre', 'traites', 'suivis', 'archives', 'supprimes_recemment', 'expirant'].include?(@statut)
|
||||
end
|
||||
|
||||
def operations_for_dossier(dossier)
|
||||
case dossier.state
|
||||
when Dossier.states.fetch(:en_construction)
|
||||
[BatchOperation.operations.fetch(:passer_en_instruction)]
|
||||
[BatchOperation.operations.fetch(:passer_en_instruction), BatchOperation.operations.fetch(:repousser_expiration)]
|
||||
when Dossier.states.fetch(:en_instruction)
|
||||
[BatchOperation.operations.fetch(:accepter), BatchOperation.operations.fetch(:refuser), BatchOperation.operations.fetch(:classer_sans_suite), BatchOperation.operations.fetch(:repasser_en_construction)]
|
||||
[
|
||||
BatchOperation.operations.fetch(:accepter), BatchOperation.operations.fetch(:refuser),
|
||||
BatchOperation.operations.fetch(:classer_sans_suite), BatchOperation.operations.fetch(:repasser_en_construction)
|
||||
]
|
||||
when Dossier.states.fetch(:accepte), Dossier.states.fetch(:refuse), Dossier.states.fetch(:sans_suite)
|
||||
[BatchOperation.operations.fetch(:archiver)]
|
||||
[
|
||||
BatchOperation.operations.fetch(:archiver), BatchOperation.operations.fetch(:desarchiver), BatchOperation.operations.fetch(:supprimer),
|
||||
BatchOperation.operations.fetch(:restaurer), BatchOperation.operations.fetch(:repousser_expiration)
|
||||
]
|
||||
else
|
||||
[]
|
||||
end.append(BatchOperation.operations.fetch(:follow), BatchOperation.operations.fetch(:unfollow))
|
||||
|
@ -31,12 +37,26 @@ class Dossiers::BatchOperationComponent < ApplicationComponent
|
|||
{
|
||||
options:
|
||||
[
|
||||
{
|
||||
label: t(".operations.passer_en_instruction"),
|
||||
operation: BatchOperation.operations.fetch(:passer_en_instruction)
|
||||
},
|
||||
{
|
||||
label: t(".operations.follow"),
|
||||
operation: BatchOperation.operations.fetch(:follow)
|
||||
}
|
||||
]
|
||||
}
|
||||
when 'archives' then
|
||||
{
|
||||
options:
|
||||
[
|
||||
{
|
||||
label: t(".operations.desarchiver"),
|
||||
operation: BatchOperation.operations.fetch(:desarchiver)
|
||||
}
|
||||
]
|
||||
}
|
||||
when 'traites' then
|
||||
{
|
||||
options:
|
||||
|
@ -44,6 +64,30 @@ class Dossiers::BatchOperationComponent < ApplicationComponent
|
|||
{
|
||||
label: t(".operations.archiver"),
|
||||
operation: BatchOperation.operations.fetch(:archiver)
|
||||
},
|
||||
{
|
||||
label: t(".operations.supprimer"),
|
||||
operation: BatchOperation.operations.fetch(:supprimer)
|
||||
}
|
||||
]
|
||||
}
|
||||
when 'expirant' then
|
||||
{
|
||||
options:
|
||||
[
|
||||
{
|
||||
label: t(".operations.repousser_expiration"),
|
||||
operation: BatchOperation.operations.fetch(:repousser_expiration)
|
||||
}
|
||||
]
|
||||
}
|
||||
when 'supprimes_recemment' then
|
||||
{
|
||||
options:
|
||||
[
|
||||
{
|
||||
label: t(".operations.restaurer"),
|
||||
operation: BatchOperation.operations.fetch(:restaurer)
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -110,9 +154,12 @@ class Dossiers::BatchOperationComponent < ApplicationComponent
|
|||
{
|
||||
accepter: 'fr-icon-success-line',
|
||||
archiver: 'fr-icon-folder-2-line',
|
||||
desarchiver: 'fr-icon-upload-2-line',
|
||||
follow: 'fr-icon-star-line',
|
||||
passer_en_instruction: 'fr-icon-edit-line',
|
||||
repasser_en_construction: 'fr-icon-draft-line',
|
||||
supprimer: 'fr-icon-delete-line',
|
||||
restaurer: 'fr-icon-refresh-line',
|
||||
unfollow: 'fr-icon-star-fill'
|
||||
}
|
||||
end
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
fr:
|
||||
operations:
|
||||
archiver: 'Archive selected files'
|
||||
desarchiver: 'Unarchive selected files'
|
||||
passer_en_instruction: 'Change selected files to instructing'
|
||||
instruction: Instructing files
|
||||
repousser_expiration: Keep for one more month
|
||||
accepter: 'Accept seleted files'
|
||||
supprimer: Delete seleted files
|
||||
restaurer: Restore seleted files
|
||||
accepter_description: Users will be notified that their file has been accepted
|
||||
refuser: 'Refuse seleted files'
|
||||
refuser_description: Users will be notified that their file has been refused
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
fr:
|
||||
operations:
|
||||
archiver: 'Archiver les dossiers'
|
||||
desarchiver: 'Désarchiver les dossiers'
|
||||
passer_en_instruction: 'Passer les dossiers en instruction'
|
||||
instruction: Instruire les dossiers
|
||||
repousser_expiration: Conserver un mois de plus
|
||||
accepter: 'Accepter les dossiers'
|
||||
supprimer: 'Supprimer les dossiers'
|
||||
restaurer: 'Restaurer les dossiers'
|
||||
accepter_description: Les usagers seront informés que leur dossier a été accepté
|
||||
refuser: 'Refuser les dossiers'
|
||||
refuser_description: Les usagers seront informés que leur dossier a été refusé
|
||||
|
|
|
@ -4,10 +4,14 @@ class BatchOperation < ApplicationRecord
|
|||
refuser: 'refuser',
|
||||
classer_sans_suite: 'classer_sans_suite',
|
||||
archiver: 'archiver',
|
||||
desarchiver: 'desarchiver',
|
||||
follow: 'follow',
|
||||
passer_en_instruction: 'passer_en_instruction',
|
||||
repousser_expiration: 'repousser_expiration',
|
||||
repasser_en_construction: 'repasser_en_construction',
|
||||
unfollow: 'unfollow'
|
||||
restaurer: 'restaurer',
|
||||
unfollow: 'unfollow',
|
||||
supprimer: 'supprimer'
|
||||
}
|
||||
|
||||
has_many :dossiers, dependent: :nullify
|
||||
|
@ -37,25 +41,32 @@ class BatchOperation < ApplicationRecord
|
|||
def dossiers_safe_scope(dossier_ids = self.dossier_ids)
|
||||
query = instructeur
|
||||
.dossiers
|
||||
.visible_by_administration
|
||||
.where(id: dossier_ids)
|
||||
case operation
|
||||
when BatchOperation.operations.fetch(:archiver) then
|
||||
query.not_archived.state_termine
|
||||
query.visible_by_administration.not_archived.state_termine
|
||||
when BatchOperation.operations.fetch(:desarchiver) then
|
||||
query.visible_by_administration.archived.state_termine
|
||||
when BatchOperation.operations.fetch(:passer_en_instruction) then
|
||||
query.state_en_construction
|
||||
query.visible_by_administration.state_en_construction
|
||||
when BatchOperation.operations.fetch(:accepter) then
|
||||
query.state_en_instruction
|
||||
query.visible_by_administration.state_en_instruction
|
||||
when BatchOperation.operations.fetch(:refuser) then
|
||||
query.state_en_instruction
|
||||
query.visible_by_administration.state_en_instruction
|
||||
when BatchOperation.operations.fetch(:classer_sans_suite) then
|
||||
query.state_en_instruction
|
||||
query.visible_by_administration.state_en_instruction
|
||||
when BatchOperation.operations.fetch(:follow) then
|
||||
query.without_followers.en_cours
|
||||
query.visible_by_administration.without_followers.en_cours
|
||||
when BatchOperation.operations.fetch(:repousser_expiration) then
|
||||
query.visible_by_administration.termine_or_en_construction_close_to_expiration
|
||||
when BatchOperation.operations.fetch(:repasser_en_construction) then
|
||||
query.state_en_instruction
|
||||
query.visible_by_administration.state_en_instruction
|
||||
when BatchOperation.operations.fetch(:unfollow) then
|
||||
query.with_followers.en_cours
|
||||
query.visible_by_administration.with_followers.en_cours
|
||||
when BatchOperation.operations.fetch(:supprimer) then
|
||||
query.visible_by_administration.state_termine
|
||||
when BatchOperation.operations.fetch(:restaurer) then
|
||||
query.hidden_by_administration
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -68,6 +79,8 @@ class BatchOperation < ApplicationRecord
|
|||
case operation
|
||||
when BatchOperation.operations.fetch(:archiver)
|
||||
dossier.archiver!(instructeur)
|
||||
when BatchOperation.operations.fetch(:desarchiver)
|
||||
dossier.desarchiver!
|
||||
when BatchOperation.operations.fetch(:passer_en_instruction)
|
||||
dossier.passer_en_instruction(instructeur: instructeur)
|
||||
when BatchOperation.operations.fetch(:accepter)
|
||||
|
@ -78,10 +91,16 @@ class BatchOperation < ApplicationRecord
|
|||
dossier.classer_sans_suite(instructeur: instructeur, motivation: motivation, justificatif: justificatif_motivation)
|
||||
when BatchOperation.operations.fetch(:follow)
|
||||
instructeur.follow(dossier)
|
||||
when BatchOperation.operations.fetch(:repousser_expiration)
|
||||
dossier.extend_conservation(1.month)
|
||||
when BatchOperation.operations.fetch(:repasser_en_construction)
|
||||
dossier.repasser_en_construction!(instructeur: instructeur)
|
||||
when BatchOperation.operations.fetch(:unfollow)
|
||||
instructeur.unfollow(dossier)
|
||||
when BatchOperation.operations.fetch(:supprimer)
|
||||
dossier.hide_and_keep_track!(instructeur, :instructeur_request)
|
||||
when BatchOperation.operations.fetch(:restaurer)
|
||||
dossier.restore(instructeur)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -58,6 +58,60 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'desarchiver' do
|
||||
let(:component) do
|
||||
described_class.new(
|
||||
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: :desarchiver, 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é désarchivés") }
|
||||
it { is_expected.to have_text("Cette opération a été lancée par #{instructeur.email}, il y a moins d'une minute") }
|
||||
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é désarchivé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é désarchivés") }
|
||||
it { expect(batch_operation.seen_at).to eq(nil) }
|
||||
|
||||
it 'on next render "seen_at" is set to avoid rendering alert' do
|
||||
render_inline(component).to_html
|
||||
expect(batch_operation.seen_at).not_to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'passer_en_instruction' do
|
||||
let(:component) do
|
||||
described_class.new(
|
||||
|
@ -112,6 +166,60 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'repousser_expiration' do
|
||||
let(:component) do
|
||||
described_class.new(
|
||||
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: :repousser_expiration, 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 seront conservé 1 mois supplémentaire") }
|
||||
it { is_expected.to have_text("Cette opération a été lancée par #{instructeur.email}, il y a moins d'une minute") }
|
||||
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 seront conservé 1 mois supplémentaire") }
|
||||
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 seront conservé 1 mois supplémentaire") }
|
||||
it { expect(batch_operation.seen_at).to eq(nil) }
|
||||
|
||||
it 'on next render "seen_at" is set to avoid rendering alert' do
|
||||
render_inline(component).to_html
|
||||
expect(batch_operation.seen_at).not_to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'accepter' do
|
||||
let(:component) do
|
||||
described_class.new(
|
||||
|
@ -346,6 +454,60 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'restaurer' do
|
||||
let(:component) do
|
||||
described_class.new(
|
||||
batch: batch_operation,
|
||||
procedure: procedure
|
||||
)
|
||||
end
|
||||
let!(:dossier) { create(:dossier, :accepte, procedure: procedure, hidden_by_administration_at: Time.zone.now) }
|
||||
let!(:dossier_2) { create(:dossier, :accepte, procedure: procedure, hidden_by_administration_at: Time.zone.now) }
|
||||
let!(:batch_operation) { create(:batch_operation, operation: :restaurer, 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é restauré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é restauré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é restaurés") }
|
||||
it { expect(batch_operation.seen_at).to eq(nil) }
|
||||
|
||||
it 'on next render "seen_at" is set to avoid rendering alert' do
|
||||
render_inline(component).to_html
|
||||
expect(batch_operation.seen_at).not_to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'repasser en construction' do
|
||||
let(:component) do
|
||||
described_class.new(
|
||||
|
@ -399,4 +561,58 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'supprimer' do
|
||||
let(:component) do
|
||||
described_class.new(
|
||||
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: :supprimer, 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é supprimé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é supprimé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é supprimés") }
|
||||
it { expect(batch_operation.seen_at).to eq(nil) }
|
||||
|
||||
it 'on next render "seen_at" is set to avoid rendering alert' do
|
||||
render_inline(component).to_html
|
||||
expect(batch_operation.seen_at).not_to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,6 +18,18 @@ FactoryBot.define do
|
|||
end
|
||||
end
|
||||
|
||||
trait :desarchiver do
|
||||
operation { BatchOperation.operations.fetch(:desarchiver) }
|
||||
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, :accepte, procedure: procedure, archived: true),
|
||||
create(:dossier, :with_individual, :refuse, procedure: procedure, archived: true),
|
||||
create(:dossier, :with_individual, :sans_suite, procedure: procedure, archived: true)
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
trait :passer_en_instruction do
|
||||
operation { BatchOperation.operations.fetch(:passer_en_instruction) }
|
||||
after(:build) do |batch_operation, evaluator|
|
||||
|
@ -29,6 +41,17 @@ FactoryBot.define do
|
|||
end
|
||||
end
|
||||
|
||||
trait :repousser_expiration do
|
||||
operation { BatchOperation.operations.fetch(:repousser_expiration) }
|
||||
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, :accepte, procedure: procedure, processed_at: 12.months.ago),
|
||||
create(:dossier, :with_individual, :accepte, procedure: procedure, processed_at: 12.months.ago)
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
trait :accepter do
|
||||
operation { BatchOperation.operations.fetch(:accepter) }
|
||||
after(:build) do |batch_operation, evaluator|
|
||||
|
@ -84,6 +107,17 @@ FactoryBot.define do
|
|||
end
|
||||
end
|
||||
|
||||
trait :restaurer do
|
||||
operation { BatchOperation.operations.fetch(:restaurer) }
|
||||
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, :accepte, procedure: procedure, hidden_by_administration_at: Time.zone.now),
|
||||
create(:dossier, :with_individual, :refuse, procedure: procedure, hidden_by_administration_at: Time.zone.now)
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
trait :repasser_en_construction do
|
||||
operation { BatchOperation.operations.fetch(:repasser_en_construction) }
|
||||
after(:build) do |batch_operation, evaluator|
|
||||
|
@ -94,5 +128,16 @@ FactoryBot.define do
|
|||
]
|
||||
end
|
||||
end
|
||||
|
||||
trait :supprimer do
|
||||
operation { BatchOperation.operations.fetch(:supprimer) }
|
||||
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, :accepte, procedure: procedure),
|
||||
create(:dossier, :with_individual, :refuse, procedure: procedure)
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,6 +32,19 @@ describe BatchOperationProcessOneJob, type: :job do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when operation is "desarchiver"' do
|
||||
let(:batch_operation) do
|
||||
create(:batch_operation, :desarchiver,
|
||||
options.merge(instructeur: create(:instructeur)))
|
||||
end
|
||||
it 'archives the dossier in the batch' do
|
||||
expect { subject.perform_now }
|
||||
.to change { dossier_job.reload.archived? }
|
||||
.from(true)
|
||||
.to(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when operation is "passer_en_instruction"' do
|
||||
let(:batch_operation) do
|
||||
create(:batch_operation, :passer_en_instruction,
|
||||
|
@ -46,6 +59,19 @@ describe BatchOperationProcessOneJob, type: :job do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when operation is "repousser_expiration"' do
|
||||
let(:batch_operation) do
|
||||
create(:batch_operation, :repousser_expiration,
|
||||
options.merge(instructeur: create(:instructeur)))
|
||||
end
|
||||
it 'archives the dossier in the batch' do
|
||||
expect { subject.perform_now }
|
||||
.to change { dossier_job.reload.conservation_extension }
|
||||
.from(dossier_job.conservation_extension)
|
||||
.to(dossier_job.conservation_extension + 1.month)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when operation is "follow"' do
|
||||
let(:batch_operation) do
|
||||
create(:batch_operation, :follow,
|
||||
|
@ -175,6 +201,20 @@ describe BatchOperationProcessOneJob, type: :job do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when operation is "restaurer"' do
|
||||
let(:batch_operation) do
|
||||
create(:batch_operation, :restaurer,
|
||||
options.merge(instructeur: create(:instructeur)))
|
||||
end
|
||||
|
||||
it 'changed the dossier to en construction' do
|
||||
expect { subject.perform_now }
|
||||
.to change { dossier_job.reload.hidden_by_administration? }
|
||||
.from(true)
|
||||
.to(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when operation is "classer_sans_suite"' do
|
||||
let(:batch_operation) do
|
||||
create(:batch_operation, :classer_sans_suite,
|
||||
|
@ -196,6 +236,20 @@ describe BatchOperationProcessOneJob, type: :job do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when operation is "supprimer"' do
|
||||
let(:batch_operation) do
|
||||
create(:batch_operation, :supprimer,
|
||||
options.merge(instructeur: create(:instructeur)))
|
||||
end
|
||||
|
||||
it 'changed the dossier to en construction' do
|
||||
expect { subject.perform_now }
|
||||
.to change { dossier_job.reload.hidden_by_administration? }
|
||||
.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
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
let(:procedure) { create(:simple_procedure, instructeurs: [instructeur]) }
|
||||
|
|
Loading…
Reference in a new issue