fix(sva): when there were resolved corrections and a pending correction

This commit is contained in:
Colin Darie 2024-09-24 12:48:09 +02:00
parent cae524b6bd
commit b50d42fbb4
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
2 changed files with 15 additions and 1 deletions

View file

@ -59,7 +59,7 @@ class SVASVRDecisionDateCalculatorService
end
def latest_correction_date
correction_date dossier.corrections.max_by(&:resolved_at)
correction_date dossier.corrections.max_by { _1.resolved_at || Time.current }
end
def calculate_correction_delay(start_date)

View file

@ -139,6 +139,20 @@ describe SVASVRDecisionDateCalculatorService do
it 'calculates the date based on SVA rules from the last resolved date' do
expect(subject).to eq(Date.new(2023, 7, 26))
end
context 'and a pending correction' do
before do
travel_to Time.zone.local(2023, 5, 30, 18) do
dossier.flag_as_pending_correction!(build(:commentaire, dossier:))
end
travel_to Time.zone.local(2023, 6, 5, 8)
end
it 'calculates the date, like if resolution will be today and delay restarted' do
expect(subject).to eq(Date.new(2023, 8, 6))
end
end
end
context 'there is a pending correction' do