diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index a593b105b..830bc3549 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -65,6 +65,13 @@ module Validations::HouseholdValidations end end + def validate_condition_effects(record) + all_options = [record.illness_type_1, record.illness_type_2, record.illness_type_3, record.illness_type_4, record.illness_type_5, record.illness_type_6, record.illness_type_7, record.illness_type_8, record.illness_type_9, record.illness_type_10] + if all_options.count(1) >= 1 && household_no_illness?(record) + record.errors.add :condition_effects, I18n.t("validations.household.condition_effects.no_choices") + end + end + def validate_previous_housing_situation(record) if record.is_relet_to_temp_tenant? && !record.previous_tenancy_was_temporary? record.errors.add :prevten, I18n.t("validations.household.prevten.non_temp_accommodation") @@ -107,6 +114,10 @@ module Validations::HouseholdValidations private + def household_no_illness?(record) + record.illness != 0 + end + def women_of_child_bearing_age_in_household(record) (1..8).any? do |n| next if record["sex#{n}"].nil? || record["age#{n}"].nil? diff --git a/config/locales/en.yml b/config/locales/en.yml index 154845233..9f5d8056f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -146,6 +146,8 @@ en: male_refuge: "Answer cannot be male as you told us their housing situation immediately before this letting was a refuge" reason: not_internal_transfer: "Answer cannot be permanently decanted from another property owned by this landlord as you told us the source of referral for this tenancy was not an internal transfer" + condition_effects: + no_choices: "You can not provide details about effects of conditions on any of the household members if you have not answered yes to the any of the household having a physical or mental health condition (or other illness) expected to last 12 months or more" tenancy: length: diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index 1c2d41850..67e6d4b32 100644 --- a/spec/factories/case_log.rb +++ b/spec/factories/case_log.rb @@ -51,7 +51,7 @@ FactoryBot.define do underoccupation_benefitcap { 0 } leftreg { 1 } reservist { 0 } - illness { 1 } + illness { 0 } preg_occ { 1 } tenancy_code { "BZ757" } startertenancy { 0 } diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index 6f3bf98e9..8b06563f4 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -44,7 +44,7 @@ "underoccupation_benefitcap": 0, "leftreg": 1, "reservist": 0, - "illness": 1, + "illness": 0, "preg_occ": 0, "tenancy_code": "BZ757", "startdate": "12/12/2021", diff --git a/spec/fixtures/exports/case_logs.xml b/spec/fixtures/exports/case_logs.xml index 478f3d90f..7a1b17dbd 100644 --- a/spec/fixtures/exports/case_logs.xml +++ b/spec/fixtures/exports/case_logs.xml @@ -38,7 +38,7 @@ 0 1 0 - 1 + 0 1 BZ757 0 diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index b8a2dba23..5d9611620 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -482,6 +482,97 @@ RSpec.describe Validations::HouseholdValidations do end end + describe "condition effects validation" do + it "validates vision can't be selected if answer to anyone in household with health condition is not yes" do + record.illness = 1 + record.illness_type_1 = 1 + household_validator.validate_condition_effects(record) + expect(record.errors["condition_effects"]) + .to include(match I18n.t("validations.household.condition_effects.no_choices")) + end + + it "validates hearing can't be selected if answer to anyone in household with health condition is not yes" do + record.illness = 1 + record.illness_type_2 = 1 + household_validator.validate_condition_effects(record) + expect(record.errors["condition_effects"]) + .to include(match I18n.t("validations.household.condition_effects.no_choices")) + end + + it "validates mobility can't be selected if answer to anyone in household with health condition is not yes" do + record.illness = 1 + record.illness_type_3 = 1 + household_validator.validate_condition_effects(record) + expect(record.errors["condition_effects"]) + .to include(match I18n.t("validations.household.condition_effects.no_choices")) + end + + it "validates dexterity can't be selected if answer to anyone in household with health condition is not yes" do + record.illness = 1 + record.illness_type_4 = 1 + household_validator.validate_condition_effects(record) + expect(record.errors["condition_effects"]) + .to include(match I18n.t("validations.household.condition_effects.no_choices")) + end + + it "validates learning or understanding or concentrating can't be selected if answer to anyone in household with health condition is not yes" do + record.illness = 1 + record.illness_type_5 = 1 + household_validator.validate_condition_effects(record) + expect(record.errors["condition_effects"]) + .to include(match I18n.t("validations.household.condition_effects.no_choices")) + end + + it "validates memory can't be selected if answer to anyone in household with health condition is not yes" do + record.illness = 1 + record.illness_type_6 = 1 + household_validator.validate_condition_effects(record) + expect(record.errors["condition_effects"]) + .to include(match I18n.t("validations.household.condition_effects.no_choices")) + end + + it "validates mental health can't be selected if answer to anyone in household with health condition is not yes" do + record.illness = 1 + record.illness_type_7 = 1 + household_validator.validate_condition_effects(record) + expect(record.errors["condition_effects"]) + .to include(match I18n.t("validations.household.condition_effects.no_choices")) + end + + it "validates stamina or breathing or fatigue can't be selected if answer to anyone in household with health condition is not yes" do + record.illness = 1 + record.illness_type_8 = 1 + household_validator.validate_condition_effects(record) + expect(record.errors["condition_effects"]) + .to include(match I18n.t("validations.household.condition_effects.no_choices")) + end + + it "validates socially or behaviourally can't be selected if answer to anyone in household with health condition is not yes" do + record.illness = 1 + record.illness_type_9 = 1 + household_validator.validate_condition_effects(record) + expect(record.errors["condition_effects"]) + .to include(match I18n.t("validations.household.condition_effects.no_choices")) + end + + it "validates other can't be selected if answer to anyone in household with health condition is not yes" do + record.illness = 1 + record.illness_type_10 = 1 + household_validator.validate_condition_effects(record) + expect(record.errors["condition_effects"]) + .to include(match I18n.t("validations.household.condition_effects.no_choices")) + end + + it "expects that an illness can be selected if answer to anyone in household with health condition is yes " do + record.illness = 0 + record.illness_type_1 = 1 + record.illness_type_2 = 1 + record.illness_type_3 = 1 + household_validator.validate_condition_effects(record) + expect(record.errors["condition_effects"]).to be_empty + end + end + describe "accessibility requirement validations" do it "validates that mutually exclusive options can't be selected together" do record.housingneeds_a = 1