Browse Source

CLDC-3733: Adjust ordering for working situation question (#2762)

* CLDC-3733: Adjust ordering for working situation question

* Fix tests
pull/2746/head^2
Rachael Booth 1 month ago committed by GitHub
parent
commit
fbeaee9368
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 43
      app/models/form/sales/questions/buyer1_working_situation.rb
  2. 43
      app/models/form/sales/questions/buyer2_working_situation.rb
  3. 66
      app/models/form/sales/questions/person_working_situation.rb
  4. 2
      spec/models/form/sales/pages/buyer1_working_situation_spec.rb
  5. 2
      spec/models/form/sales/pages/buyer2_working_situation_spec.rb
  6. 2
      spec/models/form/sales/pages/person_working_situation_spec.rb
  7. 19
      spec/models/form/sales/questions/buyer1_working_situation_spec.rb
  8. 19
      spec/models/form/sales/questions/buyer2_working_situation_spec.rb
  9. 19
      spec/models/form/sales/questions/person_working_situation_spec.rb

43
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

43
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

66
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

2
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)

2
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)

2
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" }

19
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

19
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

19
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 }

Loading…
Cancel
Save