Do not notify not visible dossiers
This commit is contained in:
parent
9fabef0ac7
commit
53ce0e05f6
4 changed files with 12 additions and 2 deletions
|
@ -5,6 +5,7 @@ class Cron::NotifyOldBrouillonDossiersSoonDeletedJob < Cron::CronJob
|
|||
|
||||
def perform
|
||||
Dossier
|
||||
.visible_by_user
|
||||
.state_brouillon
|
||||
.where(updated_at: ..3.months.ago)
|
||||
.where("notified_soon_deleted_sent_at IS NULL OR notified_soon_deleted_sent_at < updated_at")
|
||||
|
|
|
@ -5,6 +5,7 @@ class Cron::PurgeOldBrouillonDossiersJob < Cron::CronJob
|
|||
|
||||
def perform
|
||||
Dossier
|
||||
.visible_by_user
|
||||
.state_brouillon
|
||||
.where(updated_at: ..(3.months + 2.weeks).ago)
|
||||
.find_each do |dossier|
|
||||
|
|
|
@ -18,6 +18,8 @@ RSpec.describe Cron::NotifyOldBrouillonDossiersSoonDeletedJob, type: :job do
|
|||
end
|
||||
let!(:recent_draft) { travel_to(2.months.ago) { create(:dossier, :brouillon) } }
|
||||
let!(:old_non_draft) { travel_to(4.months.ago) { create(:dossier, :en_construction) } }
|
||||
let!(:not_visible_dossier) { travel_to(6.months.ago) { create(:dossier, :brouillon, :hidden_by_user) } }
|
||||
let!(:not_visible_dossier2) { travel_to(6.months.ago) { create(:dossier, :brouillon, :hidden_by_expired) } }
|
||||
|
||||
it "sends notifications only for eligible draft dossiers" do
|
||||
expect(DossierMailer).to receive(:notify_old_brouillon_soon_deleted)
|
||||
|
@ -30,8 +32,10 @@ RSpec.describe Cron::NotifyOldBrouillonDossiersSoonDeletedJob, type: :job do
|
|||
.and_return(double(deliver_later: true))
|
||||
.once
|
||||
|
||||
expect(DossierMailer).not_to receive(:notify_old_brouillon_soon_deleted)
|
||||
.with(old_draft_recently_notified)
|
||||
[old_draft_recently_notified, not_visible_dossier, not_visible_dossier2].each do |dossier|
|
||||
expect(DossierMailer).not_to receive(:notify_old_brouillon_soon_deleted)
|
||||
.with(dossier)
|
||||
end
|
||||
|
||||
job.perform
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ RSpec.describe Cron::PurgeOldBrouillonDossiersJob, type: :job do
|
|||
let!(:old_brouillon) { travel_to(5.months.ago) { create(:dossier, :brouillon, procedure: procedure) } }
|
||||
let!(:very_old_brouillon) { travel_to(6.months.ago) { create(:dossier, :brouillon, procedure: procedure) } }
|
||||
let!(:old_en_construction) { travel_to(5.months.ago) { create(:dossier, :en_construction, procedure: procedure) } }
|
||||
let!(:not_visible_dossier) { travel_to(6.months.ago) { create(:dossier, :brouillon, :hidden_by_user, procedure: procedure) } }
|
||||
let!(:not_visible_dossier2) { travel_to(6.months.ago) { create(:dossier, :brouillon, :hidden_by_expired, procedure: procedure) } }
|
||||
|
||||
subject(:perform_job) { described_class.perform_now }
|
||||
|
||||
|
@ -28,6 +30,8 @@ RSpec.describe Cron::PurgeOldBrouillonDossiersJob, type: :job do
|
|||
expect(DossierMailer).to have_received(:notify_old_brouillon_after_deletion).with(very_old_brouillon).once
|
||||
expect(DossierMailer).not_to have_received(:notify_old_brouillon_after_deletion).with(recent_brouillon)
|
||||
expect(DossierMailer).not_to have_received(:notify_old_brouillon_after_deletion).with(old_en_construction)
|
||||
expect(DossierMailer).not_to have_received(:notify_old_brouillon_after_deletion).with(not_visible_dossier)
|
||||
expect(DossierMailer).not_to have_received(:notify_old_brouillon_after_deletion).with(not_visible_dossier2)
|
||||
end
|
||||
|
||||
it 'sets the correct hidden_by attributes' do
|
||||
|
|
Loading…
Reference in a new issue