From b50d42fbb44e2a7de04d166832b52cd113ddada7 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Tue, 24 Sep 2024 12:48:09 +0200 Subject: [PATCH] fix(sva): when there were resolved corrections and a pending correction --- .../sva_svr_decision_date_calculator_service.rb | 2 +- ...va_svr_decision_date_calculator_service_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/services/sva_svr_decision_date_calculator_service.rb b/app/services/sva_svr_decision_date_calculator_service.rb index 7a7e6cc44..ec8c9e829 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 @@ 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) 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 9cc7b5cdf..0100250a2 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 @@ 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