Browse Source

CLDC-3110: Add hard validation error to age fields that cause child ecstat to be inferred

pull/2136/head
Rachael Booth 2 years ago
parent
commit
fab9c4c112
  1. 9
      app/models/validations/financial_validations.rb
  2. 2
      config/locales/en.yml
  3. 9
      spec/models/validations/financial_validations_spec.rb

9
app/models/validations/financial_validations.rb

@ -41,6 +41,15 @@ module Validations::FinancialValidations
message: I18n.t("validations.financial.ecstat.over_hard_max", earnings: format_as_currency(record.earnings), frequency:),
)
end
(2..8).each do |n|
next unless record["ecstat#{n}"] == 9
record.errors.add(
"age#{n}",
:over_hard_max,
message: I18n.t("validations.financial.ecstat.inferred_child.over_hard_max", earnings: format_as_currency(record.earnings), frequency:),
)
end
end
if record.weekly_net_income < record.applicable_income_range.hard_min

2
config/locales/en.yml

@ -377,6 +377,8 @@ en:
out_of_range: "Enter a value for the %{charge_name} between £0 and %{maximum_per_period} paid %{frequency}. %{maximum_per_period} is the max limit for rent and charges paid %{frequency} for %{letting_type} lettings owned by a %{provider_type}."
ecstat:
over_hard_max: "The household's income of %{earnings} %{frequency} is too high given the household’s working situation"
inferred_child:
over_hard_max: "The household's income of %{earnings} %{frequency} is too high given the household’s characteristics and working situation"
brent:
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"

9
spec/models/validations/financial_validations_spec.rb

@ -244,18 +244,23 @@ RSpec.describe Validations::FinancialValidations do
.to eq(["The household's income cannot be less than £150.00 per week given the household’s working situation"])
end
it "adds errors to all tenant ecstat fields when income is too high" do
it "adds errors to relevant fields for each tenant when income is too high" do
record.earnings = 5000
record.incfreq = 1
record.hhmemb = 3
record.ecstat1 = 1
record.ecstat2 = 2
record.age3 = 12
record.ecstat3 = 9
financial_validator.validate_net_income(record)
(1..8).each do |n|
(1..record.hhmemb).each do |n|
expect(record.errors["ecstat#{n}"])
.to eq(["The household's income of £5,000.00 weekly is too high given the household’s working situation"])
end
expect(record.errors["age1"]).to be_empty
expect(record.errors["age2"]).to be_empty
expect(record.errors["age3"])
.to eq(["The household's income of £5,000.00 weekly is too high given the household’s characteristics and working situation"])
end
end
end

Loading…
Cancel
Save