From cd882d322f744088895a12058bfc3850d860da27 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Fri, 18 Feb 2022 14:02:02 +0000 Subject: [PATCH] add homelessness validation (#319) --- .../validations/household_validations.rb | 10 +++++ config/locales/en.yml | 8 ++++ .../validations/household_validations_spec.rb | 40 +++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index 7fadbdf1e..6dff1ac12 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -78,6 +78,16 @@ module Validations::HouseholdValidations record.errors.add :referral, I18n.t("validations.household.referral.secure_tenancy") record.errors.add :tenancy, I18n.t("validations.tenancy.cannot_be_internal_transfer") end + + if record.referral == "Internal transfer" && record.homeless == "Assessed as homeless (or threatened with homelessness within 56 days) by a local authority and owed a homelessness duty" + record.errors.add :referral, I18n.t("validations.household.referral.assessed_homeless") + record.errors.add :homeless, I18n.t("validations.household.homeless.assessed.internal_transfer") + end + + if record.referral == "Internal transfer" && record.homeless == "Other homeless - not found statutorily homeless but considered homeless by landlord" + record.errors.add :referral, I18n.t("validations.household.referral.other_homeless") + record.errors.add :homeless, I18n.t("validations.household.homeless.other.internal_transfer") + end end private diff --git a/config/locales/en.yml b/config/locales/en.yml index 2fe73f04c..b18747985 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -114,6 +114,14 @@ en: secure_tenancy: "Answer must be internal transfer as you already told us this is a secure tenancy" rsnvac_non_temp: "Answer cannot be this source of referral as you already told us this is a re-let to tenant who occupied the same property as temporary accommodation" cannot_be_secure_tenancy: "Answer cannot be secure tenancy as you already told us this is not an internal transfer" + assessed_homeless: "Answer cannot be internal transfer as you already told us the tenant was assessed as homeless" + other_homeless: "Answer cannot be internal transfer as you already told us the tenant was considered homeless by their landlord" + homeless: + assessed: + internal_transfer: "Answer cannot be assessed as homeless as you already told us this tenancy is an internal transfer" + other: + internal_transfer: "Answer cannot be other homelessness as you already told us this tenancy was an internal transfer" + tenancy: length: diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index 1d987bcd7..6d588ff4f 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -495,5 +495,45 @@ RSpec.describe Validations::HouseholdValidations do expect(record.errors["referral"]).to be_empty end end + + context "when homelessness is assessed" do + it "cannot be internal transfer" do + record.homeless = "Assessed as homeless (or threatened with homelessness within 56 days) by a local authority and owed a homelessness duty" + record.referral = "Internal transfer" + household_validator.validate_referral(record) + expect(record.errors["referral"]) + .to include(match I18n.t("validations.household.referral.assessed_homeless")) + expect(record.errors["homeless"]) + .to include(match I18n.t("validations.household.homeless.assessed.internal_transfer")) + end + + it "can be non internal transfer" do + record.homeless = "Assessed as homeless (or threatened with homelessness within 56 days) by a local authority and owed a homelessness duty" + record.referral = "Other social landlord" + household_validator.validate_referral(record) + expect(record.errors["referral"]).to be_empty + expect(record.errors["homeless"]).to be_empty + end + end + + context "when homelessness is other" do + it "cannot be internal transfer" do + record.referral = "Internal transfer" + record.homeless = "Other homeless - not found statutorily homeless but considered homeless by landlord" + household_validator.validate_referral(record) + expect(record.errors["referral"]) + .to include(match I18n.t("validations.household.referral.other_homeless")) + expect(record.errors["homeless"]) + .to include(match I18n.t("validations.household.homeless.other.internal_transfer")) + end + + it "can be non internal transfer" do + record.referral = "Other social landlord" + record.homeless = "Other homeless - not found statutorily homeless but considered homeless by landlord" + household_validator.validate_referral(record) + expect(record.errors["referral"]).to be_empty + expect(record.errors["homeless"]).to be_empty + end + end end end