Browse Source

Increase soft maximum for carehome charges

pull/1651/head
Kat 3 years ago
parent
commit
9c928f2e69
  1. 4
      app/models/validations/financial_validations.rb
  2. 40
      spec/models/validations/financial_validations_spec.rb

4
app/models/validations/financial_validations.rb

@ -133,8 +133,8 @@ module Validations::FinancialValidations
if record.chcharge.blank?
# record.errors.add :is_carehome, I18n.t("validations.financial.carehome.not_provided", period:)
# record.errors.add :chcharge, I18n.t("validations.financial.carehome.not_provided", period:)
elsif !weekly_value_in_range(record, "chcharge", 10, 1000)
max_chcharge = record.weekly_to_value_per_period(1000)
elsif !weekly_value_in_range(record, "chcharge", 10, 5000)
max_chcharge = record.weekly_to_value_per_period(5000)
min_chcharge = record.weekly_to_value_per_period(10)
message = I18n.t("validations.financial.carehome.out_of_range", period:, min_chcharge:, max_chcharge:)

40
spec/models/validations/financial_validations_spec.rb

@ -916,42 +916,42 @@ RSpec.describe Validations::FinancialValidations do
context "and charges are over the valid limit (£1,000 per week)" do
it "validates charge when period is weekly for 52 weeks" do
record.period = 1
record.chcharge = 1001
record.chcharge = 5001
financial_validator.validate_care_home_charges(record)
expect(record.errors["chcharge"])
.to include("Household rent and other charges must be between £10.00 and £1,000.00 if paying weekly for 52 weeks")
.to include("Household rent and other charges must be between £10.00 and £5,000.00 if paying weekly for 52 weeks")
expect(record.errors["period"])
.to include("Household rent and other charges must be between £10.00 and £1,000.00 if paying weekly for 52 weeks")
.to include("Household rent and other charges must be between £10.00 and £5,000.00 if paying weekly for 52 weeks")
end
it "validates charge when period is monthly" do
record.period = 4
record.chcharge = 4334
record.chcharge = 21_667
financial_validator.validate_care_home_charges(record)
expect(record.errors["chcharge"])
.to include("Household rent and other charges must be between £43.00 and £4,333.00 if paying every calendar month")
.to include("Household rent and other charges must be between £43.00 and £21,666.00 if paying every calendar month")
expect(record.errors["period"])
.to include("Household rent and other charges must be between £43.00 and £4,333.00 if paying every calendar month")
.to include("Household rent and other charges must be between £43.00 and £21,666.00 if paying every calendar month")
end
it "validates charge when period is every 2 weeks" do
record.period = 2
record.chcharge = 2001
record.chcharge = 12_001
financial_validator.validate_care_home_charges(record)
expect(record.errors["chcharge"])
.to include("Household rent and other charges must be between £20.00 and £2,000.00 if paying every 2 weeks")
.to include("Household rent and other charges must be between £20.00 and £10,000.00 if paying every 2 weeks")
expect(record.errors["period"])
.to include("Household rent and other charges must be between £20.00 and £2,000.00 if paying every 2 weeks")
.to include("Household rent and other charges must be between £20.00 and £10,000.00 if paying every 2 weeks")
end
it "validates charge when period is every 4 weeks" do
record.period = 3
record.chcharge = 4001
record.chcharge = 24_001
financial_validator.validate_care_home_charges(record)
expect(record.errors["chcharge"])
.to include("Household rent and other charges must be between £40.00 and £4,000.00 if paying every 4 weeks")
.to include("Household rent and other charges must be between £40.00 and £20,000.00 if paying every 4 weeks")
expect(record.errors["period"])
.to include("Household rent and other charges must be between £40.00 and £4,000.00 if paying every 4 weeks")
.to include("Household rent and other charges must be between £40.00 and £20,000.00 if paying every 4 weeks")
end
end
@ -1007,9 +1007,9 @@ RSpec.describe Validations::FinancialValidations do
record.chcharge = 9
financial_validator.validate_care_home_charges(record)
expect(record.errors["chcharge"])
.to include("Household rent and other charges must be between £10.00 and £1,000.00 if paying weekly for 52 weeks")
.to include("Household rent and other charges must be between £10.00 and £5,000.00 if paying weekly for 52 weeks")
expect(record.errors["period"])
.to include("Household rent and other charges must be between £10.00 and £1,000.00 if paying weekly for 52 weeks")
.to include("Household rent and other charges must be between £10.00 and £5,000.00 if paying weekly for 52 weeks")
end
it "validates charge when period is monthly" do
@ -1017,9 +1017,9 @@ RSpec.describe Validations::FinancialValidations do
record.chcharge = 42
financial_validator.validate_care_home_charges(record)
expect(record.errors["chcharge"])
.to include("Household rent and other charges must be between £43.00 and £4,333.00 if paying every calendar month")
.to include("Household rent and other charges must be between £43.00 and £21,666.00 if paying every calendar month")
expect(record.errors["period"])
.to include("Household rent and other charges must be between £43.00 and £4,333.00 if paying every calendar month")
.to include("Household rent and other charges must be between £43.00 and £21,666.00 if paying every calendar month")
end
it "validates charge when period is every 2 weeks" do
@ -1027,9 +1027,9 @@ RSpec.describe Validations::FinancialValidations do
record.chcharge = 19
financial_validator.validate_care_home_charges(record)
expect(record.errors["chcharge"])
.to include("Household rent and other charges must be between £20.00 and £2,000.00 if paying every 2 weeks")
.to include("Household rent and other charges must be between £20.00 and £10,000.00 if paying every 2 weeks")
expect(record.errors["period"])
.to include("Household rent and other charges must be between £20.00 and £2,000.00 if paying every 2 weeks")
.to include("Household rent and other charges must be between £20.00 and £10,000.00 if paying every 2 weeks")
end
it "validates charge when period is every 4 weeks" do
@ -1037,9 +1037,9 @@ RSpec.describe Validations::FinancialValidations do
record.chcharge = 39
financial_validator.validate_care_home_charges(record)
expect(record.errors["chcharge"])
.to include("Household rent and other charges must be between £40.00 and £4,000.00 if paying every 4 weeks")
.to include("Household rent and other charges must be between £40.00 and £20,000.00 if paying every 4 weeks")
expect(record.errors["period"])
.to include("Household rent and other charges must be between £40.00 and £4,000.00 if paying every 4 weeks")
.to include("Household rent and other charges must be between £40.00 and £20,000.00 if paying every 4 weeks")
end
end
end

Loading…
Cancel
Save