Browse Source

CLDC-3344: Sales CSV download ecstat2 child label bug fix (#2801)

* Add missing answer option

* Update tests

* Allow user to change the age of a person if they're not actually under 16 without being blocked

* Update displayed answer options

* Add tests

* Fix lint

* Clear only when age is not known

* Lint

* Use existing method

* Update tests

* Revert changes in derived variables

* Update sales_log_spec.rb
pull/2857/head
Manny Dinssa 2 months ago committed by GitHub
parent
commit
474ed4f348
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      app/models/form/sales/questions/buyer2_working_situation.rb
  2. 28
      spec/models/form/sales/questions/buyer2_working_situation_spec.rb

6
app/models/form/sales/questions/buyer2_working_situation.rb

@ -15,6 +15,10 @@ 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] @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max]
end end
def displayed_answer_options(_log, _user = nil)
answer_options.reject { |key, _| key == "9" }
end
def answer_options def answer_options
if form.start_year_2025_or_later? if form.start_year_2025_or_later?
{ {
@ -26,6 +30,7 @@ class Form::Sales::Questions::Buyer2WorkingSituation < ::Form::Question
"6" => { "value" => "Not seeking work" }, "6" => { "value" => "Not seeking work" },
"7" => { "value" => "Full-time student" }, "7" => { "value" => "Full-time student" },
"8" => { "value" => "Unable to work due to long term sick or disability" }, "8" => { "value" => "Unable to work due to long term sick or disability" },
"9" => { "value" => "Child under 16" },
"0" => { "value" => "Other" }, "0" => { "value" => "Other" },
"10" => { "value" => "Buyer prefers not to say" }, "10" => { "value" => "Buyer prefers not to say" },
}.freeze }.freeze
@ -41,6 +46,7 @@ class Form::Sales::Questions::Buyer2WorkingSituation < ::Form::Question
"0" => { "value" => "Other" }, "0" => { "value" => "Other" },
"10" => { "value" => "Buyer prefers not to say" }, "10" => { "value" => "Buyer prefers not to say" },
"7" => { "value" => "Full-time student" }, "7" => { "value" => "Full-time student" },
"9" => { "value" => "Child under 16" },
}.freeze }.freeze
end end
end end

28
spec/models/form/sales/questions/buyer2_working_situation_spec.rb

@ -36,6 +36,22 @@ RSpec.describe Form::Sales::Questions::Buyer2WorkingSituation, type: :model do
"0" => { "value" => "Other" }, "0" => { "value" => "Other" },
"10" => { "value" => "Buyer prefers not to say" }, "10" => { "value" => "Buyer prefers not to say" },
"7" => { "value" => "Full-time student" }, "7" => { "value" => "Full-time student" },
"9" => { "value" => "Child under 16" },
})
end
it "has the correct displayed_answer_options" do
expect(question.displayed_answer_options(nil)).to eq({
"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" },
}) })
end end
@ -43,7 +59,11 @@ RSpec.describe Form::Sales::Questions::Buyer2WorkingSituation, type: :model do
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2025_or_later?: false) } 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 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]) expect(question.answer_options.keys).to eq(%w[1 2 3 4 6 8 5 0 10 7 9])
end
it "uses the old ordering for displayed answer options" do
expect(question.displayed_answer_options(nil).keys).to eq(%w[1 2 3 4 6 8 5 0 10 7])
end end
end end
@ -51,7 +71,11 @@ RSpec.describe Form::Sales::Questions::Buyer2WorkingSituation, type: :model do
let(:form) { instance_double(Form, start_date: Time.zone.local(2025, 4, 1), start_year_2025_or_later?: true) } 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 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]) expect(question.answer_options.keys).to eq(%w[1 2 3 4 5 6 7 8 9 0 10])
end
it "uses the new ordering for displayed answer options" do
expect(question.displayed_answer_options(nil).keys).to eq(%w[1 2 3 4 5 6 7 8 0 10])
end end
end end

Loading…
Cancel
Save