Browse Source

CLDC-2805 Updates charge hard validation error messages (#1995)

* feat: make error message dynamic

* recator: lint

* feat: update tests

* feat: update tests

* refactor: lint

* feat: simplify method call in validations

* Update error message

---------

Co-authored-by: Kat <katrina@kosiak.co.uk>
demo-branch
natdeanlewissoftwire 1 year ago committed by GitHub
parent
commit
5e9f01db7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      app/models/validations/financial_validations.rb
  2. 22
      config/locales/en.yml
  3. 182
      spec/models/validations/financial_validations_spec.rb

20
app/models/validations/financial_validations.rb

@ -146,7 +146,7 @@ module Validations::FinancialValidations
private private
CHARGE_MAXIMUMS = { CHARGE_MAXIMA_PER_WEEK = {
scharge: { scharge: {
private_registered_provider: { private_registered_provider: {
general_needs: 800, general_needs: 800,
@ -181,22 +181,30 @@ private
PROVIDER_TYPE = { 1 => :local_authority, 2 => :private_registered_provider }.freeze PROVIDER_TYPE = { 1 => :local_authority, 2 => :private_registered_provider }.freeze
NEEDSTYPE_VALUES = { 2 => :supported_housing, 1 => :general_needs }.freeze NEEDSTYPE_VALUES = { 2 => :supported_housing, 1 => :general_needs }.freeze
CHARGE_NAMES = { scharge: "service charge", pscharge: "personal service charge", supcharg: "support charge" }.freeze
def validate_charges(record) def validate_charges(record)
return unless record.owning_organisation return unless record.owning_organisation
provider_type = record.owning_organisation.provider_type_before_type_cast provider_type = record.owning_organisation.provider_type_before_type_cast
%i[scharge pscharge supcharg].each do |charge| %i[scharge pscharge supcharg].each do |charge|
maximum = CHARGE_MAXIMUMS.dig(charge, PROVIDER_TYPE[provider_type], NEEDSTYPE_VALUES[record.needstype]) maximum_per_week = CHARGE_MAXIMA_PER_WEEK.dig(charge, PROVIDER_TYPE[provider_type], NEEDSTYPE_VALUES[record.needstype])
if maximum.present? && record[:period].present? && record[charge].present? && !weekly_value_in_range(record, charge, 0.0, maximum) next unless maximum_per_week.present? && record[:period].present? && record[charge].present? && !weekly_value_in_range(record, charge, 0.0, maximum_per_week)
record.errors.add charge, :outside_the_range, message: I18n.t("validations.financial.rent.#{charge}.#{PROVIDER_TYPE[provider_type]}.#{NEEDSTYPE_VALUES[record.needstype]}")
end charge_name = CHARGE_NAMES[charge]
frequency = record.form.get_question("period", record).label_from_value(record.period).downcase
letting_type = NEEDSTYPE_VALUES[record.needstype].to_s.humanize(capitalize: false)
provider_type_label = PROVIDER_TYPE[provider_type].to_s.humanize(capitalize: false)
maximum_per_period = record.weekly_to_value_per_period(maximum_per_week)
record.errors.add charge, :outside_the_range, message: I18n.t("validations.financial.rent.out_of_range", charge_name:, maximum_per_period:, frequency:, letting_type:, provider_type: provider_type_label)
record.errors.add :period, :outside_the_range, message: I18n.t("validations.financial.rent.out_of_range", charge_name:, maximum_per_period:, frequency:, letting_type:, provider_type: provider_type_label)
end end
end end
def weekly_value_in_range(record, field, min, max) def weekly_value_in_range(record, field, min, max)
record[field].present? && record.weekly_value(record[field]).present? && record.weekly_value(record[field]).between?(min, max) record.weekly_value(record[field])&.between?(min, max)
end end
def validate_rent_range(record) def validate_rent_range(record)

22
config/locales/en.yml

@ -367,27 +367,7 @@ en:
negative_currency: "Enter an amount above 0" negative_currency: "Enter an amount above 0"
rent: rent:
less_than_shortfall: "Enter an amount that is more than the shortfall in basic rent" less_than_shortfall: "Enter an amount that is more than the shortfall in basic rent"
scharge: 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}."
private_registered_provider:
general_needs: "Enter a value for the service charge between £0 and £800 per week if the landlord is a private registered provider and it is a general needs letting"
supported_housing: "Enter a value for the service charge between £0 and £800 per week if the landlord is a private registered provider and it is a supported housing letting"
local_authority:
general_needs: "Enter a value for the service charge between £0 and £500 per week if the landlord is a local authority and it is a general needs letting"
supported_housing: "Enter a value for the service charge between £0 and £500 per week if the landlord is a local authority and it is a supported housing letting"
pscharge:
private_registered_provider:
general_needs: "Enter a value for the personal service charge between £0 and £700 per week if the landlord is a private registered provider and it is a general needs letting"
supported_housing: "Enter a value for the personal service charge between £0 and £700 per week if the landlord is a private registered provider and it is a supported housing letting"
local_authority:
general_needs: "Enter a value for the personal service charge between £0 and £200 per week if the landlord is a local authority and it is a general needs letting"
supported_housing: "Enter a value for the personal service charge between £0 and £200 per week if the landlord is a local authority and it is a supported housing letting"
supcharg:
private_registered_provider:
general_needs: "Enter a value for the support charge between £0 and £800 per week if the landlord is a private registered provider and it is a general needs letting"
supported_housing: "Enter a value for the support charge between £0 and £800 per week if the landlord is a private registered provider and it is a supported housing letting"
local_authority:
general_needs: "Enter a value for the support charge between £0 and £200 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 £200 per week if the landlord is a local authority and it is a supported housing letting"
ecstat: ecstat:
over_hard_max: "Net income of %{hard_max} per week is too high given the tenant’s working situation" over_hard_max: "Net income of %{hard_max} per week is too high given the tenant’s working situation"
brent: brent:

182
spec/models/validations/financial_validations_spec.rb

@ -262,56 +262,74 @@ RSpec.describe Validations::FinancialValidations do
before { record.needstype = 1 } before { record.needstype = 1 }
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "scharge", value: 801 }, charge: { field: "scharge", value: 801 },
charge_name: "service charge",
maximum_per_period: "£800.00",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "scharge", value: 3471 }, charge: { field: "scharge", value: 3471 },
charge_name: "service charge",
maximum_per_period: "£3,466.00",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
charge: { field: "scharge", value: 1601 }, charge: { field: "scharge", value: 1601 },
charge_name: "service charge",
maximum_per_period: "£1,600.00",
}, },
{ {
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "pscharge", value: 701 }, charge: { field: "pscharge", value: 701 },
charge_name: "personal service charge",
maximum_per_period: "£700.00",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "pscharge", value: 3200 }, charge: { field: "pscharge", value: 3200 },
charge_name: "personal service charge",
maximum_per_period: "£3,033.00",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
charge: { field: "pscharge", value: 1401 }, charge: { field: "pscharge", value: 1401 },
charge_name: "personal service charge",
maximum_per_period: "£1,400.00",
}, },
{ {
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "supcharg", value: 801 }, charge: { field: "supcharg", value: 801 },
charge_name: "support charge",
maximum_per_period: "£800.00",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "supcharg", value: 3471 }, charge: { field: "supcharg", value: 3471 },
charge_name: "support charge",
maximum_per_period: "£3,466.00",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
charge: { field: "supcharg", value: 1601 }, charge: { field: "supcharg", value: 1601 },
charge_name: "support charge",
maximum_per_period: "£1,600.00",
}].each do |test_case| }].each do |test_case|
it "does not allow charges outside the range when period is #{test_case[:period][:label]}" do it "does not allow charges outside the range when period is #{test_case[:period][:label]}" do
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
record[test_case[:charge][:field]] = test_case[:charge][:value] record[test_case[:charge][:field]] = test_case[:charge][:value]
financial_validator.validate_rent_amount(record) financial_validator.validate_rent_amount(record)
expect(record.errors[test_case[:charge][:field]]) expect(record.errors[test_case[:charge][:field]])
.to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.private_registered_provider.general_needs")) .to include(match I18n.t("validations.financial.rent.out_of_range", charge_name: test_case[:charge_name], maximum_per_period: test_case[:maximum_per_period], frequency: test_case[:period][:label], letting_type: "general needs", provider_type: "private registered provider"))
end end
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "scharge", value: 799 }, charge: { field: "scharge", value: 799 },
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "scharge", value: 3400 }, charge: { field: "scharge", value: 3400 },
}, },
{ {
@ -319,11 +337,11 @@ RSpec.describe Validations::FinancialValidations do
charge: { field: "scharge", value: 1599 }, charge: { field: "scharge", value: 1599 },
}, },
{ {
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "pscharge", value: 699 }, charge: { field: "pscharge", value: 699 },
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "pscharge", value: 2500 }, charge: { field: "pscharge", value: 2500 },
}, },
{ {
@ -331,11 +349,11 @@ RSpec.describe Validations::FinancialValidations do
charge: { field: "pscharge", value: 1399 }, charge: { field: "pscharge", value: 1399 },
}, },
{ {
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "supcharg", value: 799 }, charge: { field: "supcharg", value: 799 },
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "supcharg", value: 3000 }, charge: { field: "supcharg", value: 3000 },
}, },
{ {
@ -356,56 +374,74 @@ RSpec.describe Validations::FinancialValidations do
before { record.needstype = 2 } before { record.needstype = 2 }
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "scharge", value: 801 }, charge: { field: "scharge", value: 801 },
charge_name: "service charge",
maximum_per_period: "£800.00",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "scharge", value: 3471 }, charge: { field: "scharge", value: 3471 },
charge_name: "service charge",
maximum_per_period: "£3,466.00",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
charge: { field: "scharge", value: 1601 }, charge: { field: "scharge", value: 1601 },
charge_name: "service charge",
maximum_per_period: "£1,600.00",
}, },
{ {
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "pscharge", value: 701 }, charge: { field: "pscharge", value: 701 },
charge_name: "personal service charge",
maximum_per_period: "£700.00",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "pscharge", value: 3200 }, charge: { field: "pscharge", value: 3200 },
charge_name: "personal service charge",
maximum_per_period: "£3,033.00",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
charge: { field: "pscharge", value: 1401 }, charge: { field: "pscharge", value: 1401 },
charge_name: "personal service charge",
maximum_per_period: "£1,400.00",
}, },
{ {
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "supcharg", value: 801 }, charge: { field: "supcharg", value: 801 },
charge_name: "support charge",
maximum_per_period: "£800.00",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "supcharg", value: 3471 }, charge: { field: "supcharg", value: 3471 },
charge_name: "support charge",
maximum_per_period: "£3,466.00",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
charge: { field: "supcharg", value: 1601 }, charge: { field: "supcharg", value: 1601 },
charge_name: "support charge",
maximum_per_period: "£1,600.00",
}].each do |test_case| }].each do |test_case|
it "does not allow charges outside the range when period is #{test_case[:period][:label]}" do it "does not allow charges outside the range when period is #{test_case[:period][:label]}" do
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
record[test_case[:charge][:field]] = test_case[:charge][:value] record[test_case[:charge][:field]] = test_case[:charge][:value]
financial_validator.validate_rent_amount(record) financial_validator.validate_rent_amount(record)
expect(record.errors[test_case[:charge][:field]]) expect(record.errors[test_case[:charge][:field]])
.to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.private_registered_provider.supported_housing")) .to include(match I18n.t("validations.financial.rent.out_of_range", charge_name: test_case[:charge_name], maximum_per_period: test_case[:maximum_per_period], frequency: test_case[:period][:label], letting_type: "supported housing", provider_type: "private registered provider"))
end end
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "scharge", value: 799 }, charge: { field: "scharge", value: 799 },
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "scharge", value: 3400 }, charge: { field: "scharge", value: 3400 },
}, },
{ {
@ -413,11 +449,11 @@ RSpec.describe Validations::FinancialValidations do
charge: { field: "scharge", value: 1599 }, charge: { field: "scharge", value: 1599 },
}, },
{ {
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "pscharge", value: 699 }, charge: { field: "pscharge", value: 699 },
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "pscharge", value: 2500 }, charge: { field: "pscharge", value: 2500 },
}, },
{ {
@ -425,11 +461,11 @@ RSpec.describe Validations::FinancialValidations do
charge: { field: "pscharge", value: 1399 }, charge: { field: "pscharge", value: 1399 },
}, },
{ {
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "supcharg", value: 799 }, charge: { field: "supcharg", value: 799 },
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "supcharg", value: 3400 }, charge: { field: "supcharg", value: 3400 },
}, },
{ {
@ -454,56 +490,74 @@ RSpec.describe Validations::FinancialValidations do
before { record.needstype = 1 } before { record.needstype = 1 }
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "scharge", value: 501 }, charge: { field: "scharge", value: 501 },
charge_name: "service charge",
maximum_per_period: "£500.00",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "scharge", value: 2300 }, charge: { field: "scharge", value: 2300 },
charge_name: "service charge",
maximum_per_period: "£2,166.00",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
charge: { field: "scharge", value: 1001 }, charge: { field: "scharge", value: 1001 },
charge_name: "service charge",
maximum_per_period: "£1,000.00",
}, },
{ {
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "pscharge", value: 201 }, charge: { field: "pscharge", value: 201 },
charge_name: "personal service charge",
maximum_per_period: "£200.00",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "pscharge", value: 1000 }, charge: { field: "pscharge", value: 1000 },
charge_name: "personal service charge",
maximum_per_period: "£866.00",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
charge: { field: "pscharge", value: 401 }, charge: { field: "pscharge", value: 401 },
charge_name: "personal service charge",
maximum_per_period: "£400.00",
}, },
{ {
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "supcharg", value: 201 }, charge: { field: "supcharg", value: 201 },
charge_name: "support charge",
maximum_per_period: "£200.00",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "supcharg", value: 1000 }, charge: { field: "supcharg", value: 1000 },
charge_name: "support charge",
maximum_per_period: "£866.00",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
charge: { field: "supcharg", value: 401 }, charge: { field: "supcharg", value: 401 },
charge_name: "support charge",
maximum_per_period: "£400.00",
}].each do |test_case| }].each do |test_case|
it "does not allow charges outside the range when period is #{test_case[:period][:label]}" do it "does not allow charges outside the range when period is #{test_case[:period][:label]}" do
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
record[test_case[:charge][:field]] = test_case[:charge][:value] record[test_case[:charge][:field]] = test_case[:charge][:value]
financial_validator.validate_rent_amount(record) financial_validator.validate_rent_amount(record)
expect(record.errors[test_case[:charge][:field]]) expect(record.errors[test_case[:charge][:field]])
.to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.local_authority.general_needs")) .to include(match I18n.t("validations.financial.rent.out_of_range", charge_name: test_case[:charge_name], maximum_per_period: test_case[:maximum_per_period], frequency: test_case[:period][:label], letting_type: "general needs", provider_type: "local authority"))
end end
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "scharge", value: 499 }, charge: { field: "scharge", value: 499 },
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "scharge", value: 2000 }, charge: { field: "scharge", value: 2000 },
}, },
{ {
@ -511,11 +565,11 @@ RSpec.describe Validations::FinancialValidations do
charge: { field: "scharge", value: 999 }, charge: { field: "scharge", value: 999 },
}, },
{ {
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "pscharge", value: 199 }, charge: { field: "pscharge", value: 199 },
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "pscharge", value: 800 }, charge: { field: "pscharge", value: 800 },
}, },
{ {
@ -523,11 +577,11 @@ RSpec.describe Validations::FinancialValidations do
charge: { field: "pscharge", value: 399 }, charge: { field: "pscharge", value: 399 },
}, },
{ {
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "supcharg", value: 199.99 }, charge: { field: "supcharg", value: 199.99 },
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "supcharg", value: 800 }, charge: { field: "supcharg", value: 800 },
}, },
{ {
@ -548,61 +602,79 @@ RSpec.describe Validations::FinancialValidations do
before { record.needstype = 2 } before { record.needstype = 2 }
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "scharge", value: 501 }, charge: { field: "scharge", value: 501 },
charge_name: "service charge",
maximum_per_period: "£500.00",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "scharge", value: 2300 }, charge: { field: "scharge", value: 2300 },
charge_name: "service charge",
maximum_per_period: "£2,166.00",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
charge: { field: "scharge", value: 1001 }, charge: { field: "scharge", value: 1001 },
charge_name: "service charge",
maximum_per_period: "£1,000.00",
}, },
{ {
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "pscharge", value: 201 }, charge: { field: "pscharge", value: 201 },
charge_name: "personal service charge",
maximum_per_period: "£200.00",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "pscharge", value: 1000 }, charge: { field: "pscharge", value: 1000 },
charge_name: "personal service charge",
maximum_per_period: "£866.00",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
charge: { field: "pscharge", value: 401 }, charge: { field: "pscharge", value: 401 },
charge_name: "personal service charge",
maximum_per_period: "£400.00",
}, },
{ {
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "supcharg", value: 201 }, charge: { field: "supcharg", value: 201 },
charge_name: "support charge",
maximum_per_period: "£200.00",
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "supcharg", value: 1000 }, charge: { field: "supcharg", value: 1000 },
charge_name: "support charge",
maximum_per_period: "£866.00",
}, },
{ {
period: { label: "every 2 weeks", value: 2 }, period: { label: "every 2 weeks", value: 2 },
charge: { field: "supcharg", value: 401 }, charge: { field: "supcharg", value: 401 },
charge_name: "support charge",
maximum_per_period: "£400.00",
}].each do |test_case| }].each do |test_case|
it "does not allow charges outside the range when period is #{test_case[:period][:label]}" do it "does not allow charges outside the range when period is #{test_case[:period][:label]}" do
record.period = test_case[:period][:value] record.period = test_case[:period][:value]
record[test_case[:charge][:field]] = test_case[:charge][:value] record[test_case[:charge][:field]] = test_case[:charge][:value]
financial_validator.validate_rent_amount(record) financial_validator.validate_rent_amount(record)
expect(record.errors[test_case[:charge][:field]]) expect(record.errors[test_case[:charge][:field]])
.to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.local_authority.supported_housing")) .to include(match I18n.t("validations.financial.rent.out_of_range", charge_name: test_case[:charge_name], maximum_per_period: test_case[:maximum_per_period], frequency: test_case[:period][:label], letting_type: "supported housing", provider_type: "local authority"))
end end
end end
context "when charges are not given" do context "when charges are not given" do
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "scharge", value: nil }, charge: { field: "scharge", value: nil },
}, },
{ {
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "pscharge", value: nil }, charge: { field: "pscharge", value: nil },
}, },
{ {
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "supcharg", value: nil }, charge: { field: "supcharg", value: nil },
}].each do |test_case| }].each do |test_case|
it "does not error" do it "does not error" do
@ -616,11 +688,11 @@ RSpec.describe Validations::FinancialValidations do
end end
[{ [{
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "scharge", value: 499 }, charge: { field: "scharge", value: 499 },
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "scharge", value: 2000 }, charge: { field: "scharge", value: 2000 },
}, },
{ {
@ -628,11 +700,11 @@ RSpec.describe Validations::FinancialValidations do
charge: { field: "scharge", value: 999 }, charge: { field: "scharge", value: 999 },
}, },
{ {
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "pscharge", value: 199 }, charge: { field: "pscharge", value: 199 },
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "pscharge", value: 800 }, charge: { field: "pscharge", value: 800 },
}, },
{ {
@ -640,11 +712,11 @@ RSpec.describe Validations::FinancialValidations do
charge: { field: "pscharge", value: 399 }, charge: { field: "pscharge", value: 399 },
}, },
{ {
period: { label: "weekly", value: 1 }, period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "supcharg", value: 199.99 }, charge: { field: "supcharg", value: 199.99 },
}, },
{ {
period: { label: "monthly", value: 4 }, period: { label: "every calendar month", value: 4 },
charge: { field: "supcharg", value: 800 }, charge: { field: "supcharg", value: 800 },
}, },
{ {

Loading…
Cancel
Save