Skip to content

Commit

Permalink
CLDC-3344: Sales CSV download ecstat2 child label bug fix (#2801)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Dinssa authored Dec 9, 2024
1 parent af79b58 commit 474ed4f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
6 changes: 6 additions & 0 deletions app/models/form/sales/questions/buyer2_working_situation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def initialize(id, hsh, page)
@question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max]
end

def displayed_answer_options(_log, _user = nil)
answer_options.reject { |key, _| key == "9" }
end

def answer_options
if form.start_year_2025_or_later?
{
Expand All @@ -26,6 +30,7 @@ def answer_options
"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" },
"0" => { "value" => "Other" },
"10" => { "value" => "Buyer prefers not to say" },
}.freeze
Expand All @@ -41,6 +46,7 @@ def answer_options
"0" => { "value" => "Other" },
"10" => { "value" => "Buyer prefers not to say" },
"7" => { "value" => "Full-time student" },
"9" => { "value" => "Child under 16" },
}.freeze
end
end
Expand Down
28 changes: 26 additions & 2 deletions spec/models/form/sales/questions/buyer2_working_situation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,46 @@
"0" => { "value" => "Other" },
"10" => { "value" => "Buyer prefers not to say" },
"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

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

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

Expand Down

0 comments on commit 474ed4f

Please sign in to comment.