From fbeaee9368d50e19fd756da1c83db6514b6a7a76 Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Wed, 13 Nov 2024 16:38:05 +0000 Subject: [PATCH] CLDC-3733: Adjust ordering for working situation question (#2762) * CLDC-3733: Adjust ordering for working situation question * Fix tests --- .../questions/buyer1_working_situation.rb | 43 ++++++++---- .../questions/buyer2_working_situation.rb | 43 ++++++++---- .../questions/person_working_situation.rb | 66 +++++++++++++------ .../pages/buyer1_working_situation_spec.rb | 2 +- .../pages/buyer2_working_situation_spec.rb | 2 +- .../pages/person_working_situation_spec.rb | 2 +- .../buyer1_working_situation_spec.rb | 19 +++++- .../buyer2_working_situation_spec.rb | 19 +++++- .../person_working_situation_spec.rb | 19 +++++- 9 files changed, 162 insertions(+), 53 deletions(-) diff --git a/app/models/form/sales/questions/buyer1_working_situation.rb b/app/models/form/sales/questions/buyer1_working_situation.rb index b00db033f..dbbc24eff 100644 --- a/app/models/form/sales/questions/buyer1_working_situation.rb +++ b/app/models/form/sales/questions/buyer1_working_situation.rb @@ -3,7 +3,7 @@ class Form::Sales::Questions::Buyer1WorkingSituation < ::Form::Question super @id = "ecstat1" @type = "radio" - @answer_options = ANSWER_OPTIONS + @answer_options = answer_options @check_answers_card_number = 1 @inferred_check_answers_value = [{ "condition" => { @@ -14,18 +14,35 @@ class Form::Sales::Questions::Buyer1WorkingSituation < ::Form::Question @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] end - ANSWER_OPTIONS = { - "1" => { "value" => "Full-time - 30 hours or more" }, - "2" => { "value" => "Part-time - Less than 30 hours" }, - "3" => { "value" => "In government training into work" }, - "4" => { "value" => "Jobseeker" }, - "6" => { "value" => "Not seeking work" }, - "8" => { "value" => "Unable to work due to long term sick or disability" }, - "5" => { "value" => "Retired" }, - "0" => { "value" => "Other" }, - "10" => { "value" => "Buyer prefers not to say" }, - "7" => { "value" => "Full-time student" }, - }.freeze + def answer_options + if form.start_year_2025_or_later? + { + "1" => { "value" => "Full-time - 30 hours or more" }, + "2" => { "value" => "Part-time - Less than 30 hours" }, + "3" => { "value" => "In government training into work" }, + "4" => { "value" => "Jobseeker" }, + "5" => { "value" => "Retired" }, + "6" => { "value" => "Not seeking work" }, + "7" => { "value" => "Full-time student" }, + "8" => { "value" => "Unable to work due to long term sick or disability" }, + "0" => { "value" => "Other" }, + "10" => { "value" => "Buyer prefers not to say" }, + }.freeze + else + { + "1" => { "value" => "Full-time - 30 hours or more" }, + "2" => { "value" => "Part-time - Less than 30 hours" }, + "3" => { "value" => "In government training into work" }, + "4" => { "value" => "Jobseeker" }, + "6" => { "value" => "Not seeking work" }, + "8" => { "value" => "Unable to work due to long term sick or disability" }, + "5" => { "value" => "Retired" }, + "0" => { "value" => "Other" }, + "10" => { "value" => "Buyer prefers not to say" }, + "7" => { "value" => "Full-time student" }, + }.freeze + end + end QUESTION_NUMBER_FROM_YEAR = { 2023 => 25, 2024 => 27 }.freeze end diff --git a/app/models/form/sales/questions/buyer2_working_situation.rb b/app/models/form/sales/questions/buyer2_working_situation.rb index 5356cb8e8..38ab320b3 100644 --- a/app/models/form/sales/questions/buyer2_working_situation.rb +++ b/app/models/form/sales/questions/buyer2_working_situation.rb @@ -4,7 +4,7 @@ class Form::Sales::Questions::Buyer2WorkingSituation < ::Form::Question @id = "ecstat2" @copy_key = "sales.household_characteristics.ecstat2.buyer" @type = "radio" - @answer_options = ANSWER_OPTIONS + @answer_options = answer_options @check_answers_card_number = 2 @inferred_check_answers_value = [{ "condition" => { @@ -15,18 +15,35 @@ class Form::Sales::Questions::Buyer2WorkingSituation < ::Form::Question @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] end - ANSWER_OPTIONS = { - "1" => { "value" => "Full-time - 30 hours or more" }, - "2" => { "value" => "Part-time - Less than 30 hours" }, - "3" => { "value" => "In government training into work" }, - "4" => { "value" => "Jobseeker" }, - "6" => { "value" => "Not seeking work" }, - "8" => { "value" => "Unable to work due to long term sick or disability" }, - "5" => { "value" => "Retired" }, - "0" => { "value" => "Other" }, - "10" => { "value" => "Buyer prefers not to say" }, - "7" => { "value" => "Full-time student" }, - }.freeze + def answer_options + if form.start_year_2025_or_later? + { + "1" => { "value" => "Full-time - 30 hours or more" }, + "2" => { "value" => "Part-time - Less than 30 hours" }, + "3" => { "value" => "In government training into work" }, + "4" => { "value" => "Jobseeker" }, + "5" => { "value" => "Retired" }, + "6" => { "value" => "Not seeking work" }, + "7" => { "value" => "Full-time student" }, + "8" => { "value" => "Unable to work due to long term sick or disability" }, + "0" => { "value" => "Other" }, + "10" => { "value" => "Buyer prefers not to say" }, + }.freeze + else + { + "1" => { "value" => "Full-time - 30 hours or more" }, + "2" => { "value" => "Part-time - Less than 30 hours" }, + "3" => { "value" => "In government training into work" }, + "4" => { "value" => "Jobseeker" }, + "6" => { "value" => "Not seeking work" }, + "8" => { "value" => "Unable to work due to long term sick or disability" }, + "5" => { "value" => "Retired" }, + "0" => { "value" => "Other" }, + "10" => { "value" => "Buyer prefers not to say" }, + "7" => { "value" => "Full-time student" }, + }.freeze + end + end QUESTION_NUMBER_FROM_YEAR = { 2023 => 33, 2024 => 35 }.freeze end diff --git a/app/models/form/sales/questions/person_working_situation.rb b/app/models/form/sales/questions/person_working_situation.rb index 488a77092..f3fbebd6f 100644 --- a/app/models/form/sales/questions/person_working_situation.rb +++ b/app/models/form/sales/questions/person_working_situation.rb @@ -16,27 +16,51 @@ class Form::Sales::Questions::PersonWorkingSituation < ::Form::Question end def answer_options - { - "1" => { "value" => "Full-time - 30 hours or more" }, - "2" => { "value" => "Part-time - Less than 30 hours" }, - "3" => { "value" => "In government training into work" }, - "4" => { "value" => "Jobseeker" }, - "6" => { "value" => "Not seeking work" }, - "8" => { "value" => "Unable to work due to long term sick or disability" }, - "5" => { "value" => "Retired" }, - "0" => { "value" => "Other" }, - "10" => { "value" => "Person prefers not to say" }, - "7" => { "value" => "Full-time student" }, - "9" => { - "value" => "Child under 16", - "depends_on" => [ - { "saledate" => { "operator" => "<", "operand" => Time.zone.local(2024, 4, 1) } }, - { "age#{@person_index}_known" => 1 }, - { "age#{@person_index}_known" => nil }, - { "age#{@person_index}" => { "operator" => "<", "operand" => 16 } }, - ], - }, - } + if form.start_year_2025_or_later? + { + "1" => { "value" => "Full-time - 30 hours or more" }, + "2" => { "value" => "Part-time - Less than 30 hours" }, + "3" => { "value" => "In government training into work" }, + "4" => { "value" => "Jobseeker" }, + "5" => { "value" => "Retired" }, + "6" => { "value" => "Not seeking work" }, + "7" => { "value" => "Full-time student" }, + "8" => { "value" => "Unable to work due to long term sick or disability" }, + "9" => { + "value" => "Child under 16", + "depends_on" => [ + { "saledate" => { "operator" => "<", "operand" => Time.zone.local(2024, 4, 1) } }, + { "age#{@person_index}_known" => 1 }, + { "age#{@person_index}_known" => nil }, + { "age#{@person_index}" => { "operator" => "<", "operand" => 16 } }, + ], + }, + "0" => { "value" => "Other" }, + "10" => { "value" => "Person prefers not to say" }, + } + else + { + "1" => { "value" => "Full-time - 30 hours or more" }, + "2" => { "value" => "Part-time - Less than 30 hours" }, + "3" => { "value" => "In government training into work" }, + "4" => { "value" => "Jobseeker" }, + "6" => { "value" => "Not seeking work" }, + "8" => { "value" => "Unable to work due to long term sick or disability" }, + "5" => { "value" => "Retired" }, + "0" => { "value" => "Other" }, + "10" => { "value" => "Person prefers not to say" }, + "7" => { "value" => "Full-time student" }, + "9" => { + "value" => "Child under 16", + "depends_on" => [ + { "saledate" => { "operator" => "<", "operand" => Time.zone.local(2024, 4, 1) } }, + { "age#{@person_index}_known" => 1 }, + { "age#{@person_index}_known" => nil }, + { "age#{@person_index}" => { "operator" => "<", "operand" => 16 } }, + ], + }, + } + end end def question_number diff --git a/spec/models/form/sales/pages/buyer1_working_situation_spec.rb b/spec/models/form/sales/pages/buyer1_working_situation_spec.rb index fb8529967..182da0a82 100644 --- a/spec/models/form/sales/pages/buyer1_working_situation_spec.rb +++ b/spec/models/form/sales/pages/buyer1_working_situation_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Form::Sales::Pages::Buyer1WorkingSituation, type: :model do let(:page_id) { nil } let(:page_definition) { nil } - let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2024_or_later?: false)) } + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2024_or_later?: true, start_year_2025_or_later?: false)) } it "has correct subsection" do expect(page.subsection).to eq(subsection) diff --git a/spec/models/form/sales/pages/buyer2_working_situation_spec.rb b/spec/models/form/sales/pages/buyer2_working_situation_spec.rb index 0b7708303..6c9915903 100644 --- a/spec/models/form/sales/pages/buyer2_working_situation_spec.rb +++ b/spec/models/form/sales/pages/buyer2_working_situation_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Form::Sales::Pages::Buyer2WorkingSituation, type: :model do let(:page_id) { nil } let(:page_definition) { nil } - let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1))) } + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2025_or_later?: false)) } it "has correct subsection" do expect(page.subsection).to eq(subsection) diff --git a/spec/models/form/sales/pages/person_working_situation_spec.rb b/spec/models/form/sales/pages/person_working_situation_spec.rb index 53c127e16..91d23f34f 100644 --- a/spec/models/form/sales/pages/person_working_situation_spec.rb +++ b/spec/models/form/sales/pages/person_working_situation_spec.rb @@ -4,7 +4,7 @@ RSpec.describe Form::Sales::Pages::PersonWorkingSituation, type: :model do subject(:page) { described_class.new(page_id, page_definition, subsection, person_index:) } let(:page_definition) { nil } - let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1))) } + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2025_or_later?: false)) } let(:person_index) { 2 } let(:page_id) { "person_2_working_situation" } diff --git a/spec/models/form/sales/questions/buyer1_working_situation_spec.rb b/spec/models/form/sales/questions/buyer1_working_situation_spec.rb index e25eb2aaf..0e1b02257 100644 --- a/spec/models/form/sales/questions/buyer1_working_situation_spec.rb +++ b/spec/models/form/sales/questions/buyer1_working_situation_spec.rb @@ -5,7 +5,8 @@ RSpec.describe Form::Sales::Questions::Buyer1WorkingSituation, type: :model do let(:question_id) { nil } let(:question_definition) { nil } - let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2024_or_later?: false))) } + let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2025_or_later?: false) } + let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form:)) } it "has correct page" do expect(question.page).to eq(page) @@ -38,6 +39,22 @@ RSpec.describe Form::Sales::Questions::Buyer1WorkingSituation, type: :model do }) end + context "with start year before 2025" do + let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2025_or_later?: false) } + + it "uses the old ordering for answer options" do + expect(question.answer_options.keys).to eq(%w[1 2 3 4 6 8 5 0 10 7]) + end + end + + context "with start year from 2025" do + let(:form) { instance_double(Form, start_date: Time.zone.local(2025, 4, 1), start_year_2025_or_later?: true) } + + it "uses the new ordering for answer options" do + expect(question.answer_options.keys).to eq(%w[1 2 3 4 5 6 7 8 0 10]) + end + end + it "has the correct check_answers_card_number" do expect(question.check_answers_card_number).to eq(1) end diff --git a/spec/models/form/sales/questions/buyer2_working_situation_spec.rb b/spec/models/form/sales/questions/buyer2_working_situation_spec.rb index 81d1e052f..7b825185c 100644 --- a/spec/models/form/sales/questions/buyer2_working_situation_spec.rb +++ b/spec/models/form/sales/questions/buyer2_working_situation_spec.rb @@ -5,7 +5,8 @@ RSpec.describe Form::Sales::Questions::Buyer2WorkingSituation, type: :model do let(:question_id) { nil } let(:question_definition) { nil } - let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))) } + let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2025_or_later?: false) } + let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form:)) } it "has correct page" do expect(question.page).to eq(page) @@ -38,6 +39,22 @@ RSpec.describe Form::Sales::Questions::Buyer2WorkingSituation, type: :model do }) end + context "with start year before 2025" do + let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2025_or_later?: false) } + + it "uses the old ordering for answer options" do + expect(question.answer_options.keys).to eq(%w[1 2 3 4 6 8 5 0 10 7]) + end + end + + context "with start year from 2025" do + let(:form) { instance_double(Form, start_date: Time.zone.local(2025, 4, 1), start_year_2025_or_later?: true) } + + it "uses the new ordering for answer options" do + expect(question.answer_options.keys).to eq(%w[1 2 3 4 5 6 7 8 0 10]) + end + end + it "has the correct check_answers_card_number" do expect(question.check_answers_card_number).to eq(2) end diff --git a/spec/models/form/sales/questions/person_working_situation_spec.rb b/spec/models/form/sales/questions/person_working_situation_spec.rb index a9f5316cd..b09c0bf69 100644 --- a/spec/models/form/sales/questions/person_working_situation_spec.rb +++ b/spec/models/form/sales/questions/person_working_situation_spec.rb @@ -5,7 +5,8 @@ RSpec.describe Form::Sales::Questions::PersonWorkingSituation, type: :model do let(:question_id) { "ecstat2" } let(:question_definition) { nil } - let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))) } + let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2025_or_later?: false) } + let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form:)) } let(:person_index) { 2 } it "has correct page" do @@ -41,6 +42,22 @@ RSpec.describe Form::Sales::Questions::PersonWorkingSituation, type: :model do }) end + context "with start year before 2025" do + let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2025_or_later?: false) } + + it "uses the old ordering for answer options" do + expect(question.answer_options.keys).to eq(%w[1 2 3 4 6 8 5 0 10 7 9]) + end + end + + context "with start year from 2025" do + let(:form) { instance_double(Form, start_date: Time.zone.local(2025, 4, 1), start_year_2025_or_later?: true) } + + it "uses the new ordering for answer options" do + expect(question.answer_options.keys).to eq(%w[1 2 3 4 5 6 7 8 9 0 10]) + end + end + context "when person 2" do let(:question_id) { "ecstat2" } let(:person_index) { 2 }