Browse Source

CLDC-3687: Extract copy - lettings date validations (#2738)

pull/2726/head^2
Manny Dinssa 2 months ago committed by GitHub
parent
commit
7f016f898f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 22
      app/models/validations/date_validations.rb
  2. 13
      config/locales/en.yml
  3. 20
      config/locales/validations/lettings/date.en.yml
  4. 26
      spec/models/validations/date_validations_spec.rb

22
app/models/validations/date_validations.rb

@ -4,30 +4,30 @@ module Validations::DateValidations
def validate_property_major_repairs(record) def validate_property_major_repairs(record)
date_valid?("mrcdate", record) date_valid?("mrcdate", record)
if record["startdate"].present? && record["mrcdate"].present? && record["startdate"] < record["mrcdate"] if record["startdate"].present? && record["mrcdate"].present? && record["startdate"] < record["mrcdate"]
record.errors.add :mrcdate, I18n.t("validations.property.mrcdate.before_tenancy_start") record.errors.add :mrcdate, I18n.t("validations.lettings.date.mrcdate.before_tenancy_start")
end end
if is_rsnvac_first_let?(record) && record["mrcdate"].present? if is_rsnvac_first_let?(record) && record["mrcdate"].present?
record.errors.add :mrcdate, I18n.t("validations.property.mrcdate.not_first_let") record.errors.add :mrcdate, I18n.t("validations.lettings.date.mrcdate.not_first_let")
end end
if record["mrcdate"].present? && record["startdate"].present? && record["startdate"].to_date - record["mrcdate"].to_date > 3650 if record["mrcdate"].present? && record["startdate"].present? && record["startdate"].to_date - record["mrcdate"].to_date > 3650
record.errors.add :mrcdate, I18n.t("validations.property.mrcdate.ten_years_before_tenancy_start") record.errors.add :mrcdate, I18n.t("validations.lettings.date.mrcdate.ten_years_before_tenancy_start")
end end
end end
def validate_property_void_date(record) def validate_property_void_date(record)
if record["voiddate"].present? && record["startdate"].present? && record["startdate"].to_date - record["voiddate"].to_date > 3650 if record["voiddate"].present? && record["startdate"].present? && record["startdate"].to_date - record["voiddate"].to_date > 3650
record.errors.add :voiddate, I18n.t("validations.property.void_date.ten_years_before_tenancy_start") record.errors.add :voiddate, I18n.t("validations.lettings.date.void_date.ten_years_before_tenancy_start")
end end
if record["voiddate"].present? && record["startdate"].present? && record["startdate"].to_date < record["voiddate"].to_date if record["voiddate"].present? && record["startdate"].present? && record["startdate"].to_date < record["voiddate"].to_date
record.errors.add :voiddate, I18n.t("validations.property.void_date.before_tenancy_start") record.errors.add :voiddate, I18n.t("validations.lettings.date.void_date.before_tenancy_start")
end end
if record["voiddate"].present? && record["mrcdate"].present? && record["mrcdate"].to_date < record["voiddate"].to_date if record["voiddate"].present? && record["mrcdate"].present? && record["mrcdate"].to_date < record["voiddate"].to_date
record.errors.add :voiddate, :after_mrcdate, message: I18n.t("validations.property.void_date.after_mrcdate") record.errors.add :voiddate, :after_mrcdate, message: I18n.t("validations.lettings.date.void_date.after_mrcdate")
record.errors.add :mrcdate, I18n.t("validations.property.mrcdate.before_void_date") record.errors.add :mrcdate, I18n.t("validations.lettings.date.mrcdate.before_void_date")
end end
end end
@ -35,19 +35,19 @@ module Validations::DateValidations
return unless record.startdate && date_valid?("startdate", record) return unless record.startdate && date_valid?("startdate", record)
if record["voiddate"].present? && record.startdate < record["voiddate"] if record["voiddate"].present? && record.startdate < record["voiddate"]
record.errors.add :startdate, I18n.t("validations.setup.startdate.after_void_date") record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.after_void_date")
end end
if record["mrcdate"].present? && record.startdate < record["mrcdate"] if record["mrcdate"].present? && record.startdate < record["mrcdate"]
record.errors.add :startdate, I18n.t("validations.setup.startdate.after_major_repair_date") record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.after_major_repair_date")
end end
if record["voiddate"].present? && record["startdate"].to_date - record["voiddate"].to_date > 3650 if record["voiddate"].present? && record["startdate"].to_date - record["voiddate"].to_date > 3650
record.errors.add :startdate, I18n.t("validations.setup.startdate.ten_years_after_void_date") record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.ten_years_after_void_date")
end end
if record["mrcdate"].present? && record["startdate"].to_date - record["mrcdate"].to_date > 3650 if record["mrcdate"].present? && record["startdate"].to_date - record["mrcdate"].to_date > 3650
record.errors.add :startdate, I18n.t("validations.setup.startdate.ten_years_after_mrc_date") record.errors.add :startdate, I18n.t("validations.lettings.date.startdate.ten_years_after_mrc_date")
end end
end end

13
config/locales/en.yml

@ -295,11 +295,7 @@ en:
"Enter a date within the %{previous_start_year_short} to %{previous_end_year_short} or %{previous_end_year_short} to %{current_end_year_short} collection years, which is between %{previous_start_year_long} and %{current_end_year_long}." "Enter a date within the %{previous_start_year_short} to %{previous_end_year_short} or %{previous_end_year_short} to %{current_end_year_short} collection years, which is between %{previous_start_year_long} and %{current_end_year_long}."
later_than_14_days_after: "The tenancy start date must not be later than 14 days from today’s date." later_than_14_days_after: "The tenancy start date must not be later than 14 days from today’s date."
before_scheme_end_date: "The tenancy start date must be before the end date for this supported housing scheme." before_scheme_end_date: "The tenancy start date must be before the end date for this supported housing scheme."
after_void_date: "Enter a tenancy start date that is after the void date."
after_major_repair_date: "Enter a tenancy start date that is after the major repair date."
year_not_two_or_four_digits: "Tenancy start year must be 2 or 4 digits." year_not_two_or_four_digits: "Tenancy start year must be 2 or 4 digits."
ten_years_after_void_date: "Enter a tenancy start date that is no more than 10 years after the void date."
ten_years_after_mrc_date: "Enter a tenancy start date that is no more than 10 years after the major repairs completion date."
invalid_merged_organisations_start_date: invalid_merged_organisations_start_date:
same_organisation: "Enter a date when the owning and managing organisation was active. %{owning_organisation} became inactive on %{owning_organisation_merge_date} and was replaced by %{owning_absorbing_organisation}." same_organisation: "Enter a date when the owning and managing organisation was active. %{owning_organisation} became inactive on %{owning_organisation_merge_date} and was replaced by %{owning_absorbing_organisation}."
same_merge: "Enter a date when the owning and managing organisations were active. %{owning_organisation} and %{managing_organisation} became inactive on %{owning_organisation_merge_date} and were replaced by %{owning_absorbing_organisation}." same_merge: "Enter a date when the owning and managing organisations were active. %{owning_organisation} and %{managing_organisation} became inactive on %{owning_organisation_merge_date} and were replaced by %{owning_absorbing_organisation}."
@ -362,15 +358,6 @@ en:
invalid: "UPRN must be 12 digits or less." invalid: "UPRN must be 12 digits or less."
uprn_known: uprn_known:
invalid: "You must answer UPRN known?" invalid: "You must answer UPRN known?"
mrcdate:
before_tenancy_start: "Enter a major repairs date that is before the tenancy start date."
not_first_let: "Major repairs date must not be completed if the tenancy is a first let."
ten_years_before_tenancy_start: "Enter a major repairs completion date that is no more than 10 years before the tenancy start date."
before_void_date: "Major repairs date must be after the void date if provided."
void_date:
ten_years_before_tenancy_start: "Enter a void date no more than 10 years before the tenancy start date."
before_tenancy_start: "Enter a void date that is before the tenancy start date."
after_mrcdate: "Void date must be before the major repairs date if provided."
la: la:
la_invalid_for_org: "%{org_name} does not operate in %{la_name}." 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}." postcode_invalid_for_org: "Enter a postcode in an area covered by %{org_name}."

