From 9bd3389c846243bf9ba1bb81334661f2c5ff53ba Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Tue, 22 Oct 2024 16:27:51 +0100 Subject: [PATCH] CLDC-3655 Extract property information validations (#2700) * Extract property information validations * Refactor possesive variable from errors --- app/models/form/sales/questions/uprn.rb | 2 +- app/models/form/sales/questions/uprn_known.rb | 2 +- .../validations/sales/property_validations.rb | 15 ++++++----- config/locales/en.yml | 6 ----- .../sales/property_information.en.yml | 27 +++++++++++++++++++ 5 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 config/locales/validations/sales/property_information.en.yml diff --git a/app/models/form/sales/questions/uprn.rb b/app/models/form/sales/questions/uprn.rb index 75a41a0ec..94aaccb43 100644 --- a/app/models/form/sales/questions/uprn.rb +++ b/app/models/form/sales/questions/uprn.rb @@ -16,7 +16,7 @@ class Form::Sales::Questions::Uprn < ::Form::Question end def unanswered_error_message - I18n.t("validations.property.uprn.invalid") + I18n.t("validations.sales.property_information.uprn.invalid") end def get_extra_check_answer_value(log) diff --git a/app/models/form/sales/questions/uprn_known.rb b/app/models/form/sales/questions/uprn_known.rb index 44ce03cad..fdd0c9e9a 100644 --- a/app/models/form/sales/questions/uprn_known.rb +++ b/app/models/form/sales/questions/uprn_known.rb @@ -31,7 +31,7 @@ class Form::Sales::Questions::UprnKnown < ::Form::Question }.freeze def unanswered_error_message - I18n.t("validations.property.uprn_known.invalid") + I18n.t("validations.sales.property_information.uprn_known.invalid") end QUESTION_NUMBER_FROM_YEAR = { 2023 => 14, 2024 => 15 }.freeze diff --git a/app/models/validations/sales/property_validations.rb b/app/models/validations/sales/property_validations.rb index 50818c422..59d616c9a 100644 --- a/app/models/validations/sales/property_validations.rb +++ b/app/models/validations/sales/property_validations.rb @@ -4,10 +4,11 @@ module Validations::Sales::PropertyValidations return unless record.ppostcode_full.present? && record.postcode_full.present? if record.discounted_ownership_sale? && record.ppostcode_full != record.postcode_full - record.errors.add :postcode_full, I18n.t("validations.property.postcode.must_match_previous", buyer_possessive: record.joint_purchase? ? "Buyers’" : "Buyer’s") - record.errors.add :ppostcode_full, I18n.t("validations.property.postcode.must_match_previous", buyer_possessive: record.joint_purchase? ? "Buyers’" : "Buyer’s") - record.errors.add :ownershipsch, I18n.t("validations.property.postcode.must_match_previous", buyer_possessive: record.joint_purchase? ? "Buyers’" : "Buyer’s") - record.errors.add :uprn, I18n.t("validations.property.postcode.must_match_previous", buyer_possessive: record.joint_purchase? ? "Buyers’" : "Buyer’s") + joint_purchase_id = record.joint_purchase? ? "joint_purchase" : "not_joint_purchase" + record.errors.add :postcode_full, I18n.t("validations.sales.property_information.postcode_full.postcode_must_match_previous.#{joint_purchase_id}") + record.errors.add :ppostcode_full, I18n.t("validations.sales.property_information.ppostcode_full.postcode_must_match_previous.#{joint_purchase_id}") + record.errors.add :ownershipsch, I18n.t("validations.sales.property_information.ownershipsch.postcode_must_match_previous.#{joint_purchase_id}") + record.errors.add :uprn, I18n.t("validations.sales.property_information.uprn.postcode_must_match_previous.#{joint_purchase_id}") end end @@ -15,8 +16,8 @@ module Validations::Sales::PropertyValidations return unless record.proptype.present? && record.beds.present? if record.is_bedsit? && record.beds > 1 - record.errors.add :proptype, I18n.t("validations.property.proptype.bedsits_have_max_one_bedroom") - record.errors.add :beds, I18n.t("validations.property.beds.bedsits_have_max_one_bedroom") + record.errors.add :proptype, I18n.t("validations.sales.property_information.proptype.bedsits_have_max_one_bedroom") + record.errors.add :beds, I18n.t("validations.sales.property_information.beds.bedsits_have_max_one_bedroom") end end @@ -25,6 +26,6 @@ module Validations::Sales::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.sales.property_information.uprn.invalid") end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 7cff7aae7..ff73bfdcb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -382,12 +382,6 @@ en: 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." - beds: - bedsits_have_max_one_bedroom: "Number of bedrooms must be 1 if the property is a bedsit." - proptype: - bedsits_have_max_one_bedroom: "Answer cannot be 'Bedsit' if the property has 2 or more bedrooms." - postcode: - must_match_previous: "%{buyer_possessive} last accommodation and discounted ownership postcodes must match." financial: tshortfall: diff --git a/config/locales/validations/sales/property_information.en.yml b/config/locales/validations/sales/property_information.en.yml new file mode 100644 index 000000000..e69f90edf --- /dev/null +++ b/config/locales/validations/sales/property_information.en.yml @@ -0,0 +1,27 @@ +en: + validations: + sales: + property_information: + postcode_full: + postcode_must_match_previous: + joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match." + not_joint_purchase: "Buyer’s last accommodation and discounted ownership postcodes must match." + ppostcode_full: + postcode_must_match_previous: + joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match." + not_joint_purchase: "Buyer’s last accommodation and discounted ownership postcodes must match." + ownershipsch: + postcode_must_match_previous: + joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match." + not_joint_purchase: "Buyer’s last accommodation and discounted ownership postcodes must match." + uprn: + postcode_must_match_previous: + joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match." + not_joint_purchase: "Buyer’s last accommodation and discounted ownership postcodes must match." + invalid: "UPRN must be 12 digits or less." + beds: + bedsits_have_max_one_bedroom: "Number of bedrooms must be 1 if the property is a bedsit." + proptype: + bedsits_have_max_one_bedroom: "Answer cannot be 'Bedsit' if the property has 2 or more bedrooms." + uprn_known: + invalid: "You must answer UPRN known?"