Browse Source

Add disability and wheelchair questions validation (#1215)

* Add Page#interruption_screen? method

* Use form helper method

* Validate household disability questions

* Update CYA
pull/1213/head
Jack 2 years ago committed by GitHub
parent
commit
cf92c9559c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      app/controllers/form_controller.rb
  2. 4
      app/models/form/page.rb
  3. 1
      app/models/form/sales/questions/household_wheelchair_check.rb
  4. 1
      app/models/form/sales/subsections/household_needs.rb
  5. 4
      app/models/validations/sales/soft_validations.rb
  6. 2
      spec/fixtures/forms/2021_2022.json
  7. 16
      spec/models/form/page_spec.rb
  8. 1
      spec/models/form/sales/subsections/household_needs_spec.rb
  9. 4
      spec/models/form_handler_spec.rb
  10. 45
      spec/models/validations/sales/soft_validations_spec.rb

30
app/controllers/form_controller.rb

@ -6,7 +6,7 @@ class FormController < ApplicationController
def submit_form
if @log
@page = @log.form.get_page(params[@log.model_name.param_key][:page])
@page = form.get_page(params[@log.model_name.param_key][:page])
responses_for_page = responses_for_page(@page)
mandatory_questions_with_no_response = mandatory_questions_with_no_response(responses_for_page)
@ -30,7 +30,7 @@ class FormController < ApplicationController
def check_answers
if @log
current_url = request.env["PATH_INFO"]
subsection = @log.form.get_subsection(current_url.split("/")[-2])
subsection = form.get_subsection(current_url.split("/")[-2])
render "form/check_answers", locals: { subsection:, current_user: }
else
render_not_found
@ -49,8 +49,8 @@ class FormController < ApplicationController
if @log
restore_error_field_values
page_id = request.path.split("/")[-1].underscore
@page = @log.form.get_page(page_id)
@subsection = @log.form.subsection_for_page(@page)
@page = form.get_page(page_id)
@subsection = form.subsection_for_page(@page)
if @page.routed_to?(@log, current_user)
render "form/page"
else
@ -71,7 +71,7 @@ private
end
if session["fields"]
session["fields"].each do |field, value|
if @log.form.get_question(field, @log)&.type != "date" && @log.respond_to?(field)
if form.get_question(field, @log)&.type != "date" && @log.respond_to?(field)
@log[field] = value
end
end
@ -129,20 +129,26 @@ private
def successful_redirect_path
if is_referrer_check_answers?
page_ids = @log.form.subsection_for_page(@page).pages.map(&:id)
page_ids = form.subsection_for_page(@page).pages.map(&:id)
page_index = page_ids.index(@page.id)
next_page = @log.form.next_page(@page, @log, current_user)
previous_page = @log.form.previous_page(page_ids, page_index, @log, current_user)
if next_page.to_s.include?("value_check") || next_page == previous_page
return send("#{@log.class.name.underscore}_#{next_page}_path", @log, { referrer: "check_answers" })
next_page_id = form.next_page(@page, @log, current_user)
next_page = form.get_page(next_page_id)
previous_page = form.previous_page(page_ids, page_index, @log, current_user)
if next_page&.interruption_screen? || next_page_id == previous_page
return send("#{@log.class.name.underscore}_#{next_page_id}_path", @log, { referrer: "check_answers" })
else
return send("#{@log.model_name.param_key}_#{@log.form.subsection_for_page(@page).id}_check_answers_path", @log)
return send("#{@log.model_name.param_key}_#{form.subsection_for_page(@page).id}_check_answers_path", @log)
end
end
redirect_path = @log.form.next_page_redirect_path(@page, @log, current_user)
redirect_path = form.next_page_redirect_path(@page, @log, current_user)
send(redirect_path, @log)
end
def form
@log&.form
end
def mandatory_questions_with_no_response(responses_for_page)
session["fields"] = {}
calc_questions = @page.questions.map(&:result_field)

4
app/models/form/page.rb

@ -32,6 +32,10 @@ class Form::Page
end
end
def interruption_screen?
questions.all? { |question| question.type == "interruption_screen" }
end
private
def conditional_question_ids

1
app/models/form/sales/questions/household_wheelchair_check.rb

@ -19,5 +19,6 @@ class Form::Sales::Questions::HouseholdWheelchairCheck < ::Form::Question
},
],
}
@page = page
end
end