20
config/locales/validations/lettings/date.en.yml

@ -0,0 +1,20 @@
en:
validations:
lettings:
date:
startdate:
after_void_date: "Enter a tenancy start date that is after the void date."
after_major_repair_date: "Enter a tenancy start date that is after the major repair date."
ten_years_after_void_date: "Enter a tenancy start date that is no more than 10 years after the void date."
ten_years_after_mrc_date: "Enter a tenancy start date that is no more than 10 years after the major repairs completion date."
mrcdate:
before_tenancy_start: "Enter a major repairs date that is before the tenancy start date."
not_first_let: "Major repairs date must not be completed if the tenancy is a first let."
ten_years_before_tenancy_start: "Enter a major repairs completion date that is no more than 10 years before the tenancy start date."
before_void_date: "Major repairs date must be after the void date if provided."
void_date:
ten_years_before_tenancy_start: "Enter a void date no more than 10 years before the tenancy start date."
before_tenancy_start: "Enter a void date that is before the tenancy start date."
after_mrcdate: "Void date must be before the major repairs date if provided."

26
spec/models/validations/date_validations_spec.rb

@ -26,7 +26,7 @@ RSpec.describe Validations::DateValidations do
record.voiddate = Time.zone.local(2022, 2, 1) record.voiddate = Time.zone.local(2022, 2, 1)
date_validator.validate_startdate(record) date_validator.validate_startdate(record)
expect(record.errors["startdate"]) expect(record.errors["startdate"])
.to include(match I18n.t("validations.setup.startdate.after_void_date")) .to include(match I18n.t("validations.lettings.date.startdate.after_void_date"))
end end
it "validates that the tenancy start date is after the major repair date if it has a major repair date" do it "validates that the tenancy start date is after the major repair date if it has a major repair date" do
@ -34,7 +34,7 @@ RSpec.describe Validations::DateValidations do
record.mrcdate = Time.zone.local(2022, 2, 1) record.mrcdate = Time.zone.local(2022, 2, 1)
date_validator.validate_startdate(record) date_validator.validate_startdate(record)
expect(record.errors["startdate"]) expect(record.errors["startdate"])
.to include(match I18n.t("validations.setup.startdate.after_major_repair_date")) .to include(match I18n.t("validations.lettings.date.startdate.after_major_repair_date"))
end end
it "produces no error when the tenancy start date is before the end date of the chosen scheme if it has an end date" do it "produces no error when the tenancy start date is before the end date of the chosen scheme if it has an end date" do
@ -58,7 +58,7 @@ RSpec.describe Validations::DateValidations do
record.mrcdate = Time.zone.local(2022, 2, 1) record.mrcdate = Time.zone.local(2022, 2, 1)
date_validator.validate_property_major_repairs(record) date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"]) expect(record.errors["mrcdate"])
.to include(match I18n.t("validations.property.mrcdate.before_tenancy_start")) .to include(match I18n.t("validations.lettings.date.mrcdate.before_tenancy_start"))
end end
it "must be before the tenancy start date" do it "must be before the tenancy start date" do
@ -74,9 +74,9 @@ RSpec.describe Validations::DateValidations do
date_validator.validate_property_major_repairs(record) date_validator.validate_property_major_repairs(record)
date_validator.validate_startdate(record) date_validator.validate_startdate(record)
expect(record.errors["mrcdate"]) expect(record.errors["mrcdate"])
.to include(match I18n.t("validations.property.mrcdate.ten_years_before_tenancy_start")) .to include(match I18n.t("validations.lettings.date.mrcdate.ten_years_before_tenancy_start"))
expect(record.errors["startdate"]) expect(record.errors["startdate"])
.to include(match I18n.t("validations.setup.startdate.ten_years_after_mrc_date")) .to include(match I18n.t("validations.lettings.date.startdate.ten_years_after_mrc_date"))
end end
it "must be within 10 years of the tenancy start date" do it "must be within 10 years of the tenancy start date" do
@ -93,7 +93,7 @@ RSpec.describe Validations::DateValidations do
record.mrcdate = Time.zone.local(2022, 1, 1) record.mrcdate = Time.zone.local(2022, 1, 1)
date_validator.validate_property_major_repairs(record) date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"]) expect(record.errors["mrcdate"])
.to include(match I18n.t("validations.property.mrcdate.not_first_let")) .to include(match I18n.t("validations.lettings.date.mrcdate.not_first_let"))
end end
it "validates that no major repair date is provided for a conversion" do it "validates that no major repair date is provided for a conversion" do
@ -101,7 +101,7 @@ RSpec.describe Validations::DateValidations do
record.mrcdate = Time.zone.local(2022, 1, 1) record.mrcdate = Time.zone.local(2022, 1, 1)
date_validator.validate_property_major_repairs(record) date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"]) expect(record.errors["mrcdate"])
.to include(match I18n.t("validations.property.mrcdate.not_first_let")) .to include(match I18n.t("validations.lettings.date.mrcdate.not_first_let"))
end end
it "validates that no major repair date is provided for a leased property" do it "validates that no major repair date is provided for a leased property" do
@ -109,7 +109,7 @@ RSpec.describe Validations::DateValidations do
record.mrcdate = Time.zone.local(2022, 1, 1) record.mrcdate = Time.zone.local(2022, 1, 1)
date_validator.validate_property_major_repairs(record) date_validator.validate_property_major_repairs(record)
expect(record.errors["mrcdate"]) expect(record.errors["mrcdate"])
.to include(match I18n.t("validations.property.mrcdate.not_first_let")) .to include(match I18n.t("validations.lettings.date.mrcdate.not_first_let"))
end end
end end
@ -129,7 +129,7 @@ RSpec.describe Validations::DateValidations do
record.voiddate = Time.zone.local(2022, 2, 1) record.voiddate = Time.zone.local(2022, 2, 1)
date_validator.validate_property_void_date(record) date_validator.validate_property_void_date(record)
expect(record.errors["voiddate"]) expect(record.errors["voiddate"])
.to include(match I18n.t("validations.property.void_date.before_tenancy_start")) .to include(match I18n.t("validations.lettings.date.void_date.before_tenancy_start"))
end end
it "must be before the tenancy start date" do it "must be before the tenancy start date" do
@ -145,9 +145,9 @@ RSpec.describe Validations::DateValidations do
date_validator.validate_property_void_date(record) date_validator.validate_property_void_date(record)
date_validator.validate_startdate(record) date_validator.validate_startdate(record)
expect(record.errors["voiddate"]) expect(record.errors["voiddate"])
.to include(match I18n.t("validations.property.void_date.ten_years_before_tenancy_start")) .to include(match I18n.t("validations.lettings.date.void_date.ten_years_before_tenancy_start"))
expect(record.errors["startdate"]) expect(record.errors["startdate"])
.to include(match I18n.t("validations.setup.startdate.ten_years_after_void_date")) .to include(match I18n.t("validations.lettings.date.startdate.ten_years_after_void_date"))
end end
it "must be within 10 years of the tenancy start date" do it "must be within 10 years of the tenancy start date" do
@ -164,9 +164,9 @@ RSpec.describe Validations::DateValidations do
record.voiddate = Time.zone.local(2022, 2, 1) record.voiddate = Time.zone.local(2022, 2, 1)
date_validator.validate_property_void_date(record) date_validator.validate_property_void_date(record)
expect(record.errors["voiddate"]) expect(record.errors["voiddate"])
.to include(match I18n.t("validations.property.void_date.after_mrcdate")) .to include(match I18n.t("validations.lettings.date.void_date.after_mrcdate"))
expect(record.errors["mrcdate"]) expect(record.errors["mrcdate"])
.to include(match I18n.t("validations.property.mrcdate.before_void_date")) .to include(match I18n.t("validations.lettings.date.mrcdate.before_void_date"))
end end
it "must be before major repairs date" do it "must be before major repairs date" do

Loading…
Cancel
Save