From 219bf937ccdbb39d28c3b66b262c0bfa6492ef9a Mon Sep 17 00:00:00 2001 From: SamSeed-Softwire <63662292+SamSeed-Softwire@users.noreply.github.com> Date: Thu, 10 Nov 2022 14:44:29 +0000 Subject: [PATCH] CLDC-1694 Fix issue with non-renewal lettings allowing 'renewal' for vacancy reason (#982) * feat: add renewal validation on rsnvac * test: check sensible error seen when rsnvac is renewal and but letting is not a renewal * test: change renewal validation check to fetch error message dynamically * feat: lint code * feat: write record.renewal.present?, not record.renewal Co-authored-by: James Rose Co-authored-by: James Rose --- app/models/validations/property_validations.rb | 4 ++++ config/locales/en.yml | 1 + spec/models/validations/property_validations_spec.rb | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/app/models/validations/property_validations.rb b/app/models/validations/property_validations.rb index d5ab8e9e0..c655d8c85 100644 --- a/app/models/validations/property_validations.rb +++ b/app/models/validations/property_validations.rb @@ -38,6 +38,10 @@ module Validations::PropertyValidations record.errors.add :rsnvac, I18n.t("validations.property.rsnvac.referral_invalid") record.errors.add :referral, I18n.t("validations.household.referral.rsnvac_non_temp") end + + if record.renewal.present? && record.renewal.zero? && record.rsnvac == 14 + record.errors.add :rsnvac, I18n.t("validations.property.rsnvac.not_a_renewal") + end end def validate_unitletas(record) diff --git a/config/locales/en.yml b/config/locales/en.yml index 55ea3a0f7..9a45d96dd 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -141,6 +141,7 @@ en: previous_let_social: "Property cannot have a previous let type if being let as social housing for the first time" non_temp_accommodation: "Answer cannot be re-let to tenant who occupied the same property as temporary accommodation as this accommodation is not temporary" referral_invalid: "Answer cannot be re-let to tenant who occupied the same property as temporary accommodation as a different source of referral for this letting" + not_a_renewal: "Reason for vacancy cannot be 'Renewal of fixed-term tenancy' if letting is not a renewal" unittype_gn: one_bedroom_bedsit: "A bedsit can only have one bedroom" one_seven_bedroom_shared: "A shared house must have 1 to 7 bedrooms" diff --git a/spec/models/validations/property_validations_spec.rb b/spec/models/validations/property_validations_spec.rb index 153934ebc..b3965b3d6 100644 --- a/spec/models/validations/property_validations_spec.rb +++ b/spec/models/validations/property_validations_spec.rb @@ -233,6 +233,17 @@ RSpec.describe Validations::PropertyValidations do property_validator.validate_rsnvac(record) expect(record.errors["rsnvac"]).to be_empty end + + context "when the letting is not a renewal" do + it "validates that the reason for vacancy is not renewal" do + record.first_time_property_let_as_social_housing = 0 + record.renewal = 0 + record.rsnvac = 14 + property_validator.validate_rsnvac(record) + expect(record.errors["rsnvac"]) + .to include(match I18n.t("validations.property.rsnvac.not_a_renewal")) + end + end end context "when the property has been let before" do