From 659d647c7a64470abc7f497034a2cdae364b8a5d Mon Sep 17 00:00:00 2001 From: Kat <54268893+kosiakkatrina@users.noreply.github.com> Date: Wed, 30 Oct 2024 13:48:55 +0000 Subject: [PATCH] Extract lettings property validations copy --- .../validations/property_validations.rb | 30 ++++++------- config/locales/en.yml | 14 ------- .../lettings/property_information.en.yml | 23 +++++++++- .../validations/property_validations_spec.rb | 42 +++++++++---------- 4 files changed, 58 insertions(+), 51 deletions(-) diff --git a/app/models/validations/property_validations.rb b/app/models/validations/property_validations.rb index 1864adc5c..76a8b8a66 100644 --- a/app/models/validations/property_validations.rb +++ b/app/models/validations/property_validations.rb @@ -5,30 +5,30 @@ module Validations::PropertyValidations REFERRAL_INVALID_TMP = [8, 10, 12, 13, 14, 15].freeze def validate_rsnvac(record) if !record.first_time_property_let_as_social_housing? && record.has_first_let_vacancy_reason? - record.errors.add :rsnvac, I18n.t("validations.property.rsnvac.first_let_not_social") + record.errors.add :rsnvac, I18n.t("validations.lettings.property.rsnvac.first_let_not_social") end if record.first_time_property_let_as_social_housing? && record.rsnvac.present? && !record.has_first_let_vacancy_reason? - record.errors.add :rsnvac, I18n.t("validations.property.rsnvac.first_let_social") + record.errors.add :rsnvac, I18n.t("validations.lettings.property.rsnvac.first_let_social") end if record.is_relet_to_temp_tenant? && !record.previous_tenancy_was_temporary? - record.errors.add :rsnvac, I18n.t("validations.property.rsnvac.non_temp_accommodation") + record.errors.add :rsnvac, I18n.t("validations.lettings.property.rsnvac.non_temp_accommodation") end if record.is_relet_to_temp_tenant? && REFERRAL_INVALID_TMP.include?(record.referral) - record.errors.add :rsnvac, I18n.t("validations.property.rsnvac.referral_invalid") - record.errors.add :referral, :referral_invalid, message: I18n.t("validations.household.referral.rsnvac_non_temp") + record.errors.add :rsnvac, I18n.t("validations.lettings.property.rsnvac.referral_invalid") + record.errors.add :referral, :referral_invalid, message: I18n.t("validations.lettings.property.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") + record.errors.add :rsnvac, I18n.t("validations.lettings.property.rsnvac.not_a_renewal") end end def validate_unitletas(record) if record.first_time_property_let_as_social_housing? && record.unitletas.present? - record.errors.add :unitletas, I18n.t("validations.property.rsnvac.previous_let_social") + record.errors.add :unitletas, I18n.t("validations.lettings.property.unitletas.previous_let_social") end end @@ -36,17 +36,17 @@ module Validations::PropertyValidations return unless record.unittype_gn if record.is_bedsit? && record.beds != 1 && record.beds.present? && !record.form.start_year_2024_or_later? - record.errors.add :unittype_gn, I18n.t("validations.property.unittype_gn.one_bedroom_bedsit") - record.errors.add :beds, I18n.t("validations.property.unittype_gn.one_bedroom_bedsit") + record.errors.add :unittype_gn, I18n.t("validations.lettings.property.unittype_gn.one_bedroom_bedsit") + record.errors.add :beds, I18n.t("validations.lettings.property.beds.one_bedroom_bedsit") end if record.hhmemb == 1 && record.is_shared_housing? && !record.beds.to_i.between?(1, 3) && record.beds.present? - record.errors.add :unittype_gn, I18n.t("validations.property.unittype_gn.one_three_bedroom_single_tenant_shared") - record.errors.add :beds, :one_three_bedroom_single_tenant_shared, message: I18n.t("validations.property.unittype_gn.one_three_bedroom_single_tenant_shared") + record.errors.add :unittype_gn, I18n.t("validations.lettings.property.unittype_gn.one_three_bedroom_single_tenant_shared") + record.errors.add :beds, :one_three_bedroom_single_tenant_shared, message: I18n.t("validations.lettings.property.beds.one_three_bedroom_single_tenant_shared") elsif record.is_shared_housing? && record.beds.present? && !record.beds.to_i.between?(1, 7) - record.errors.add :unittype_gn, I18n.t("validations.property.unittype_gn.one_seven_bedroom_shared") - record.errors.add :beds, I18n.t("validations.property.unittype_gn.one_seven_bedroom_shared") + record.errors.add :unittype_gn, I18n.t("validations.lettings.property.unittype_gn.one_seven_bedroom_shared") + record.errors.add :beds, I18n.t("validations.lettings.property.beds.one_seven_bedroom_shared") end end @@ -55,13 +55,13 @@ module Validations::PropertyValidations return if record.uprn.match?(/^[0-9]{1,12}$/) - record.errors.add :uprn, I18n.t("validations.property.uprn.invalid") + record.errors.add :uprn, I18n.t("validations.lettings.property.uprn.invalid") end def validate_property_postcode(record) postcode = record.postcode_full if record.postcode_known? && (postcode.blank? || !postcode.match(POSTCODE_REGEXP)) - error_message = I18n.t("validations.lettings.property_information.postcode_full.invalid") + error_message = I18n.t("validations.lettings.property.postcode_full.invalid") record.errors.add :postcode_full, :wrong_format, message: error_message end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 8cf9634b5..20cd63bf4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -265,24 +265,11 @@ en: owning_organisation: data_sharing_agreement_not_signed: "The organisation must accept the Data Sharing Agreement before it can be selected as the owning organisation." property: - uprn: - invalid: "UPRN must be 12 digits or less." uprn_known: invalid: "You must answer UPRN known?" la: la_invalid_for_org: "%{org_name} does not operate in %{la_name}." postcode_invalid_for_org: "Enter a postcode in an area covered by %{org_name}." - rsnvac: - first_let_not_social: "Enter a reason for vacancy that is not 'first let' if unit has been previously let as social housing." - 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 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." - one_three_bedroom_single_tenant_shared: "A shared house with fewer than two tenants must have 1 to 3 bedrooms." financial: income: @@ -370,7 +357,6 @@ en: internal_transfer: "Answer cannot be a fixed-term or lifetime local authority general needs tenancy as it’s an internal transfer and a private registered provider is on the tenancy agreement." referral: secure_tenancy: "Answer must be internal transfer as this is a secure tenancy." - rsnvac_non_temp: "Answer cannot be this source of referral as 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 this is not an internal transfer." assessed_homeless: "Answer cannot be internal transfer as the tenant was assessed as homeless." other_homeless: "Answer cannot be internal transfer as the tenant was considered homeless by their landlord." diff --git a/config/locales/validations/lettings/property_information.en.yml b/config/locales/validations/lettings/property_information.en.yml index ed42acb4c..af78064de 100644 --- a/config/locales/validations/lettings/property_information.en.yml +++ b/config/locales/validations/lettings/property_information.en.yml @@ -1,6 +1,27 @@ en: validations: lettings: - property_information: + property: postcode_full: invalid: "Enter a postcode in the correct format, for example AA1 1AA." + rsnvac: + first_let_not_social: "Enter a reason for vacancy that is not 'first let' if unit has been previously let as social housing." + first_let_social: "Reason for vacancy must be first let if unit has been previously let as social housing." + 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." + referral: + rsnvac_non_temp: "Answer cannot be this source of referral as this is a re-let to tenant who occupied the same property as temporary accommodation." + unitletas: + previous_let_social: "Property cannot have a previous let type if being let as social housing for the first time." + unittype_gn: + one_bedroom_bedsit: "A bedsit can only have one bedroom." + one_three_bedroom_single_tenant_shared: "A shared house with fewer than two tenants must have 1 to 3 bedrooms." + one_seven_bedroom_shared: "A shared house must have 1 to 7 bedrooms." + beds: + one_bedroom_bedsit: "A bedsit can only have one bedroom." + one_three_bedroom_single_tenant_shared: "A shared house with fewer than two tenants must have 1 to 3 bedrooms." + one_seven_bedroom_shared: "A shared house must have 1 to 7 bedrooms." + uprn: + invalid: "UPRN must be 12 digits or less." + diff --git a/spec/models/validations/property_validations_spec.rb b/spec/models/validations/property_validations_spec.rb index 8cf484f91..8c05d9559 100644 --- a/spec/models/validations/property_validations_spec.rb +++ b/spec/models/validations/property_validations_spec.rb @@ -54,8 +54,8 @@ RSpec.describe Validations::PropertyValidations do property_validator.validate_shared_housing_rooms(log) - expect(log.errors["unittype_gn"]).to include(I18n.t("validations.property.unittype_gn.one_bedroom_bedsit")) - expect(log.errors["beds"]).to include(I18n.t("validations.property.unittype_gn.one_bedroom_bedsit")) + expect(log.errors["unittype_gn"]).to include(I18n.t("validations.lettings.property.unittype_gn.one_bedroom_bedsit")) + expect(log.errors["beds"]).to include(I18n.t("validations.lettings.property.unittype_gn.one_bedroom_bedsit")) end end end @@ -80,14 +80,14 @@ RSpec.describe Validations::PropertyValidations do property_validator.validate_shared_housing_rooms(log) - expect(log.errors["unittype_gn"]).to include(I18n.t("validations.property.unittype_gn.one_bedroom_bedsit")) - expect(log.errors["beds"]).to include(I18n.t("validations.property.unittype_gn.one_bedroom_bedsit")) + expect(log.errors["unittype_gn"]).to include(I18n.t("validations.lettings.property.unittype_gn.one_bedroom_bedsit")) + expect(log.errors["beds"]).to include(I18n.t("validations.lettings.property.unittype_gn.one_bedroom_bedsit")) end end end context "when shared housing has more than 7 bedrooms" do - let(:expected_error) { I18n.t("validations.property.unittype_gn.one_seven_bedroom_shared") } + let(:expected_error) { I18n.t("validations.lettings.property.unittype_gn.one_seven_bedroom_shared") } it "adds an error if the number of bedrooms is not between 1 and 7" do log.beds = 8 @@ -95,12 +95,12 @@ RSpec.describe Validations::PropertyValidations do log.hhmemb = 3 property_validator.validate_shared_housing_rooms(log) expect(log.errors["unittype_gn"]).to include(match(expected_error)) - expect(log.errors["beds"]).to include(I18n.t("validations.property.unittype_gn.one_seven_bedroom_shared")) + expect(log.errors["beds"]).to include(I18n.t("validations.lettings.property.unittype_gn.one_seven_bedroom_shared")) end end context "when shared housing has less than 1 bedrooms" do - let(:expected_error) { I18n.t("validations.property.unittype_gn.one_seven_bedroom_shared") } + let(:expected_error) { I18n.t("validations.lettings.property.unittype_gn.one_seven_bedroom_shared") } it "adds an error if the number of bedrooms is not between 1 and 7" do log.beds = 0 @@ -108,12 +108,12 @@ RSpec.describe Validations::PropertyValidations do log.hhmemb = 3 property_validator.validate_shared_housing_rooms(log) expect(log.errors["unittype_gn"]).to include(match(expected_error)) - expect(log.errors["beds"]).to include(I18n.t("validations.property.unittype_gn.one_seven_bedroom_shared")) + expect(log.errors["beds"]).to include(I18n.t("validations.lettings.property.unittype_gn.one_seven_bedroom_shared")) end end context "when there are too many bedrooms for the number of household members and unit type" do - let(:expected_error) { I18n.t("validations.property.unittype_gn.one_three_bedroom_single_tenant_shared") } + let(:expected_error) { I18n.t("validations.lettings.property.unittype_gn.one_three_bedroom_single_tenant_shared") } it "adds an error" do log.beds = 4 @@ -121,7 +121,7 @@ RSpec.describe Validations::PropertyValidations do log.hhmemb = 1 property_validator.validate_shared_housing_rooms(log) expect(log.errors["unittype_gn"]).to include(match(expected_error)) - expect(log.errors["beds"]).to include(I18n.t("validations.property.unittype_gn.one_three_bedroom_single_tenant_shared")) + expect(log.errors["beds"]).to include(I18n.t("validations.lettings.property.unittype_gn.one_three_bedroom_single_tenant_shared")) end end end @@ -133,19 +133,19 @@ RSpec.describe Validations::PropertyValidations do log.unitletas = 0 property_validator.validate_unitletas(log) expect(log.errors["unitletas"]) - .to include(match I18n.t("validations.property.rsnvac.previous_let_social")) + .to include(match I18n.t("validations.lettings.property.unitletas.previous_let_social")) log.unitletas = 1 property_validator.validate_unitletas(log) expect(log.errors["unitletas"]) - .to include(match I18n.t("validations.property.rsnvac.previous_let_social")) + .to include(match I18n.t("validations.lettings.property.unitletas.previous_let_social")) log.unitletas = 2 property_validator.validate_unitletas(log) expect(log.errors["unitletas"]) - .to include(match I18n.t("validations.property.rsnvac.previous_let_social")) + .to include(match I18n.t("validations.lettings.property.unitletas.previous_let_social")) log.unitletas = 3 property_validator.validate_unitletas(log) expect(log.errors["unitletas"]) - .to include(match I18n.t("validations.property.rsnvac.previous_let_social")) + .to include(match I18n.t("validations.lettings.property.unitletas.previous_let_social")) end end @@ -166,7 +166,7 @@ RSpec.describe Validations::PropertyValidations do log.rsnvac = 6 property_validator.validate_rsnvac(log) expect(log.errors["rsnvac"]) - .to include(match I18n.t("validations.property.rsnvac.first_let_social")) + .to include(match I18n.t("validations.lettings.property.rsnvac.first_let_social")) end it "expects to have a first let reason for vacancy" do @@ -189,15 +189,15 @@ RSpec.describe Validations::PropertyValidations do log.rsnvac = 15 property_validator.validate_rsnvac(log) expect(log.errors["rsnvac"]) - .to include(match I18n.t("validations.property.rsnvac.first_let_not_social")) + .to include(match I18n.t("validations.lettings.property.rsnvac.first_let_not_social")) log.rsnvac = 16 property_validator.validate_rsnvac(log) expect(log.errors["rsnvac"]) - .to include(match I18n.t("validations.property.rsnvac.first_let_not_social")) + .to include(match I18n.t("validations.lettings.property.rsnvac.first_let_not_social")) log.rsnvac = 17 property_validator.validate_rsnvac(log) expect(log.errors["rsnvac"]) - .to include(match I18n.t("validations.property.rsnvac.first_let_not_social")) + .to include(match I18n.t("validations.lettings.property.rsnvac.first_let_not_social")) end it "expects the reason for vacancy to be a first let as social housing reason" do @@ -220,7 +220,7 @@ RSpec.describe Validations::PropertyValidations do log.rsnvac = 14 property_validator.validate_rsnvac(log) expect(log.errors["rsnvac"]) - .to include(match I18n.t("validations.property.rsnvac.not_a_renewal")) + .to include(match I18n.t("validations.lettings.property.rsnvac.not_a_renewal")) end end end @@ -237,7 +237,7 @@ RSpec.describe Validations::PropertyValidations do log.prevten = prevten property_validator.validate_rsnvac(log) expect(log.errors["rsnvac"]) - .to include(match I18n.t("validations.property.rsnvac.non_temp_accommodation")) + .to include(match I18n.t("validations.lettings.property.rsnvac.non_temp_accommodation")) end end @@ -247,7 +247,7 @@ RSpec.describe Validations::PropertyValidations do log.referral = src property_validator.validate_rsnvac(log) expect(log.errors["rsnvac"]) - .to include(match I18n.t("validations.property.rsnvac.referral_invalid")) + .to include(match I18n.t("validations.lettings.property.rsnvac.referral_invalid")) end end end