Browse Source

add supported housing scharge validation

pull/388/head
Kat 3 years ago
parent
commit
07d7caf058
  1. 9
      app/models/validations/financial_validations.rb
  2. 3
      config/locales/en.yml
  3. 170
      spec/models/validations/financial_validations_spec.rb

9
app/models/validations/financial_validations.rb

@ -65,9 +65,12 @@ module Validations::FinancialValidations
record.errors.add :tshortfall, I18n.t("validations.financial.tshortfall.more_than_rent") record.errors.add :tshortfall, I18n.t("validations.financial.tshortfall.more_than_rent")
end end
if record.scharge.present? && record.this_landlord? && record.weekly_value(record.scharge).present? && !record.weekly_value(record.scharge).between?(0, 55) if record.scharge.present? && record.this_landlord? && record.weekly_value(record.scharge).present?
record.errors.add :scharge, I18n.t("validations.financial.rent.scharge.this_landlord.general_needs") if !record.weekly_value(record.scharge).between?(0, 55) && record.is_general_needs?
record.errors.add :landlord, I18n.t("validations.organisation.landlord.invalid_scharge") record.errors.add :scharge, I18n.t("validations.financial.rent.scharge.this_landlord.general_needs")
elsif !record.weekly_value(record.scharge).between?(0, 280) && record.is_supported_housing?
record.errors.add :scharge, I18n.t("validations.financial.rent.scharge.this_landlord.supported_housing")
end
end end
end end
end end

3
config/locales/en.yml

@ -94,7 +94,8 @@ en:
less_than_double_shortfall: "Answer must be more than double the shortfall in basic rent" less_than_double_shortfall: "Answer must be more than double the shortfall in basic rent"
scharge: scharge:
this_landlord: this_landlord:
general_needs: "Service charge must be between 0 and 55 per week if the landlord is this landlord" general_needs: "Service charge must be between 0 and 55 per week if the landlord is this landlord and it is a general needs letting"
supported_housing: "Service charge must be between 0 and 280 per week if the landlord is this landlord and it is a suported housing letting"
household: household:
reasonpref: reasonpref:

170
spec/models/validations/financial_validations_spec.rb

