Browse Source

CLDC-3734 Add LA in England validation for 2025 (#2763)

* Add LA in England validation for 2025

* Validate supported housing logs

* Add error message to the date

* Update error messages

* lint

* Fix error messages for date

* Update no address found soft validation

* Update validation messages
pull/2792/head^2 v0.4.86
kosiakkatrina 1 month ago committed by GitHub
parent
commit
671232daa9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      app/models/form/lettings/pages/no_address_found.rb
  2. 27
      app/models/validations/property_validations.rb
  3. 16
      app/models/validations/sales/property_validations.rb
  4. 8
      config/locales/forms/2024/lettings/soft_validations.en.yml
  5. 17
      config/locales/validations/lettings/property_information.en.yml
  6. 11
      config/locales/validations/sales/property_information.en.yml
  7. 7
      spec/models/form/lettings/pages/no_address_found_spec.rb
  8. 74
      spec/models/validations/property_validations_spec.rb
  9. 56
      spec/models/validations/sales/property_validations_spec.rb

5
app/models/form/lettings/pages/no_address_found.rb

@ -3,12 +3,13 @@ class Form::Lettings::Pages::NoAddressFound < ::Form::Page
super
@id = "no_address_found"
@type = "interruption_screen"
@copy_key = "lettings.soft_validations.no_address_found"
@title_text = {
"translation" => "soft_validations.no_address_found.title_text",
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text",
"arguments" => [],
}
@informative_text = {
"translation" => "soft_validations.no_address_found.informative_text",
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.informative_text",
"arguments" => [],
}
@depends_on = [

27
app/models/validations/property_validations.rb

@ -46,4 +46,31 @@ module Validations::PropertyValidations
record.errors.add :postcode_full, :wrong_format, message: error_message
end
end
def validate_la_in_england(record)
return unless record.form.start_year_2025_or_later?
if record.is_general_needs?
return unless record.la
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")
if record.uprn.present?
record.errors.add :startdate, I18n.t("validations.lettings.property.startdate.address_not_in_england")
else
record.errors.add :startdate, I18n.t("validations.lettings.property.startdate.postcode_not_in_england")
end
elsif record.is_supported_housing?
return unless record.location
return if record.location.location_code.in?(LocalAuthority.england.pluck(:code))
record.errors.add :location_id, I18n.t("validations.lettings.property.location_id.not_in_england")
record.errors.add :scheme_id, I18n.t("validations.lettings.property.scheme_id.not_in_england")
record.errors.add :startdate, I18n.t("validations.lettings.property.startdate.location_not_in_england")
end
end
end

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

@ -36,4 +36,20 @@ module Validations::Sales::PropertyValidations
record.errors.add :postcode_full, :wrong_format, message: error_message
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")
if record.uprn.present?
record.errors.add :saledate, I18n.t("validations.sales.property_information.saledate.address_not_in_england")
else
record.errors.add :saledate, I18n.t("validations.sales.property_information.saledate.postcode_not_in_england")
end
end
end

8
config/locales/forms/2024/lettings/soft_validations.en.yml

@ -130,3 +130,11 @@ en:
question_text: "Are you sure the property has been vacant for this long?"
title_text: "You told us the property has been vacant for 2 years."
informative_text: "This is longer than we would expect."
no_address_found:
page_header: ""
check_answer_label: "No address found"
hint_text: ""
question_text: "We could not find an address that matches your search. You can search again or continue to enter the address manually."
title_text: "No address found"
informative_text: "We could not find an address that matches your search. You can search again or continue to enter the address manually."

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

@ -4,6 +4,7 @@ en:
property:
postcode_full:
invalid: "Enter a postcode in the correct format, for example AA1 1AA."
not_in_england: "It looks like you have an entered a postcode outside of England. Only create logs for lettings in England."
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."
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,18 @@ en:
one_seven_bedroom_shared: "A shared house must have 1 to 7 bedrooms."
uprn:
invalid: "UPRN must be 12 digits or less."
not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England."
uprn_confirmation:
not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England."
uprn_selection:
not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England."
la:
not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England."
scheme_id:
not_in_england: "This scheme’s only location is outside of England. Only create logs for lettings in England."
location_id:
not_in_england: "It looks like you have selected a location outside of England. Only create logs for lettings in England."
startdate:
postcode_not_in_england: "It looks like you have an entered a postcode outside of England. Only create logs for lettings in England."
address_not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England."
location_not_in_england: "It looks like you have selected a location outside of England. Only create logs for lettings in England."

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

@ -7,6 +7,7 @@ en:
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: "Enter a postcode in the correct format, for example AA1 1AA."
not_in_england: "It looks like you have entered a postcode outside of England - only submit Lettings forms for Lettings that occur in England"
ppostcode_full:
postcode_must_match_previous:
joint_purchase: "Buyers’ last accommodation and discounted ownership postcodes must match."
@ -20,9 +21,19 @@ en:
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."
not_in_england: "It looks like you have an entered a postcode outside of England. Only create logs for lettings in England."
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?"
la:
not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England."
uprn_confirmation:
not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England."
uprn_selection:
not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England."
saledate:
postcode_not_in_england: "It looks like you have an entered a postcode outside of England. Only create logs for lettings in England."
address_not_in_england: "It looks like you have entered an address outside of England. Only create logs for lettings in England."

7
spec/models/form/lettings/pages/no_address_found_spec.rb

@ -5,7 +5,8 @@ RSpec.describe Form::Lettings::Pages::NoAddressFound, type: :model do
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) }
let(:subsection) { instance_double(Form::Subsection, form:) }
let(:log) { create(:lettings_log) }
it "has correct subsection" do
@ -37,11 +38,11 @@ RSpec.describe Form::Lettings::Pages::NoAddressFound, type: :model do
end
it "has the correct title_text" do
expect(page.title_text).to eq({ "arguments" => [], "translation" => "soft_validations.no_address_found.title_text" })
expect(page.title_text).to eq({ "arguments" => [], "translation" => "forms.2024.lettings.soft_validations.no_address_found.title_text" })
end
it "has the correct informative_text" do
expect(page.informative_text).to eq({ "arguments" => [], "translation" => "soft_validations.no_address_found.informative_text" })
expect(page.informative_text).to eq({ "arguments" => [], "translation" => "forms.2024.lettings.soft_validations.no_address_found.informative_text" })
end
it "has the correct interruption_screen_question_ids" do

