Browse Source

Cldc 1675 rent validations (#946)

* feat: add 2022 rent range data, update rake task for population of this

* feat: change file format so ranges_rent_id is recognised

* feat: add updated error messages and casing

* tests: make tests pass
pull/955/head v0.2.14
natdeanlewissoftwire 2 years ago committed by GitHub
parent
commit
b83c6c0b27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      app/helpers/interruption_screen_helper.rb
  2. 21
      app/models/validations/financial_validations.rb
  3. 22
      config/locales/en.yml
  4. 7726
      config/rent_range_data/2022.csv
  5. 1
      db/seeds.rb
  6. 2
      lib/tasks/rent_ranges.rake
  7. 22
      spec/models/validations/financial_validations_spec.rb

7
app/helpers/interruption_screen_helper.rb

@ -5,7 +5,12 @@ module InterruptionScreenHelper
translation_params = {}
informative_text["arguments"].each do |argument|
value = if argument["label"]
lettings_log.form.get_question(argument["key"], lettings_log).answer_label(lettings_log).downcase
pre_casing_value = lettings_log.form.get_question(argument["key"], lettings_log).answer_label(lettings_log)
if argument["key"] == "la"
pre_casing_value
else
pre_casing_value.downcase
end
else
lettings_log.public_send(argument["key"])
end

21
app/models/validations/financial_validations.rb

@ -184,12 +184,21 @@ private
rent_range = LaRentRange.find_by(start_year: collection_year, la: record.la, beds: record.beds, lettype: record.lettype)
if rent_range.present? && !weekly_value_in_range(record, "brent", rent_range.hard_min, rent_range.hard_max) && record.brent.present? && record.period.present?
record.errors.add :brent, I18n.t("validations.financial.brent.not_in_range")
record.errors.add :beds, I18n.t("validations.financial.brent.beds.not_in_range")
record.errors.add :la, I18n.t("validations.financial.brent.la.not_in_range")
record.errors.add :rent_type, I18n.t("validations.financial.brent.rent_type.not_in_range")
record.errors.add :needstype, I18n.t("validations.financial.brent.needstype.not_in_range")
record.errors.add :period, I18n.t("validations.financial.brent.period.not_in_range")
if record.weekly_value(record["brent"]) < rent_range.hard_min
record.errors.add :brent, I18n.t("validations.financial.brent.below_hard_min")
record.errors.add :beds, I18n.t("validations.financial.brent.beds.below_hard_min")
record.errors.add :la, I18n.t("validations.financial.brent.la.below_hard_min")
record.errors.add :rent_type, I18n.t("validations.financial.brent.rent_type.below_hard_min")
record.errors.add :needstype, I18n.t("validations.financial.brent.needstype.below_hard_min")
record.errors.add :period, I18n.t("validations.financial.brent.period.below_hard_min")
else
record.errors.add :brent, I18n.t("validations.financial.brent.above_hard_max")
record.errors.add :beds, I18n.t("validations.financial.brent.beds.above_hard_max")
record.errors.add :la, I18n.t("validations.financial.brent.la.above_hard_max")
record.errors.add :rent_type, I18n.t("validations.financial.brent.rent_type.above_hard_max")
record.errors.add :needstype, I18n.t("validations.financial.brent.needstype.above_hard_max")
record.errors.add :period, I18n.t("validations.financial.brent.period.above_hard_max")
end
end
end
end

22
config/locales/en.yml

@ -188,17 +188,23 @@ en:
general_needs: "Enter a value for the support charge between £0 and £60 per week if the landlord is a local authority and it is a general needs letting"
supported_housing: "Enter a value for the support charge between £0 and £120 per week if the landlord is a local authority and it is a supported housing letting"
brent:
not_in_range: "Basic rent is outside of the expected range based on the lettings type, local authority and number of bedrooms"
below_hard_min: "Rent is below the absolute minimum expected for a property of this type. Please check the rent, rent period, local authority and (if general needs) number of bedrooms"
above_hard_max: "Rent is higher than the absolute maximum expected for a property of this type. Please check the rent, rent period, local authority and (if general needs) number of bedrooms"
la:
not_in_range: "Basic rent is outside of the expected range based on this local authority"
below_hard_min: "Rent is below the absolute minimum expected for a property of this type based on this local authority"
above_hard_max: "Rent is higher than the absolute maximum expected for a property of this type based on this local authority"
beds:
not_in_range: "Basic rent is outside of the expected range based on this number of bedrooms"
below_hard_min: "Rent is below the absolute minimum expected for a property of this type based on this number of bedrooms"
above_hard_max: "Rent is higher than the absolute maximum expected for a property of this type based on this number of bedrooms"
needstype:
not_in_range: "Basic rent is outside of the expected range based on this lettings type"
below_hard_min: "Rent is below the absolute minimum expected for a property of this type based on this lettings type"
above_hard_max: "Rent is higher than the absolute maximum expected for a property of this type based on this lettings type"
rent_type:
not_in_range: "Basic rent is outside of the expected range based on this lettings type"
below_hard_min: "Rent is below the absolute minimum expected for a property of this type based on this lettings type"
above_hard_max: "Rent is higher than the absolute maximum expected for a property of this type based on this lettings type"
period:
not_in_range: "Basic rent is outside of the expected range based on this period"
below_hard_min: "Rent is below the absolute minimum expected for a property of this type based on this period"
above_hard_max: "Rent is higher than the absolute maximum expected for a property of this type based on this period"
charges:
complete_1_of_3: "Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’"
tcharge:
@ -307,10 +313,10 @@ en:
rent:
min:
title_text: "You told us the rent is %{brent}"
hint_text: "The minimum rent for this type of property in %{la} is £%{soft_min_for_period}."
hint_text: "The minimum rent expected for this type of property in %{la} is £%{soft_min_for_period}."
max:
title_text: "You told us the rent is %{brent}"
hint_text: "The maximum rent for this type of property in %{la} is £%{soft_max_for_period}."
hint_text: "The maximum rent expected for this type of property in %{la} is £%{soft_max_for_period}."
retirement:
min:
title: "You told us this person is under %{age} and retired"

7726
config/rent_range_data/2022.csv

File diff suppressed because it is too large Load Diff

1
db/seeds.rb

@ -189,6 +189,7 @@ unless Rails.env.test?
Dir.glob("config/rent_range_data/*.csv").each do |path|
start_year = File.basename(path, ".csv")
Rake::Task["data_import:rent_ranges"].invoke(start_year, path)
Rake::Task["data_import:rent_ranges"].reenable
end
end
end

2
lib/tasks/rent_ranges.rake

@ -24,6 +24,6 @@ namespace :data_import do
)
count += 1
end
pp "Created/updated #{count} LA Rent Range records" unless Rails.env.test?
pp "Created/updated #{count} LA Rent Range records for #{start_year}" unless Rails.env.test?
end
end

