Skip to content

Commit

Permalink
amelioration(instructeurs/procedure#show): ETQ instructeur, dans l'on…
Browse files Browse the repository at this point in the history
…glet des dossiers expirant, je veux voir les dossiers qui seront supprimés pour cause d'usager inactif
  • Loading branch information
Martin committed Nov 6, 2023
1 parent eebb93e commit 69d1916
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/models/dossier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,19 @@ def classer_sans_suite(motivation: nil, instructeur: nil, processed_at: Time.zon
joins(:procedure).scoping do
interval_en_construction_close_to_expiration
.or(interval_termine_close_to_expiration)
.or(where(id: expiring_due_to_user))
end
end

scope :expiring_due_to_user, -> do
state_en_construction
.visible_by_user_or_administration
.where(created_at: ..ExpiredUsersDeletionService::EXPIRABLE_AFTER_IN_YEAR.years.ago)
.joins(:user)
.having('MAX(dossiers.created_at) < ?', ExpiredUsersDeletionService::EXPIRABLE_AFTER_IN_YEAR.years.ago)
.group('dossiers.id')
end

scope :brouillon_expired, -> do
state_brouillon
.visible_by_user
Expand Down
40 changes: 39 additions & 1 deletion spec/models/dossier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,32 @@
is_expected.to include(long_expired_dossier)
end
end
end

describe '.termine_or_en_construction_close_to_expiration ' do
context 'with expiring user' do
let(:duree_conservation_dossiers_dans_ds) { ExpiredUsersDeletionService::EXPIRABLE_AFTER_IN_YEAR * 12 + 2 }
let(:expiring_user_created_at) { (ExpiredUsersDeletionService::EXPIRABLE_AFTER_IN_YEAR.years + 1.month).ago }
let(:not_expiring_user_created_at) { (ExpiredUsersDeletionService::EXPIRABLE_AFTER_IN_YEAR.years - 1.month).ago }
let(:procedure) { create(:procedure, :published, duree_conservation_dossiers_dans_ds:, procedure_expires_when_termine_enabled: true) }
let!(:expired_dossier_by_user) { create(:dossier, :en_construction, procedure:, created_at: expiring_user_created_at, en_construction_at: not_expiring_user_created_at) }
let!(:not_expired_dossier_by_user) { create(:dossier, :en_construction, procedure:, created_at: not_expiring_user_created_at, en_construction_at: not_expiring_user_created_at) }

subject { Dossier.termine_or_en_construction_close_to_expiration }
it do
is_expected.to include(expired_dossier_by_user)
is_expected.not_to include(not_expired_dossier_by_user)
end
end

context 'when dossier termines' do
let(:procedure) { create(:procedure, :published, duree_conservation_dossiers_dans_ds: 6, procedure_expires_when_termine_enabled: true) }
let!(:young_dossier) { create(:dossier, state: :accepte, procedure: procedure, processed_at: 2.days.ago) }
let!(:expiring_dossier) { create(:dossier, state: :accepte, procedure: procedure, processed_at: 175.days.ago) }
let!(:expiring_dossier_with_notification) { create(:dossier, state: :accepte, procedure: procedure, processed_at: 175.days.ago, termine_close_to_expiration_notice_sent_at: Time.zone.now) }
let!(:just_expired_dossier) { create(:dossier, state: :accepte, procedure: procedure, processed_at: (6.months + 1.hour + 10.seconds).ago) }
let!(:long_expired_dossier) { create(:dossier, state: :accepte, procedure: procedure, processed_at: 1.year.ago) }

context 'when .close_to_expiration' do
subject { Dossier.termine_or_en_construction_close_to_expiration }
it do
is_expected.not_to include(young_dossier)
Expand All @@ -230,6 +254,20 @@
end
end

describe '#expiring_due_to_user' do
let(:procedure) { create(:procedure, :published) }
let(:expiring_user_created_at) { (ExpiredUsersDeletionService::EXPIRABLE_AFTER_IN_YEAR + 1).years.ago }
let(:not_expiring_user_created_at) { (ExpiredUsersDeletionService::EXPIRABLE_AFTER_IN_YEAR - 1).years.ago }
let!(:young_dossier) { create(:dossier, :en_construction, created_at: not_expiring_user_created_at, procedure:) }
let!(:expiring_dossier) { create(:dossier, :en_construction, created_at: expiring_user_created_at, procedure:) }

subject { Dossier.expiring_due_to_user }
it do
is_expected.to include(expiring_dossier)
is_expected.not_to include(young_dossier)
end
end

describe 'with_notifications' do
let(:dossier) { create(:dossier) }
let(:instructeur) { create(:instructeur) }
Expand Down

0 comments on commit 69d1916

Please sign in to comment.