diff --git a/app/services/sva_svr_decision_date_calculator_service.rb b/app/services/sva_svr_decision_date_calculator_service.rb index 7a7e6cc4488..ec8c9e8296d 100644 --- a/app/services/sva_svr_decision_date_calculator_service.rb +++ b/app/services/sva_svr_decision_date_calculator_service.rb @@ -59,7 +59,7 @@ def latest_incomplete_correction_date 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) diff --git a/spec/services/sva_svr_decision_date_calculator_service_spec.rb b/spec/services/sva_svr_decision_date_calculator_service_spec.rb index 9cc7b5cdf4d..0100250a259 100644 --- a/spec/services/sva_svr_decision_date_calculator_service_spec.rb +++ b/spec/services/sva_svr_decision_date_calculator_service_spec.rb @@ -139,6 +139,20 @@ 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