22
spec/models/validations/financial_validations_spec.rb

@ -800,7 +800,7 @@ RSpec.describe Validations::FinancialValidations do
financial_validator.validate_rent_amount(record)
expect(record.errors["brent"])
.to include(match I18n.t("validations.financial.brent.not_in_range"))
.to include(match I18n.t("validations.financial.brent.below_hard_min"))
end
it "validates hard max" do
@ -813,15 +813,15 @@ RSpec.describe Validations::FinancialValidations do
financial_validator.validate_rent_amount(record)
expect(record.errors["brent"])
.to include(match I18n.t("validations.financial.brent.not_in_range"))
.to include(match I18n.t("validations.financial.brent.above_hard_max"))
expect(record.errors["beds"])
.to include(match I18n.t("validations.financial.brent.beds.not_in_range"))
.to include(match I18n.t("validations.financial.brent.beds.above_hard_max"))
expect(record.errors["la"])
.to include(match I18n.t("validations.financial.brent.la.not_in_range"))
.to include(match I18n.t("validations.financial.brent.la.above_hard_max"))
expect(record.errors["rent_type"])
.to include(match I18n.t("validations.financial.brent.rent_type.not_in_range"))
.to include(match I18n.t("validations.financial.brent.rent_type.above_hard_max"))
expect(record.errors["needstype"])
.to include(match I18n.t("validations.financial.brent.needstype.not_in_range"))
.to include(match I18n.t("validations.financial.brent.needstype.above_hard_max"))
end
it "validates hard max for correct collection year" do
@ -834,15 +834,15 @@ RSpec.describe Validations::FinancialValidations do
financial_validator.validate_rent_amount(record)
expect(record.errors["brent"])
.to include(match I18n.t("validations.financial.brent.not_in_range"))
.to include(match I18n.t("validations.financial.brent.above_hard_max"))
expect(record.errors["beds"])
.to include(match I18n.t("validations.financial.brent.beds.not_in_range"))
.to include(match I18n.t("validations.financial.brent.beds.above_hard_max"))
expect(record.errors["la"])
.to include(match I18n.t("validations.financial.brent.la.not_in_range"))
.to include(match I18n.t("validations.financial.brent.la.above_hard_max"))
expect(record.errors["rent_type"])
.to include(match I18n.t("validations.financial.brent.rent_type.not_in_range"))
.to include(match I18n.t("validations.financial.brent.rent_type.above_hard_max"))
expect(record.errors["needstype"])
.to include(match I18n.t("validations.financial.brent.needstype.not_in_range"))
.to include(match I18n.t("validations.financial.brent.needstype.above_hard_max"))
end
it "does not error if some of the fields are missing" do

Loading…
Cancel
Save