From ad8bd97d5ac8d3f52253e060ed4be60a2e15f232 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Mon, 14 Feb 2022 17:36:49 +0000 Subject: [PATCH] Outstanding rent and shortfall validations --- spec/models/case_log_spec.rb | 19 +++--- .../validations/financial_validations_spec.rb | 62 ++++++++++++++++++- 2 files changed, 68 insertions(+), 13 deletions(-) diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 866c89378..f5f6d5041 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -124,17 +124,6 @@ RSpec.describe CaseLog do 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 it "validates net income maximum" do expect { @@ -350,6 +339,14 @@ RSpec.describe CaseLog do it "validates benefits as proportion of income" do expect(validator).to receive(:validate_net_income_uc_proportion) 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 describe "status" do diff --git a/spec/models/validations/financial_validations_spec.rb b/spec/models/validations/financial_validations_spec.rb index 5fdb0fcc6..e4ce17b9b 100644 --- a/spec/models/validations/financial_validations_spec.rb +++ b/spec/models/validations/financial_validations_spec.rb @@ -11,14 +11,16 @@ RSpec.describe Validations::FinancialValidations do record.earnings = 500 record.incfreq = nil 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 it "when income frequency is provided it validates that earnings must be provided" do record.earnings = nil record.incfreq = "Weekly" 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 @@ -62,4 +64,60 @@ RSpec.describe Validations::FinancialValidations do 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