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:
commit
a9bf809ea3
2 changed files with 10 additions and 6 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue