From b08f2217417fa807ebcbf99a42cc7d5096367a27 Mon Sep 17 00:00:00 2001 From: samyou-softwire Date: Wed, 1 Apr 2026 15:19:46 +0100 Subject: [PATCH] CLDC-4250: Add verifying tests --- .../validations/financial_validations_spec.rb | 94 ++++++++++++++++++- 1 file changed, 89 insertions(+), 5 deletions(-) diff --git a/spec/models/validations/financial_validations_spec.rb b/spec/models/validations/financial_validations_spec.rb index 14e2dfd0c..9f976fe67 100644 --- a/spec/models/validations/financial_validations_spec.rb +++ b/spec/models/validations/financial_validations_spec.rb @@ -5,11 +5,6 @@ RSpec.describe Validations::FinancialValidations do let(:validator_class) { Class.new { include Validations::FinancialValidations } } let(:record) { FactoryBot.create(:lettings_log) } - let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") } - - before do - allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form) - end describe "earnings and income frequency" do it "when earnings are provided it validates that income frequency must be provided" do @@ -1234,4 +1229,93 @@ RSpec.describe Validations::FinancialValidations do end end end + + describe "universal credit and income sources validations" do + before do + record.hb = hb + record.benefits = benefits + end + + context "with a 2025 form", metadata: { year: 25 } do + before do + allow(record.form).to receive(:start_year_2026_or_later?).and_return(false) + end + + context "when tenant receives universal credit and no household income comes from benefits" do + let(:hb) { 6 } + let(:benefits) { 3 } + + it "adds errors to hb and benefits" do + financial_validator.validate_housing_universal_credit_matches_income_proportion(record) + expect(record.errors["hb"]).to be_empty + expect(record.errors["benefits"]).to be_empty + end + end + end + + context "with a 2026 form", metadata: { year: 26 } do + before do + allow(record.form).to receive(:start_year_2026_or_later?).and_return(true) + end + + context "when tenant receives universal credit and no household income comes from benefits" do + let(:hb) { 6 } + let(:benefits) { 3 } + + it "adds errors to hb and benefits" do + financial_validator.validate_housing_universal_credit_matches_income_proportion(record) + expect(record.errors["hb"]).to include(match I18n.t("validations.lettings.financial.hb.benefits_received_not_match_income_source")) + expect(record.errors["benefits"]).to include(match I18n.t("validations.lettings.financial.benefits.benefits_received_not_match_income_source")) + end + end + + context "when tenant receives universal credit and some household income comes from benefits" do + let(:hb) { 6 } + let(:benefits) { 2 } + + it "does not add errors" do + financial_validator.validate_housing_universal_credit_matches_income_proportion(record) + expect(record.errors["hb"]).to be_empty + expect(record.errors["benefits"]).to be_empty + end + end + + context "when tenant receives housing benefit and no household income comes from benefits" do + let(:hb) { 1 } + let(:benefits) { 3 } + + it "does not add errors" do + financial_validator.validate_housing_universal_credit_matches_income_proportion(record) + expect(record.errors["hb"]).to be_empty + expect(record.errors["benefits"]).to be_empty + end + end + + context "when hb is not set" do + let(:hb) { nil } + let(:benefits) { 3 } + + it "does not add errors" do + record.hb = nil + record.benefits = 3 + financial_validator.validate_housing_universal_credit_matches_income_proportion(record) + expect(record.errors["hb"]).to be_empty + expect(record.errors["benefits"]).to be_empty + end + end + + context "when benefits is not set" do + let(:hb) { 6 } + let(:benefits) { nil } + + it "does not add errors" do + record.hb = 6 + record.benefits = nil + financial_validator.validate_housing_universal_credit_matches_income_proportion(record) + expect(record.errors["hb"]).to be_empty + expect(record.errors["benefits"]).to be_empty + end + end + end + end end