Browse Source

Validate supported housing logs

pull/2763/head
Kat 9 months ago
parent
commit
c5b80b3f50
  1. 12
      app/models/validations/property_validations.rb
  2. 4
      config/locales/validations/lettings/property_information.en.yml
  3. 22
      spec/models/validations/property_validations_spec.rb
  4. 6
      spec/models/validations/sales/property_validations_spec.rb

12
app/models/validations/property_validations.rb

@ -48,7 +48,10 @@ module Validations::PropertyValidations
end end
def validate_la_in_england(record) def validate_la_in_england(record)
return unless record.form.start_year_2025_or_later? && record.la.present? 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)) 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 :la, I18n.t("validations.lettings.property.la.not_in_england")
@ -56,5 +59,12 @@ module Validations::PropertyValidations
record.errors.add :uprn, I18n.t("validations.lettings.property.uprn.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_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") record.errors.add :uprn_selection, I18n.t("validations.lettings.property.uprn_selection.not_in_england")
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")
end
end end
end end

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

@ -26,3 +26,7 @@ en:
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" 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: 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" 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"
scheme_id:
not_in_england: "It looks like you have selected a location with a local authority outside of England - only submit Lettings forms for Lettings that occur in England"
location_id:
not_in_england: "It looks like you have selected a location with a local authority outside of England - only submit Lettings forms for Lettings that occur in England"

22
spec/models/validations/property_validations_spec.rb

@ -211,8 +211,8 @@ RSpec.describe Validations::PropertyValidations do
allow(log.form).to receive(:start_year_2025_or_later?).and_return true allow(log.form).to receive(:start_year_2025_or_later?).and_return true
end end
context "and the local authority is not in England" do context "and the local authority is not in England for general needs log" do
let(:log) { build(:lettings_log, la: "S12000019") } let(:log) { build(:lettings_log, la: "S12000019", needstype: 1) }
it "adds an error" do it "adds an error" do
property_validator.validate_la_in_england(log) property_validator.validate_la_in_england(log)
@ -221,6 +221,24 @@ RSpec.describe Validations::PropertyValidations do
expect(log.errors["uprn"]).to include(I18n.t("validations.lettings.property.uprn.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_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["uprn_selection"]).to include(I18n.t("validations.lettings.property.uprn_selection.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["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

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

@ -150,7 +150,7 @@ RSpec.describe Validations::Sales::PropertyValidations do
end end
context "and the local authority is not in England" do context "and the local authority is not in England" do
let(:log) { build(:lettings_log, la: "S12000019") } let(:log) { build(:sales_log, la: "S12000019") }
it "adds an error" do it "adds an error" do
property_validator.validate_la_in_england(log) property_validator.validate_la_in_england(log)
@ -163,7 +163,7 @@ RSpec.describe Validations::Sales::PropertyValidations do
end end
context "and the local authority is in England" do context "and the local authority is in England" do
let(:log) { build(:lettings_log, la: "E06000002") } let(:log) { build(:sales_log, la: "E06000002") }
it "does not add an error" do it "does not add an error" do
property_validator.validate_la_in_england(log) property_validator.validate_la_in_england(log)
@ -182,7 +182,7 @@ RSpec.describe Validations::Sales::PropertyValidations do
end end
context "and the local authority is not in England" do context "and the local authority is not in England" do
let(:log) { build(:lettings_log, la: "S12000019") } let(:log) { build(:sales_log, la: "S12000019") }
it "does not add an error" do it "does not add an error" do
property_validator.validate_la_in_england(log) property_validator.validate_la_in_england(log)

Loading…
Cancel
Save