From f369775d5ba85c5949b7981867339438d98529d8 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 21 Jun 2023 11:59:38 +0200 Subject: [PATCH] fix(sva): compute decision date from the day after deposit or resolution --- ...va_svr_decision_date_calculator_service.rb | 4 +-- spec/models/dossier_spec.rb | 2 +- ...r_decision_date_calculator_service_spec.rb | 26 +++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/services/sva_svr_decision_date_calculator_service.rb b/app/services/sva_svr_decision_date_calculator_service.rb index bc3783e72..82f55fa50 100644 --- a/app/services/sva_svr_decision_date_calculator_service.rb +++ b/app/services/sva_svr_decision_date_calculator_service.rb @@ -14,7 +14,7 @@ class SVASVRDecisionDateCalculatorService def decision_date duration = calculate_duration - start_date = determine_start_date + start_date = determine_start_date + 1.day correction_delay = calculate_correction_delay(start_date) start_date + correction_delay + duration @@ -54,7 +54,7 @@ class SVASVRDecisionDateCalculatorService resolved_date = correction_date(correction) next 0 unless resolved_date > start_date - (resolved_date - correction.created_at.to_date).days + (resolved_date + 1.day - correction.created_at.to_date).days # restart from next day after resolution end end diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index a1c3ec698..67cdb3fff 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -1125,7 +1125,7 @@ describe Dossier, type: :model do it 'passes dossier en instruction' do expect(subject.followers_instructeurs).not_to include(instructeur) - expect(subject.sva_svr_decision_on).to eq(2.months.from_now.to_date) + expect(subject.sva_svr_decision_on).to eq(2.months.from_now.to_date + 1.day) expect(last_operation.operation).to eq('passer_en_instruction') expect(last_operation.automatic_operation?).to be_truthy expect(operation_serialized['operation']).to eq('passer_en_instruction') 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 4eac4a946..71246ee71 100644 --- a/spec/services/sva_svr_decision_date_calculator_service_spec.rb +++ b/spec/services/sva_svr_decision_date_calculator_service_spec.rb @@ -13,7 +13,7 @@ describe SVASVRDecisionDateCalculatorService do let(:config) { { decision: :sva, period: 2, unit: :months, resume: :continue } } it 'calculates the date based on SVA rules' do - expect(subject).to eq(Date.new(2023, 7, 15)) + expect(subject).to eq(Date.new(2023, 7, 16)) end end @@ -21,7 +21,7 @@ describe SVASVRDecisionDateCalculatorService do let(:config) { { decision: :sva, period: 30, unit: :days, resume: :continue } } it 'calculates the date based on SVA rules' do - expect(subject).to eq(Date.new(2023, 6, 14)) + expect(subject).to eq(Date.new(2023, 6, 15)) end end @@ -29,7 +29,7 @@ describe SVASVRDecisionDateCalculatorService do let(:config) { { decision: :sva, period: 8, unit: :weeks, resume: :continue } } it 'calculates the date based on SVA rules' do - expect(subject).to eq(Date.new(2023, 7, 10)) + expect(subject).to eq(Date.new(2023, 7, 11)) end end @@ -44,7 +44,7 @@ describe SVASVRDecisionDateCalculatorService do end it 'calculates the date based on SVA rules with correction delay' do - expect(subject).to eq(Date.new(2023, 7, 20)) + expect(subject).to eq(Date.new(2023, 7, 22)) end context 'when there are multiple corrections' do @@ -55,7 +55,7 @@ describe SVASVRDecisionDateCalculatorService do end it 'calculates the date based on SVA rules with all correction delays' do - expect(subject).to eq(Date.new(2023, 7, 24)) + expect(subject).to eq(Date.new(2023, 7, 27)) end end @@ -65,11 +65,11 @@ describe SVASVRDecisionDateCalculatorService do dossier.flag_as_pending_correction!(build(:commentaire, dossier:)) end - travel_to DateTime.new(2023, 6, 5, 8) # 6 days elapsed + travel_to DateTime.new(2023, 6, 5, 8) # 6 days elapsed, restart 1 day after resolved end it 'calculates the date, like if resolution will be today' do - expect(subject).to eq(Date.new(2023, 7, 26)) + expect(subject).to eq(Date.new(2023, 7, 29)) end end @@ -83,7 +83,7 @@ describe SVASVRDecisionDateCalculatorService do end it 'calculates the date, like if resolution will be today' do - expect(subject).to eq(Date.new(2023, 8, 5)) + expect(subject).to eq(Date.new(2023, 8, 6)) end end @@ -95,7 +95,7 @@ describe SVASVRDecisionDateCalculatorService do end it 'calculates the date by resetting delay' do - expect(subject).to eq(Date.new(2023, 7, 25)) + expect(subject).to eq(Date.new(2023, 7, 26)) end context 'when there are multiple corrections' do @@ -106,7 +106,7 @@ describe SVASVRDecisionDateCalculatorService do end it 'calculates the date based on SVA rules with all correction delays' do - expect(subject).to eq(Date.new(2023, 7, 29)) + expect(subject).to eq(Date.new(2023, 7, 31)) end end end @@ -118,7 +118,7 @@ describe SVASVRDecisionDateCalculatorService do context 'there is no correction' do it 'calculates the date based on deposed_at' do - expect(subject).to eq(Date.new(2023, 7, 15)) + expect(subject).to eq(Date.new(2023, 7, 16)) end end @@ -134,7 +134,7 @@ describe SVASVRDecisionDateCalculatorService do end it 'calculates the date based on SVA rules from the last resolved date' do - expect(subject).to eq(Date.new(2023, 7, 25)) + expect(subject).to eq(Date.new(2023, 7, 26)) end end @@ -148,7 +148,7 @@ describe SVASVRDecisionDateCalculatorService do end it 'calculates the date, like if resolution will be today and delay restarted' do - expect(subject).to eq(Date.new(2023, 8, 5)) + expect(subject).to eq(Date.new(2023, 8, 6)) end end end