From 506131a15fd262eefeee33a30034a7f38eba86b8 Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 26 Jan 2022 09:53:50 +0000 Subject: [PATCH] Add validation for referrals and vacancy reasons --- app/models/constants/case_log.rb | 7 +++++++ .../validations/local_authority_validations.rb | 7 +++++++ app/models/validations/property_validations.rb | 14 ++++++++------ config/locales/en.yml | 5 +++++ spec/models/case_log_spec.rb | 18 ++++++++++++++++++ 5 files changed, 45 insertions(+), 6 deletions(-) diff --git a/app/models/constants/case_log.rb b/app/models/constants/case_log.rb index 0b7dc1b63..712aff8d0 100644 --- a/app/models/constants/case_log.rb +++ b/app/models/constants/case_log.rb @@ -1112,6 +1112,13 @@ module Constants::CaseLog "Other" => 16, }.freeze + REFERRAL_INVALID_TMP = ["Re-located through official housing mobility scheme", + "Other social landlord", + "Police, probation or prison", + "Youth offending team", + "Community mental health team", + "Health service"].freeze + NON_TEMP_ACCOMMODATION = ["Tied housing or rented with job", "Supported housing", "Sheltered accomodation", diff --git a/app/models/validations/local_authority_validations.rb b/app/models/validations/local_authority_validations.rb index b4b6d8f1c..b241e158e 100644 --- a/app/models/validations/local_authority_validations.rb +++ b/app/models/validations/local_authority_validations.rb @@ -1,4 +1,5 @@ module Validations::LocalAuthorityValidations + include Constants::CaseLog POSTCODE_REGEXP = Validations::PropertyValidations::POSTCODE_REGEXP def validate_previous_accommodation_postcode(record) @@ -8,4 +9,10 @@ module Validations::LocalAuthorityValidations record.errors.add :previous_postcode, error_message end end + + def validate_referral(record) + if record.rsnvac == "Relet to tenant who occupied same property as temporary accommodation" && REFERRAL_INVALID_TMP.include?(record.referral) + record.errors.add :referral, I18n.t("validations.local_authority.referral.rsnvac_non_temp") + end + end end diff --git a/app/models/validations/property_validations.rb b/app/models/validations/property_validations.rb index b756f7acb..d564a73a9 100644 --- a/app/models/validations/property_validations.rb +++ b/app/models/validations/property_validations.rb @@ -40,6 +40,14 @@ module Validations::PropertyValidations if record.first_time_property_let_as_social_housing? && record.rsnvac.present? && !FIRST_LET_VACANCY_REASONS.include?(record.rsnvac) record.errors.add :rsnvac, I18n.t("validations.property.rsnvac.first_let_social") end + + if record.rsnvac == "Relet to tenant who occupied same property as temporary accommodation" && NON_TEMP_ACCOMMODATION.include?(record.prevten) + record.errors.add :rsnvac, I18n.t("validations.property.rsnvac.non_temp_accommodation") + end + + if record.rsnvac == "Relet to tenant who occupied same property as temporary accommodation" && REFERRAL_INVALID_TMP.include?(record.referral) + record.errors.add :rsnvac, I18n.t("validations.property.rsnvac.referral_invalid") + end end def validate_unitletas(record) @@ -55,10 +63,4 @@ module Validations::PropertyValidations record.errors.add :property_postcode, error_message end end - - def validate_property_vacancy_reason_not_first_let(record) - if record.rsnvac == "Relet to tenant who occupied same property as temporary accommodation" && NON_TEMP_ACCOMMODATION.include?(record.prevten) - record.errors.add :rsnvac, I18n.t("validations.property.rsnvac.non_temp_accommodation") - end - end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 3d40e0d65..1b5e8b1fd 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -56,6 +56,7 @@ en: first_let_social: "Reason for vacancy must be first let if unit has been previously let as social housing" previous_let_social: "Property cannot have a previous let type if it is being let as social housing for the first time" non_temp_accommodation: "Vacancy reason cannot be \"Relet to tenant who occupied same property as temporary accommodation\" if previous tenancy is a non temporary accommodation" + referral_invalid: "Vacancy reason cannot be \"Relet to tenant who occupied same property as temporary accommodation\" if source of referral for letting is ..." financial: tshortfall: @@ -110,6 +111,10 @@ en: 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" + local_authority: + referral: + rsnvac_non_temp: "Source of referral for letting cannot be ... if the vacancy reason is \"Relet to tenant who occupied same property as temporary accommodation\"" + soft_validations: net_income: hint_text: "This is based on the tenant’s work situation: %{ecstat1}" diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index db19667b4..2a0b5e43a 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -918,6 +918,15 @@ RSpec.describe Form, type: :model do }.to raise_error(ActiveRecord::RecordInvalid) end + def check_rsnvac_referral_validation(referral) + expect { + CaseLog.create!(rsnvac: "Relet to tenant who occupied same property as temporary accommodation", + referral: referral, + owning_organisation: owning_organisation, + managing_organisation: managing_organisation) + }.to raise_error(ActiveRecord::RecordInvalid) + end + it "cannot be temp accomodation if previous tenancy was non temp" do check_rsnvac_validation("Tied housing or rented with job") check_rsnvac_validation("Supported housing") @@ -925,6 +934,15 @@ RSpec.describe Form, type: :model do check_rsnvac_validation("Home Office Asylum Support") check_rsnvac_validation("Other") end + + it "cannot be temp accomodation if source of letting referral " do + check_rsnvac_referral_validation("Re-located through official housing mobility scheme") + check_rsnvac_referral_validation("Other social landlord") + check_rsnvac_referral_validation("Police, probation or prison") + check_rsnvac_referral_validation("Youth offending team") + check_rsnvac_referral_validation("Community mental health team") + check_rsnvac_referral_validation("Health service") + end end end