From 36763369b77393bbff90f308473347584b3f37e1 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Thu, 18 Jan 2024 13:45:38 +0000 Subject: [PATCH] Stop calculating work history after award/decline When an application is awarded or declined, and the work history is marked as ongoing, we stop counting the number of months when the application is awarded or declined to ensure the number doesn't keep increasing. --- app/lib/work_history_duration.rb | 3 ++- spec/lib/work_history_duration_spec.rb | 34 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/app/lib/work_history_duration.rb b/app/lib/work_history_duration.rb index 32ce0d004b..da17f286a4 100644 --- a/app/lib/work_history_duration.rb +++ b/app/lib/work_history_duration.rb @@ -102,7 +102,8 @@ def work_history_start_date(work_history) end def work_history_end_date(work_history) - work_history.end_date || Time.zone.today + work_history.end_date || application_form.awarded_at || + application_form.declined_at || Time.zone.today end def date_first_of_month(date) diff --git a/spec/lib/work_history_duration_spec.rb b/spec/lib/work_history_duration_spec.rb index ea136b6430..1766ea863d 100644 --- a/spec/lib/work_history_duration_spec.rb +++ b/spec/lib/work_history_duration_spec.rb @@ -76,6 +76,40 @@ it { is_expected.to eq(7) } end + context "with an ongoing full time work history and an awarded application form" do + let(:application_form) do + create(:application_form, awarded_at: Date.new(2020, 12, 1)) + end + + before do + create( + :work_history, + application_form:, + start_date: Date.new(2020, 1, 1), + hours_per_week: 30, + ) + end + + it { is_expected.to eq(6) } + end + + context "with an ongoing full time work history and a declined application form" do + let(:application_form) do + create(:application_form, declined_at: Date.new(2020, 12, 1)) + end + + before do + create( + :work_history, + application_form:, + start_date: Date.new(2020, 1, 1), + hours_per_week: 30, + ) + end + + it { is_expected.to eq(6) } + end + context "with an ongoing part time work history" do before do create(