Browse Source

Cldc 956 household needs subsection incomplete bugfix (#244)

* fix answered questions calculation

checkbox questions were not being counted appropriately so updated the test
for the method along with the method itself

* Fix subsection status method

* change to use question completed method

Co-authored-by: Kat <katrina@madetech.com>
pull/247/head
Dushan 3 years ago committed by GitHub
parent
commit
83378da96c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/models/form/question.rb
  2. 2
      app/models/form/subsection.rb
  3. 2
      spec/fixtures/forms/2021_2022.json
  4. 22
      spec/models/form/subsection_spec.rb

1
app/models/form/question.rb

@ -80,6 +80,7 @@ class Form::Question
def completed?(case_log) def completed?(case_log)
# Special case as No is a valid answer but doesn't let you progress and use the service # Special case as No is a valid answer but doesn't let you progress and use the service
return false if id == "gdpr_acceptance" && case_log[id] == "No" return false if id == "gdpr_acceptance" && case_log[id] == "No"
return answer_options.keys.any? { |key| case_log[key] == "Yes" } if type == "checkbox"
case_log[id].present? || !case_log.respond_to?(id.to_sym) case_log[id].present? || !case_log.respond_to?(id.to_sym)
end end

2
app/models/form/subsection.rb

@ -58,7 +58,7 @@ class Form::Subsection
end end
def answered_questions(case_log) def answered_questions(case_log)
applicable_questions(case_log).select { |question| case_log[question.id].present? } applicable_questions(case_log).select { |question| question.completed?(case_log) }
end end
def unanswered_questions(case_log) def unanswered_questions(case_log)

2
spec/fixtures/forms/2021_2022.json vendored

@ -423,7 +423,7 @@
"dependent_question": { "dependent_question": {
"check_answer_label": "Dependent Question", "check_answer_label": "Dependent Question",
"header": "Question to test page routing", "header": "Question to test page routing",
"type": "checkbox", "type": "radio",
"answer_options": { "answer_options": {
"0": "Option A", "0": "Option A",
"1": "Option B" "1": "Option B"

22
spec/models/form/subsection_spec.rb

@ -35,6 +35,17 @@ RSpec.describe Form::Subsection, type: :model do
expect(subject.status(case_log)).to eq(:in_progress) expect(subject.status(case_log)).to eq(:in_progress)
end end
it "has a completed status for completed subsection" do
subsection_definition = section_definition["subsections"]["household_needs"]
subject = Form::Subsection.new("household_needs", subsection_definition, section)
case_log.armedforces = "No"
case_log.illness = "No"
case_log.housingneeds_a = "Yes"
case_log.la = "York"
case_log.illness_type_1 = "Yes"
expect(subject.status(case_log)).to eq(:completed)
end
it "has status helpers" do it "has status helpers" do
expect(subject.is_incomplete?(case_log)).to be(true) expect(subject.is_incomplete?(case_log)).to be(true)
expect(subject.is_started?(case_log)).to be(true) expect(subject.is_started?(case_log)).to be(true)
@ -47,9 +58,16 @@ RSpec.describe Form::Subsection, type: :model do
end end
it "has question helpers for the number of answered questions" do it "has question helpers for the number of answered questions" do
expected_questions = %w[tenant_code age1] subsection_definition = section_definition["subsections"]["household_needs"]
subject = Form::Subsection.new("household_needs", subsection_definition, section)
expected_questions = %w[armedforces illness accessibility_requirements la condition_effects]
case_log.armedforces = "No"
case_log.illness = "No"
case_log.housingneeds_a = "Yes"
case_log.la = "York"
case_log.illness_type_1 = "Yes"
expect(subject.answered_questions(case_log).map(&:id)).to eq(expected_questions) expect(subject.answered_questions(case_log).map(&:id)).to eq(expected_questions)
expect(subject.answered_questions_count(case_log)).to eq(2) expect(subject.answered_questions_count(case_log)).to eq(5)
end end
it "has a question helpers for the unanswered questions" do it "has a question helpers for the unanswered questions" do

Loading…
Cancel
Save