@ -201,65 +201,129 @@ RSpec.describe Validations::FinancialValidations do
end end
end end
context "when the landlord is this landlord and needstype is general needs" do context "when the landlord is this landlord" do
it "does not allow the scharge to be outside of 0 and 55 range per week when period is weekly" do context "when needstype is general needs" do
record.needstype = 1 it "does not allow the scharge to be outside of 0 and 55 range per week when period is weekly" do
record.landlord = 1 record.needstype = 1
record.period = 1 record.landlord = 1
record.scharge = 56 record.period = 1
financial_validator.validate_rent_amount(record) record.scharge = 56
expect(record.errors["scharge"]) financial_validator.validate_rent_amount(record)
.to include(match I18n.t("validations.financial.rent.scharge.this_landlord.general_needs")) expect(record.errors["scharge"])
end .to include(match I18n.t("validations.financial.rent.scharge.this_landlord.general_needs"))
end
it "does allow the scharge to be between of 0 and 55 per week when period is weekly" do it "does allow the scharge to be between of 0 and 55 per week when period is weekly" do
record.needstype = 1 record.needstype = 1
record.landlord = 1 record.landlord = 1
record.period = 1 record.period = 1
record.scharge = 54 record.scharge = 54
financial_validator.validate_rent_amount(record) financial_validator.validate_rent_amount(record)
expect(record.errors["scharge"]) expect(record.errors["scharge"])
.to be_empty .to be_empty
end end
it "does not allow the scharge to be outside of 0 and 55 range per week when period is monthly" do it "does not allow the scharge to be outside of 0 and 55 range per week when period is monthly" do
record.needstype = 1 record.needstype = 1
record.landlord = 1 record.landlord = 1
record.period = 4 record.period = 4
record.scharge = 300 record.scharge = 300
financial_validator.validate_rent_amount(record) financial_validator.validate_rent_amount(record)
expect(record.errors["scharge"]) expect(record.errors["scharge"])
.to include(match I18n.t("validations.financial.rent.scharge.this_landlord.general_needs")) .to include(match I18n.t("validations.financial.rent.scharge.this_landlord.general_needs"))
end end
it "does allow the scharge to be between of 0 and 55 per week when period is monthly" do it "does allow the scharge to be between of 0 and 55 per week when period is monthly" do
record.needstype = 1 record.needstype = 1
record.landlord = 1 record.landlord = 1
record.period = 4 record.period = 4
record.scharge = 220 record.scharge = 220
financial_validator.validate_rent_amount(record) financial_validator.validate_rent_amount(record)
expect(record.errors["scharge"]) expect(record.errors["scharge"])
.to be_empty .to be_empty
end end
it "does not allow the scharge to be outside of 0 and 55 range per week when period is every 2 weeks" do it "does not allow the scharge to be outside of 0 and 55 range per week when period is every 2 weeks" do
record.needstype = 1 record.needstype = 1
record.landlord = 1 record.landlord = 1
record.period = 2 record.period = 2
record.scharge = 111 record.scharge = 111
financial_validator.validate_rent_amount(record) financial_validator.validate_rent_amount(record)
expect(record.errors["scharge"]) expect(record.errors["scharge"])
.to include(match I18n.t("validations.financial.rent.scharge.this_landlord.general_needs")) .to include(match I18n.t("validations.financial.rent.scharge.this_landlord.general_needs"))
end
it "does allow the scharge to be between of 0 and 55 per week when period is every 2 weeks" do
record.needstype = 1
record.landlord = 1
record.period = 2
record.scharge = 109
financial_validator.validate_rent_amount(record)
expect(record.errors["scharge"])
.to be_empty
end
end end
it "does allow the scharge to be between of 0 and 55 per week when period is every 2 weeks" do context "when needstype is supported housing" do
record.needstype = 1 it "does not allow the scharge to be outside of 0 and 280 range per week when period is weekly" do
record.landlord = 1 record.needstype = 0
record.period = 2 record.landlord = 1
record.scharge = 109 record.period = 1
financial_validator.validate_rent_amount(record) record.scharge = 281
expect(record.errors["scharge"]) financial_validator.validate_rent_amount(record)
.to be_empty expect(record.errors["scharge"])
.to include(match I18n.t("validations.financial.rent.scharge.this_landlord.supported_housing"))
end
it "does allow the scharge to be between of 0 and 280 per week when period is weekly" do
record.needstype = 0
record.landlord = 1
record.period = 1
record.scharge = 280
financial_validator.validate_rent_amount(record)
expect(record.errors["scharge"])
.to be_empty
end
it "does not allow the scharge to be outside of 0 and 280 range per week when period is monthly" do
record.needstype = 0
record.landlord = 1
record.period = 4
record.scharge = 1225
financial_validator.validate_rent_amount(record)
expect(record.errors["scharge"])
.to include(match I18n.t("validations.financial.rent.scharge.this_landlord.supported_housing"))
end
it "does allow the scharge to be between of 0 and 280 per week when period is monthly" do
record.needstype = 0
record.landlord = 1
record.period = 4
record.scharge = 1200
financial_validator.validate_rent_amount(record)
expect(record.errors["scharge"])
.to be_empty
end
it "does not allow the scharge to be outside of 0 and 280 range per week when period is every 2 weeks" do
record.needstype = 0
record.landlord = 1
record.period = 2
record.scharge = 561
financial_validator.validate_rent_amount(record)
expect(record.errors["scharge"])
.to include(match I18n.t("validations.financial.rent.scharge.this_landlord.supported_housing"))
end
it "does allow the scharge to be between of 0 and 280 per week when period is every 2 weeks" do
record.needstype = 0
record.landlord = 1
record.period = 2
record.scharge = 559
financial_validator.validate_rent_amount(record)
expect(record.errors["scharge"])
.to be_empty
end
end end
end end
end end

Loading…
Cancel
Save