diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index 41ece6c69..bfd025b35 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -73,6 +73,12 @@ module Validations::HouseholdValidations end end + def validate_referral(record) + if record.tenancy == "Secure (including flexible)" && record.referral == "Internal transfer" + record.errors.add :referral, I18n.t("validations.household.referral.secure_tenancy") + end + end + private def women_of_child_bearing_age_in_household(record) diff --git a/app/models/validations/tenancy_validations.rb b/app/models/validations/tenancy_validations.rb index f45bd0cd9..43b96c8a9 100644 --- a/app/models/validations/tenancy_validations.rb +++ b/app/models/validations/tenancy_validations.rb @@ -25,4 +25,10 @@ module Validations::TenancyValidations def validate_other_tenancy_type(record) validate_other_field(record, :tenancy, :tenancyother) end + + def validate_tenancy(record) + if record.tenancy == "Secure (including flexible)" && record.referral == "Internal transfer" + record.errors.add :tenancy, I18n.t("validations.tenancy.internal_referral") + end + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index a0aad8e60..c69ee8724 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -110,12 +110,15 @@ en: one_or_two_choices: "Only one box must be ticked or 'other disabilities' plus one of mobility disabilities" prevten: non_temp_accommodation: "Answer cannot be non-temporary accommodation as you already told us this is a re-let to tenant who occupied the same property as temporary accommodation" + referral: + secure_tenancy: "Answer must be internal transfer as you already told us this is a secure tenancy" tenancy: length: fixed_term_not_required: "You must only answer the fixed term tenancy length question if the tenancy type is fixed term" shorthold: "Fixed term – Assured Shorthold Tenancy (AST) should be between 2 and 99 years" secure: "Secure (including flexible) should be between 2 and 99 years or not specified" + internal_referral: "Answer must be secure tenancy as you already told us this tenancy is an internal transfer" local_authority: referral: diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index 95edc1313..0c01b3fe7 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -477,4 +477,16 @@ RSpec.describe Validations::HouseholdValidations do expect(record.errors["accessibility_requirements"]).to be_empty end end + + describe "referral validations" do + context "when type of tenancy is secure" do + it "must be internal transfer" do + record.tenancy = "Secure (including flexible)" + record.referral = "Internal transfer" + household_validator.validate_referral(record) + expect(record.errors["referral"]) + .to include(match I18n.t("validations.household.referral.secure_tenancy")) + end + end + end end diff --git a/spec/models/validations/tenancy_validations_spec.rb b/spec/models/validations/tenancy_validations_spec.rb index 4910ce05d..762ac7278 100644 --- a/spec/models/validations/tenancy_validations_spec.rb +++ b/spec/models/validations/tenancy_validations_spec.rb @@ -106,6 +106,16 @@ RSpec.describe Validations::TenancyValidations do expect(record.errors["tenancy"]).to be_empty end end + + context "when referral is internal transfer" do + it "adds an error" do + record.tenancy = "Secure (including flexible)" + record.referral = "Internal transfer" + tenancy_validator.validate_tenancy(record) + expect(record.errors["tenancy"]) + .to include(match I18n.t("validations.tenancy.internal_referral")) + end + end end end end