fix(ProcedureExportService): downloadable_sorted_batch is scoped by export, no need to re-filter them via downloadablable_sorted_batch otherwise export for supprimes_recemment does not includes dossier.supprimes_recemment

This commit is contained in:
Martin 2022-10-10 10:55:31 +02:00 committed by mfo
parent 8f2d0168e5
commit c921e6e1ee
3 changed files with 37 additions and 19 deletions

View file

@ -241,19 +241,8 @@ class Dossier < ApplicationRecord
.joins(:traitements)
.where(traitements: { processed_at: date.beginning_of_month..date.end_of_month })
end
scope :downloadable_sorted, -> {
state_not_brouillon
.visible_by_administration
.includes(
:user,
:individual,
:followers_instructeurs,
:traitement,
:groupe_instructeur,
:etablissement,
procedure: [:groupe_instructeurs],
avis: [:claimant, :expert]
).order(depose_at: 'asc')
scope :ordered_for_export, -> {
order(depose_at: 'asc')
}
scope :en_cours, -> { not_archived.state_en_construction_ou_instruction }
scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) }
@ -434,7 +423,16 @@ class Dossier < ApplicationRecord
end
def self.downloadable_sorted_batch
DossierPreloader.new(downloadable_sorted).in_batches
DossierPreloader.new(includes(
:user,
:individual,
:followers_instructeurs,
:traitement,
:groupe_instructeur,
:etablissement,
procedure: [:groupe_instructeurs],
avis: [:claimant, :expert]
).ordered_for_export).in_batches
end
def user_deleted?

View file

@ -597,14 +597,13 @@ describe Dossier do
end
end
describe '.downloadable_sorted' do
describe '.ordered_for_export' do
let(:procedure) { create(:procedure) }
let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:brouillon)) }
let!(:dossier2) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_construction), depose_at: Time.zone.parse('03/01/2010')) }
let!(:dossier3) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_instruction), depose_at: Time.zone.parse('01/01/2010')) }
let!(:dossier4) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_instruction), archived: true, depose_at: Time.zone.parse('02/01/2010')) }
subject { procedure.dossiers.downloadable_sorted }
subject { procedure.dossiers.ordered_for_export }
it { is_expected.to match([dossier3, dossier4, dossier2]) }
end

View file

@ -67,16 +67,23 @@ RSpec.describe Export, type: :model do
end
describe '.dossiers_for_export' do
let!(:procedure) { create(:procedure, :published) }
let!(:procedure) { create(:procedure, :published, :with_instructeur) }
let!(:dossier_brouillon) { create(:dossier, :brouillon, procedure: procedure) }
let!(:dossier_en_construction) { create(:dossier, :en_construction, procedure: procedure) }
let!(:dossier_en_instruction) { create(:dossier, :en_instruction, procedure: procedure) }
let!(:dossier_accepte) { create(:dossier, :accepte, procedure: procedure) }
let(:export) { create(:export, groupe_instructeurs: [procedure.groupe_instructeurs.first]) }
let(:export) do
create(:export,
groupe_instructeurs: [procedure.groupe_instructeurs.first],
procedure_presentation: procedure_presentation,
statut: statut)
end
context 'without procedure_presentation or since' do
let(:procedure_presentation) { nil }
let(:statut) { nil }
it 'does not includes brouillons' do
expect(export.send(:dossiers_for_export)).to include(dossier_en_construction)
expect(export.send(:dossiers_for_export)).to include(dossier_en_instruction)
@ -84,5 +91,19 @@ RSpec.describe Export, type: :model do
expect(export.send(:dossiers_for_export)).not_to include(dossier_brouillon)
end
end
context 'with procedure_presentation and statut supprimes_recemment' do
let(:statut) { 'supprimes_recemment' }
let(:procedure_presentation) do
create(:procedure_presentation,
procedure: procedure,
assign_to: procedure.groupe_instructeurs.first.assign_tos.first)
end
let!(:dossier_recemment_supprime) { create(:dossier, :accepte, procedure: procedure, hidden_by_administration_at: 2.days.ago) }
it 'includes supprimes_recemment' do
expect(export.send(:dossiers_for_export)).to include(dossier_recemment_supprime)
end
end
end
end