Browse Source

Add LA in England validation for 2025

pull/2763/head
Kat 9 months ago
parent
commit
e5ce1c70bf
  1. 11
      app/models/validations/property_validations.rb
  2. 11
      app/models/validations/sales/property_validations.rb
  3. 9
      config/locales/validations/lettings/property_information.en.yml
  4. 8
      config/locales/validations/sales/property_information.en.yml
  5. 53
      spec/models/validations/property_validations_spec.rb
  6. 53
      spec/models/validations/sales/property_validations_spec.rb

11
app/models/validations/property_validations.rb

@ -46,4 +46,15 @@ module Validations::PropertyValidations
record.errors.add :postcode_full, :wrong_format, message: error_message record.errors.add :postcode_full, :wrong_format, message: error_message
end end
end end
def validate_la_in_england(record)
return unless record.form.start_year_2025_or_later? && record.la.present?
return if record.la.in?(LocalAuthority.england.pluck(:code))
record.errors.add :la, I18n.t("validations.lettings.property.la.not_in_england")
record.errors.add :postcode_full, I18n.t("validations.lettings.property.postcode_full.not_in_england")
record.errors.add :uprn, I18n.t("validations.lettings.property.uprn.not_in_england")
record.errors.add :uprn_confirmation, I18n.t("validations.lettings.property.uprn_confirmation.not_in_england")
record.errors.add :uprn_selection, I18n.t("validations.lettings.property.uprn_selection.not_in_england")
end
end end

11
app/models/validations/sales/property_validations.rb

@ -36,4 +36,15 @@ module Validations::Sales::PropertyValidations
record.errors.add :postcode_full, :wrong_format, message: error_message record.errors.add :postcode_full, :wrong_format, message: error_message
end end
end end
def validate_la_in_england(record)
return unless record.form.start_year_2025_or_later? && record.la.present?
return if record.la.in?(LocalAuthority.england.pluck(:code))
record.errors.add :la, I18n.t("validations.sales.property_information.la.not_in_england")
record.errors.add :postcode_full, I18n.t("validations.sales.property_information.postcode_full.not_in_england")
record.errors.add :uprn, I18n.t("validations.sales.property_information.uprn.not_in_england")
record.errors.add :uprn_confirmation, I18n.t("validations.sales.property_information.uprn_confirmation.not_in_england")
record.errors.add :uprn_selection, I18n.t("validations.sales.property_information.uprn_selection.not_in_england")
end
end end

9
config/locales/validations/lettings/property_information.en.yml

@ -4,6 +4,7 @@ en:
property: property:
postcode_full: postcode_full:
invalid: "Enter a postcode in the correct format, for example AA1 1AA." invalid: "Enter a postcode in the correct format, for example AA1 1AA."
not_in_england: "It looks like you have entered a postcode for a local authority outside of England - only submit Lettings forms for Lettings that occur in England"
rsnvac: rsnvac:
non_temp_accommodation: "Answer cannot be re-let to tenant who occupied the same property as temporary accommodation as this accommodation is not temporary." 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." 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."
@ -18,4 +19,10 @@ en:
one_seven_bedroom_shared: "A shared house must have 1 to 7 bedrooms." one_seven_bedroom_shared: "A shared house must have 1 to 7 bedrooms."
uprn: uprn:
invalid: "UPRN must be 12 digits or less." invalid: "UPRN must be 12 digits or less."
not_in_england: "It looks like you have entered a UPRN for a local authority outside of England - only submit Lettings forms for Lettings that occur in England"
uprn_confirmation:
not_in_england: "It looks like you have entered a UPRN for a local authority outside of England - only submit Lettings forms for Lettings that occur in England"
uprn_selection:
not_in_england: "It looks like you have selected an address for a local authority outside of England - only submit Lettings forms for Lettings that occur in England"
la:
not_in_england: "It looks like you have entered a local authority outside of England - only submit Lettings forms for Lettings that occur in England"

8
config/locales/validations/sales/property_information.en.yml

@ -7,6 +7,7 @@ en:
joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match." joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match."
not_joint_purchase: "Buyer’s last accommodation and discounted ownership postcodes must match." not_joint_purchase: "Buyer’s last accommodation and discounted ownership postcodes must match."
invalid: "Enter a postcode in the correct format, for example AA1 1AA." invalid: "Enter a postcode in the correct format, for example AA1 1AA."
not_in_england: "It looks like you have entered a postcode for a local authority outside of England - only submit Sales forms for Sales that occur in England"
ppostcode_full: ppostcode_full:
postcode_must_match_previous: postcode_must_match_previous:
joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match." joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match."
@ -20,9 +21,16 @@ en:
joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match." joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match."
not_joint_purchase: "Buyer’s 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." invalid: "UPRN must be 12 digits or less."
not_in_england: "It looks like you have entered a UPRN for a local authority outside of England - only submit Sales forms for Sales that occur in England"
beds: beds:
bedsits_have_max_one_bedroom: "Number of bedrooms must be 1 if the property is a bedsit." bedsits_have_max_one_bedroom: "Number of bedrooms must be 1 if the property is a bedsit."
proptype: proptype:
bedsits_have_max_one_bedroom: "Answer cannot be 'Bedsit' if the property has 2 or more bedrooms." bedsits_have_max_one_bedroom: "Answer cannot be 'Bedsit' if the property has 2 or more bedrooms."
uprn_known: uprn_known:
invalid: "You must answer UPRN known?" invalid: "You must answer UPRN known?"
la:
not_in_england: "It looks like you have entered a local authority outside of England - only submit Sales forms for Sales that occur in England"
uprn_confirmation:
not_in_england: "It looks like you have entered a UPRN for a local authority outside of England - only submit Sales forms for Sales that occur in England"
uprn_selection:
not_in_england: "It looks like you have selected an address for a local authority outside of England - only submit Sales forms for Sales that occur in England"