74
spec/models/validations/property_validations_spec.rb

@ -204,4 +204,78 @@ RSpec.describe Validations::PropertyValidations do
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 for general needs log" do
let(:log) { build(:lettings_log, la: "S12000019", needstype: 1) }
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"))
expect(log.errors["startdate"]).to include(I18n.t("validations.lettings.property.startdate.postcode_not_in_england"))
expect(log.errors["scheme_id"]).to be_empty
expect(log.errors["location_id"]).to be_empty
end
end
context "and the local authority is not in England for supported housing log" do
let(:location) { create(:location, location_code: "S12000019") }
let(:log) { build(:lettings_log, la: "S12000019", needstype: 2, location:) }
it "adds an error" do
property_validator.validate_la_in_england(log)
expect(log.errors["scheme_id"]).to include(I18n.t("validations.lettings.property.scheme_id.not_in_england"))
expect(log.errors["location_id"]).to include(I18n.t("validations.lettings.property.location_id.not_in_england"))
expect(log.errors["startdate"]).to include(I18n.t("validations.lettings.property.startdate.location_not_in_england"))
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
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
expect(log.errors["startdate"]).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

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

@ -142,4 +142,60 @@ RSpec.describe Validations::Sales::PropertyValidations do
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(:sales_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"))
expect(log.errors["saledate"]).to include(I18n.t("validations.sales.property_information.saledate.postcode_not_in_england"))
end
end
context "and the local authority is in England" do
let(:log) { build(:sales_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
expect(log.errors["saledate"]).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(:sales_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
expect(log.errors["saledate"]).to be_empty
end
end
end
end
end

Loading…
Cancel
Save