1
app/models/form/sales/subsections/household_needs.rb

@ -12,6 +12,7 @@ class Form::Sales::Subsections::HouseholdNeeds < ::Form::Subsection
Form::Sales::Pages::BuyerStillServing.new(nil, nil, self),
Form::Sales::Pages::ArmedForcesSpouse.new(nil, nil, self),
Form::Sales::Pages::HouseholdDisability.new(nil, nil, self),
Form::Sales::Pages::HouseholdWheelchairCheck.new("disability_wheelchair_check", nil, self),
Form::Sales::Pages::HouseholdWheelchair.new(nil, nil, self),
Form::Sales::Pages::HouseholdWheelchairCheck.new("wheelchair_check", nil, self),
]

4
app/models/validations/sales/soft_validations.rb

@ -22,9 +22,9 @@ module Validations::Sales::SoftValidations
end
def wheelchair_when_not_disabled?
return false unless disabled == 2
return unless disabled && wheel
wheel == 1
wheel == 1 && disabled == 2
end
def savings_over_soft_max?

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

@ -208,7 +208,7 @@
"check_answer_label": "Retirement age soft validation",
"hidden_in_check_answers": true,
"header": "Are you sure this person is retired?",
"type": "radio",
"type": "interruption_screen",
"answer_options": {
"0": {
"value": "Yes"

16
spec/models/form/page_spec.rb

@ -47,6 +47,22 @@ RSpec.describe Form::Page, type: :model do
end
end
describe "#interruption_screen?" do
context "when it has regular questions" do
it "returns false" do
expect(page.interruption_screen?).to be false
end
end
context "when it has interruption_screen question" do
let(:page) { form.get_page("retirement_value_check") }
it "returns true" do
expect(page.interruption_screen?).to be true
end
end
end
context "with a lettings log" do
let(:lettings_log) { FactoryBot.build(:lettings_log, :in_progress) }

1
spec/models/form/sales/subsections/household_needs_spec.rb

@ -18,6 +18,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdNeeds, type: :model do
buyer_still_serving
armed_forces_spouse
household_disability
disability_wheelchair_check
household_wheelchair
wheelchair_check
],

4
spec/models/form_handler_spec.rb

@ -52,14 +52,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do
form = form_handler.get_form("current_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(182)
expect(form.pages.count).to eq(183)
expect(form.name).to eq("2022_2023_sales")
end
it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(182)
expect(form.pages.count).to eq(183)
expect(form.name).to eq("2021_2022_sales")
end
end

45
spec/models/validations/sales/soft_validations_spec.rb

@ -7,14 +7,14 @@ RSpec.describe Validations::Sales::SoftValidations do
context "when validating soft min" do
it "returns false if no income1 is given" do
record.income1 = nil
expect(record)
.not_to be_income1_under_soft_min
expect(record).not_to be_income1_under_soft_min
end
it "returns false if no ecstat1 is given" do
record.ecstat1 = nil
expect(record)
.not_to be_income1_under_soft_min
expect(record).not_to be_income1_under_soft_min
end
[
@ -292,4 +292,41 @@ RSpec.describe Validations::Sales::SoftValidations do
expect(record).not_to be_hodate_3_years_or_more_saledate
end
end
describe "wheelchair_when_not_disabled" do
it "when hodate not set" do
record.disabled = 2
record.wheel = nil
expect(record).not_to be_wheelchair_when_not_disabled
end
it "when disabled not set" do
record.disabled = nil
record.wheel = 1
expect(record).not_to be_wheelchair_when_not_disabled
end
it "when disabled and wheel not set" do
record.disabled = nil
record.wheel = nil
expect(record).not_to be_wheelchair_when_not_disabled
end
it "when disabled == 2 && wheel == 1" do
record.disabled = 2
record.wheel = 1
expect(record).to be_wheelchair_when_not_disabled
end
it "when disabled == 2 && wheel != 1" do
record.disabled = 2
record.wheel = 2
expect(record).not_to be_wheelchair_when_not_disabled
end
end
end

Loading…
Cancel
Save