From bb7673e6974742db5f57988dc720bffd5da438b1 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Tue, 29 Aug 2023 12:51:39 +0200 Subject: [PATCH] fix(sva): decision date when start date is at end of month and with correction delay --- ...va_svr_decision_date_calculator_service.rb | 2 +- ...cedure_sva_svr_process_dossier_job_spec.rb | 4 ++ ...r_decision_date_calculator_service_spec.rb | 43 ++++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/app/services/sva_svr_decision_date_calculator_service.rb b/app/services/sva_svr_decision_date_calculator_service.rb index 66614e524..c17fd8347 100644 --- a/app/services/sva_svr_decision_date_calculator_service.rb +++ b/app/services/sva_svr_decision_date_calculator_service.rb @@ -28,7 +28,7 @@ class SVASVRDecisionDateCalculatorService start_date = determine_start_date + 1.day correction_delay = calculate_correction_delay(start_date) - start_date + correction_delay + duration + start_date + duration + correction_delay end private diff --git a/spec/jobs/procedure_sva_svr_process_dossier_job_spec.rb b/spec/jobs/procedure_sva_svr_process_dossier_job_spec.rb index 1ce2053eb..b916c4310 100644 --- a/spec/jobs/procedure_sva_svr_process_dossier_job_spec.rb +++ b/spec/jobs/procedure_sva_svr_process_dossier_job_spec.rb @@ -2,6 +2,10 @@ RSpec.describe ProcedureSVASVRProcessDossierJob, type: :job do include ActiveJob::TestHelper include ActiveSupport::Testing::TimeHelpers + before do + travel_to Date.new(2023, 8, 15, 12) + end + let(:procedure) { create(:procedure, :published, :sva, :for_individual) } let!(:dossier) { create(:dossier, :en_instruction, :with_individual, procedure:, depose_at: 2.months.ago - 1.day, sva_svr_decision_on: Date.current) } 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 e6ff87783..ca2d675bb 100644 --- a/spec/services/sva_svr_decision_date_calculator_service_spec.rb +++ b/spec/services/sva_svr_decision_date_calculator_service_spec.rb @@ -4,7 +4,8 @@ describe SVASVRDecisionDateCalculatorService do include ActiveSupport::Testing::TimeHelpers let(:procedure) { create(:procedure, sva_svr: config) } - let(:dossier) { create(:dossier, :en_instruction, procedure:, depose_at: DateTime.new(2023, 5, 15, 12)) } + let(:dossier) { create(:dossier, :en_instruction, procedure:, depose_at:) } + let(:depose_at) { DateTime.new(2023, 5, 15, 12) } describe '#decision_date' do subject { described_class.new(dossier, procedure).decision_date } @@ -152,6 +153,46 @@ describe SVASVRDecisionDateCalculatorService do end end end + + context 'when dossier is deposed at end of month with correction delay' do + let(:config) { { decision: :sva, period: 2, unit: :months, resume: :continue } } + + let!(:correction) do # add 2 days + create(:dossier_correction, dossier:, created_at: depose_at + 1.day, resolved_at: depose_at + 2.days) + end + + context 'start date = 30' do + let(:depose_at) { DateTime.new(2023, 6, 29, 12) } + + it 'calculcates the date accordingly' do + expect(subject).to eq(Date.new(2023, 9, 1)) + end + end + + context 'start date = 31' do + let(:depose_at) { DateTime.new(2023, 7, 30, 12) } + + it 'calculcates the date accordingly' do + expect(subject).to eq(Date.new(2023, 10, 2)) + end + end + + context 'start date = 1 in month having 31 days' do + let(:depose_at) { DateTime.new(2023, 7, 31, 12) } + + it 'calculcates the date accordingly' do + expect(subject).to eq(Date.new(2023, 10, 3)) + end + end + + context 'start date = 1 in month having 30 days' do + let(:depose_at) { DateTime.new(2023, 6, 30, 12) } + + it 'calculcates the date accordingly' do + expect(subject).to eq(Date.new(2023, 9, 3)) + end + end + end end describe '#decision_date_from_today' do