Browse Source

Outstanding rent and shortfall validations

pull/304/head
baarkerlounger 3 years ago
parent
commit
ad8bd97d5a
  1. 19
      spec/models/case_log_spec.rb
  2. 62
      spec/models/validations/financial_validations_spec.rb

19
spec/models/case_log_spec.rb

@ -124,17 +124,6 @@ RSpec.describe CaseLog do
end end
end end
context "when validating outstanding rent or charges" do
it "must be not be anwered if answered no to outstanding rent or charges" do
expect {
described_class.create!(hbrentshortfall: "No",
tshortfall: 99,
owning_organisation:,
managing_organisation:)
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
context "when saving income ranges" do context "when saving income ranges" do
it "validates net income maximum" do it "validates net income maximum" do
expect { expect {
@ -350,6 +339,14 @@ RSpec.describe CaseLog do
it "validates benefits as proportion of income" do it "validates benefits as proportion of income" do
expect(validator).to receive(:validate_net_income_uc_proportion) expect(validator).to receive(:validate_net_income_uc_proportion)
end end
it "validates outstanding rent amount" do
expect(validator).to receive(:validate_outstanding_rent_amount)
end
it "validates housing benefit rent shortfall" do
expect(validator).to receive(:tshortfall)
end
end end
describe "status" do describe "status" do

62
spec/models/validations/financial_validations_spec.rb

@ -11,14 +11,16 @@ RSpec.describe Validations::FinancialValidations do
record.earnings = 500 record.earnings = 500
record.incfreq = nil record.incfreq = nil
financial_validator.validate_net_income(record) financial_validator.validate_net_income(record)
expect(record.errors["incfreq"]).to include(match I18n.t("validations.financial.earnings.freq_missing")) expect(record.errors["incfreq"])
.to include(match I18n.t("validations.financial.earnings.freq_missing"))
end end
it "when income frequency is provided it validates that earnings must be provided" do it "when income frequency is provided it validates that earnings must be provided" do
record.earnings = nil record.earnings = nil
record.incfreq = "Weekly" record.incfreq = "Weekly"
financial_validator.validate_net_income(record) financial_validator.validate_net_income(record)
expect(record.errors["earnings"]).to include(match I18n.t("validations.financial.earnings.earnings_missing")) expect(record.errors["earnings"])
.to include(match I18n.t("validations.financial.earnings.earnings_missing"))
end end
end end
@ -62,4 +64,60 @@ RSpec.describe Validations::FinancialValidations do
end end
end end
end end
describe "outstanding rent amount validations" do
context "when outstanding rent or charges is no" do
it "validates that no shortfall is provided" do
record.hbrentshortfall = "No"
record.tshortfall = 99
financial_validator.validate_outstanding_rent_amount(record)
expect(record.errors["tshortfall"])
.to include(match I18n.t("validations.financial.tshortfall.outstanding_amount_not_required"))
end
end
context "when outstanding rent or charges is yes" do
it "expects that a shortfall is provided" do
record.hbrentshortfall = "Yes"
record.tshortfall = 99
financial_validator.validate_outstanding_rent_amount(record)
expect(record.errors["tshortfall"]).to be_empty
end
end
end
describe "housing benefit rent shortfall validations" do
context "when shortfall is yes" do
it "validates that housing benefit is not none" do
record.hbrentshortfall = "Yes"
record.hb = "None"
financial_validator.validate_tshortfall(record)
expect(record.errors["tshortfall"])
.to include(match I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits"))
end
it "validates that housing benefit is not don't know" do
record.hbrentshortfall = "Yes"
record.hb = "Don’t know"
financial_validator.validate_tshortfall(record)
expect(record.errors["tshortfall"])
.to include(match I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits"))
end
it "validates that housing benefit is not Universal Credit without housing benefit" do
record.hbrentshortfall = "Yes"
record.hb = "Universal Credit (without housing element)"
financial_validator.validate_tshortfall(record)
expect(record.errors["tshortfall"])
.to include(match I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits"))
end
it "validates that housing benefit is provided" do
record.hbrentshortfall = "Yes"
record.hb = "Housing benefit"
financial_validator.validate_tshortfall(record)
expect(record.errors["tshortfall"]).to be_empty
end
end
end
end end

Loading…
Cancel
Save