Merge pull request #10069 from mfo/US/fix-spread-dossier-deletion-task

tech(spread_dossier_deletion_task): query on date time range not on date
This commit is contained in:
Paul Chavard 2024-03-05 15:27:09 +00:00 committed by GitHub
commit a9bf809ea3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 6 deletions

View file

@ -3,10 +3,11 @@
module Maintenance
class SpreadDossierDeletionTask < MaintenanceTasks::Task
ERROR_OCCURED_AT = Date.new(2024, 2, 14)
ERROR_OCCURED_RANGE = ERROR_OCCURED_AT.at_midnight..(ERROR_OCCURED_AT + 1.day)
SPREAD_DURATION_IN_DAYS = 150
def collection
Dossier.where(termine_close_to_expiration_notice_sent_at: ERROR_OCCURED_AT)
Dossier.where(termine_close_to_expiration_notice_sent_at: ERROR_OCCURED_RANGE)
.in_batches
end

View file

@ -6,14 +6,17 @@ module Maintenance
RSpec.describe SpreadDossierDeletionTask do
describe "#process" do
let(:dossiers) { Dossier.all }
let(:dossier_1) { create(:dossier, termine_close_to_expiration_notice_sent_at: Date.new(2024, 2, 14)) }
let(:dossier_2) { create(:dossier, termine_close_to_expiration_notice_sent_at: Date.new(2024, 2, 14)) }
let(:dossier_3) { create(:dossier, termine_close_to_expiration_notice_sent_at: Date.new(2024, 2, 14)) }
let(:dossier_4) { create(:dossier, termine_close_to_expiration_notice_sent_at: Date.new(2024, 2, 14)) }
before do
create(:dossier, termine_close_to_expiration_notice_sent_at: Maintenance::SpreadDossierDeletionTask::ERROR_OCCURED_AT + 1.hour)
create(:dossier, termine_close_to_expiration_notice_sent_at: Maintenance::SpreadDossierDeletionTask::ERROR_OCCURED_AT + 2.hours)
create(:dossier, termine_close_to_expiration_notice_sent_at: Maintenance::SpreadDossierDeletionTask::ERROR_OCCURED_AT + 3.hours)
create(:dossier, termine_close_to_expiration_notice_sent_at: Maintenance::SpreadDossierDeletionTask::ERROR_OCCURED_AT + 4.hours)
end
subject(:process) { described_class.process(dossiers) }
it "works" do
expect { subject }.to change { dossier_1.reload.termine_close_to_expiration_notice_sent_at }
expect { subject }.to change { Dossier.where(termine_close_to_expiration_notice_sent_at: Maintenance::SpreadDossierDeletionTask::ERROR_OCCURED_RANGE).count }
.from(4).to(0)
end
end
end