From 650757eaa4b25df47e1564cf1413098b803864c0 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Mon, 29 Jan 2024 14:35:11 +0000 Subject: [PATCH] feat: add validation tests --- app/models/lettings_log.rb | 24 +++++----- .../validations/household_validations_spec.rb | 45 +++++++++++++++---- 2 files changed, 48 insertions(+), 21 deletions(-) diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 55db7bfe4..7b25f1cc3 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -660,6 +660,18 @@ class LettingsLog < Log renttype == 1 || renttype == 2 end + def no_or_unknown_other_housing_needs? + housingneeds_other&.zero? || housingneeds_other == 2 + end + + def has_housingneeds? + housingneeds == 1 + end + + def housingneeds_type_not_listed? + housingneeds_type == 3 + end + def duplicates LettingsLog.where.not(duplicate_set_id: nil).where(duplicate_set_id:).where.not(id:) end @@ -814,14 +826,6 @@ private housingneeds_other == 1 end - def no_or_unknown_other_housing_needs? - housingneeds_other&.zero? || housing_needs_other == 2 - end - - def has_housingneeds? - housingneeds == 1 - end - def no_housingneeds? housingneeds == 2 end @@ -830,10 +834,6 @@ private housingneeds == 3 end - def housingneeds_type_not_listed? - housingneeds_type == 3 - end - def should_process_uprn_change? uprn && startdate && (uprn_changed? || startdate_changed?) && collection_start_year_for_date(startdate) >= 2023 end diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index 98da214f1..2720c7285 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -674,18 +674,45 @@ RSpec.describe Validations::HouseholdValidations do end describe "housing needs validations" do - it "is invalid when a combination of housingneeds == 1 (yes) && housingneeds_type == 3 (none of listed) && housingneeds_other == 0 (no)" do - record.housingneeds = 1 - record.housingneeds_type = 3 - record.housingneeds_other = 0 + context "with housingneeds == 2 (yes) && housingneeds_type == 3" do + before do + record.housingneeds = 1 + record.housingneeds_type = 3 + end + + context "with housingneeds_other == 0 (no)" do + before do + record.housingneeds_other = 0 + end + + it "is invalid" do + household_validator.validate_combination_of_housing_needs_responses(record) + + error_message = ["If somebody in the household has disabled access needs, they must have the access needs listed, or other access needs"] + + expect(record.errors["housingneeds"]).to eq(error_message) + expect(record.errors["housingneeds_type"]).to eq(error_message) + expect(record.errors["housingneeds_other"]).to eq(error_message) + + end + end + + context "with housingneeds_other == 2 (don't know)" do + before do + record.housingneeds_other = 2 + end - household_validator.validate_combination_of_housing_needs_responses(record) + it "is invalid" do + household_validator.validate_combination_of_housing_needs_responses(record) - error_message = ["If somebody in the household has disabled access needs, they must have the access needs listed, or other access needs"] + error_message = ["If somebody in the household has disabled access needs, they must have the access needs listed, or other access needs"] - expect(record.errors["housingneeds"]).to eq(error_message) - expect(record.errors["housingneeds_type"]).to eq(error_message) - expect(record.errors["housingneeds_other"]).to eq(error_message) + expect(record.errors["housingneeds"]).to eq(error_message) + expect(record.errors["housingneeds_type"]).to eq(error_message) + expect(record.errors["housingneeds_other"]).to eq(error_message) + + end + end end end end