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(