feat(Dossier.close_to_expiration): add method to find any kind of dossier close to expiration [reuse previous scopes], add missing spec to termine_close_to_expiration, complement spec for each kind of expiration scope with general close_to_expiration spec
This commit is contained in:
parent
d8257284ef
commit
608a85148f
3 changed files with 73 additions and 4 deletions
|
@ -330,10 +330,14 @@ class Dossier < ApplicationRecord
|
|||
# .where("dossiers.processed_at + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
|
||||
# end
|
||||
# TODO/MFO
|
||||
scope :termine_close_to_expiration, -> do
|
||||
state_termine
|
||||
.joins(:procedure)
|
||||
.where(id: Traitement.termine_close_to_expiration.select(:dossier_id).distinct)
|
||||
|
||||
scope :close_to_expiration, -> do
|
||||
joins(:procedure).scoping do
|
||||
state_brouillon.and(interval_brouillon_close_to_expiration)
|
||||
.or(state_en_construction.and(interval_en_construction_close_to_expiration))
|
||||
.or(state_en_instruction.and(interval_en_instruction_close_to_expiration))
|
||||
.or(state_termine.and(interval_termine_close_to_expiration))
|
||||
end
|
||||
end
|
||||
|
||||
scope :brouillon_expired, -> do
|
||||
|
|
8
spec/factories/traitement.rb
Normal file
8
spec/factories/traitement.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
FactoryBot.define do
|
||||
factory :traitement do
|
||||
trait :accepte do
|
||||
process_expired {true}
|
||||
state {:accepte}
|
||||
end
|
||||
end
|
||||
end
|
|
@ -61,6 +61,16 @@ describe Dossier do
|
|||
|
||||
it { is_expected.not_to include(expiring_dossier) }
|
||||
end
|
||||
|
||||
context 'when .close_to_expiration' do
|
||||
subject { Dossier.close_to_expiration }
|
||||
it do
|
||||
is_expected.not_to include(young_dossier)
|
||||
is_expected.to include(expiring_dossier)
|
||||
is_expected.to include(just_expired_dossier)
|
||||
is_expected.to include(long_expired_dossier)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'en_construction_close_to_expiration' do
|
||||
|
@ -87,6 +97,16 @@ describe Dossier do
|
|||
|
||||
it { is_expected.not_to include(expiring_dossier) }
|
||||
end
|
||||
|
||||
context 'when .close_to_expiration' do
|
||||
subject { Dossier.close_to_expiration }
|
||||
it do
|
||||
is_expected.not_to include(young_dossier)
|
||||
is_expected.to include(expiring_dossier)
|
||||
is_expected.to include(just_expired_dossier)
|
||||
is_expected.to include(long_expired_dossier)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'en_instruction_close_to_expiration' do
|
||||
|
@ -104,6 +124,43 @@ describe Dossier do
|
|||
is_expected.to include(just_expired_dossier)
|
||||
is_expected.to include(long_expired_dossier)
|
||||
end
|
||||
|
||||
context 'when .close_to_expiration' do
|
||||
subject { Dossier.close_to_expiration }
|
||||
it do
|
||||
is_expected.not_to include(young_dossier)
|
||||
is_expected.to include(expiring_dossier)
|
||||
is_expected.to include(just_expired_dossier)
|
||||
is_expected.to include(long_expired_dossier)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'termine_close_to_expiration' do
|
||||
let(:procedure) { create(:procedure, :published, duree_conservation_dossiers_dans_ds: 6) }
|
||||
let!(:young_dossier) { create(:dossier, :accepte, procedure: procedure, traitements: [build(:traitement, :accepte)]) }
|
||||
let!(:expiring_dossier) { create(:dossier, :accepte, procedure: procedure, traitements: [build(:traitement, :accepte, processed_at: 175.days.ago)]) }
|
||||
let!(:just_expired_dossier) { create(:dossier, :accepte, procedure: procedure, traitements: [build(:traitement, :accepte, processed_at: (6.months + 1.hour + 10.seconds).ago)]) }
|
||||
let!(:long_expired_dossier) { create(:dossier, :accepte, procedure: procedure, traitements: [build(:traitement, :accepte, processed_at: 1.year.ago)]) }
|
||||
|
||||
subject { Dossier.termine_close_to_expiration }
|
||||
|
||||
it do
|
||||
is_expected.not_to include(young_dossier)
|
||||
is_expected.to include(expiring_dossier)
|
||||
is_expected.to include(just_expired_dossier)
|
||||
is_expected.to include(long_expired_dossier)
|
||||
end
|
||||
|
||||
context 'when .close_to_expiration' do
|
||||
subject { Dossier.close_to_expiration }
|
||||
it do
|
||||
is_expected.not_to include(young_dossier)
|
||||
is_expected.to include(expiring_dossier)
|
||||
is_expected.to include(just_expired_dossier)
|
||||
is_expected.to include(long_expired_dossier)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with_notifications' do
|
||||
|
|
Loading…
Add table
Reference in a new issue