53
spec/models/validations/property_validations_spec.rb

@ -204,4 +204,57 @@ RSpec.describe Validations::PropertyValidations do
end end
end end
end end
describe "#validate_la_in_england" do
context "with a log on or after 2025" do
before do
allow(log.form).to receive(:start_year_2025_or_later?).and_return true
end
context "and the local authority is not in England" do
let(:log) { build(:lettings_log, la: "S12000019") }
it "adds an error" do
property_validator.validate_la_in_england(log)
expect(log.errors["la"]).to include(I18n.t("validations.lettings.property.la.not_in_england"))
expect(log.errors["postcode_full"]).to include(I18n.t("validations.lettings.property.postcode_full.not_in_england"))
expect(log.errors["uprn"]).to include(I18n.t("validations.lettings.property.uprn.not_in_england"))
expect(log.errors["uprn_confirmation"]).to include(I18n.t("validations.lettings.property.uprn_confirmation.not_in_england"))
expect(log.errors["uprn_selection"]).to include(I18n.t("validations.lettings.property.uprn_selection.not_in_england"))
end
end
context "and the local authority is in England" do
let(:log) { build(:lettings_log, la: "E06000002") }
it "does not add an error" do
property_validator.validate_la_in_england(log)
expect(log.errors["la"]).to be_empty
expect(log.errors["postcode_full"]).to be_empty
expect(log.errors["uprn"]).to be_empty
expect(log.errors["uprn_confirmation"]).to be_empty
expect(log.errors["uprn_selection"]).to be_empty
end
end
end
context "with a log before 2025" do
before do
allow(log.form).to receive(:start_year_2025_or_later?).and_return false
end
context "and the local authority is not in England" do
let(:log) { build(:lettings_log, la: "S12000019") }
it "does not add an error" do
property_validator.validate_la_in_england(log)
expect(log.errors["la"]).to be_empty
expect(log.errors["postcode_full"]).to be_empty
expect(log.errors["uprn"]).to be_empty
expect(log.errors["uprn_confirmation"]).to be_empty
expect(log.errors["uprn_selection"]).to be_empty
end
end
end
end
end end

53
spec/models/validations/sales/property_validations_spec.rb

@ -142,4 +142,57 @@ RSpec.describe Validations::Sales::PropertyValidations do
end end
end end
end end
describe "#validate_la_in_england" do
context "with a log on or after 2025" do
before do
allow(log.form).to receive(:start_year_2025_or_later?).and_return true
end
context "and the local authority is not in England" do
let(:log) { build(:lettings_log, la: "S12000019") }
it "adds an error" do
property_validator.validate_la_in_england(log)
expect(log.errors["la"]).to include(I18n.t("validations.sales.property_information.la.not_in_england"))
expect(log.errors["postcode_full"]).to include(I18n.t("validations.sales.property_information.postcode_full.not_in_england"))
expect(log.errors["uprn"]).to include(I18n.t("validations.sales.property_information.uprn.not_in_england"))
expect(log.errors["uprn_confirmation"]).to include(I18n.t("validations.sales.property_information.uprn_confirmation.not_in_england"))
expect(log.errors["uprn_selection"]).to include(I18n.t("validations.sales.property_information.uprn_selection.not_in_england"))
end
end
context "and the local authority is in England" do
let(:log) { build(:lettings_log, la: "E06000002") }
it "does not add an error" do
property_validator.validate_la_in_england(log)
expect(log.errors["la"]).to be_empty
expect(log.errors["postcode_full"]).to be_empty
expect(log.errors["uprn"]).to be_empty
expect(log.errors["uprn_confirmation"]).to be_empty
expect(log.errors["uprn_selection"]).to be_empty
end
end
end
context "with a log before 2025" do
before do
allow(log.form).to receive(:start_year_2025_or_later?).and_return false
end
context "and the local authority is not in England" do
let(:log) { build(:lettings_log, la: "S12000019") }
it "does not add an error" do
property_validator.validate_la_in_england(log)
expect(log.errors["la"]).to be_empty
expect(log.errors["postcode_full"]).to be_empty
expect(log.errors["uprn"]).to be_empty
expect(log.errors["uprn_confirmation"]).to be_empty
expect(log.errors["uprn_selection"]).to be_empty
end
end
end
end
end end

Loading…
Cancel
Save