Browse Source

feat: add validation tests

pull/2183/head
natdeanlewissoftwire 2 years ago committed by Kat
parent
commit
650757eaa4
  1. 24
      app/models/lettings_log.rb
  2. 45
      spec/models/validations/household_validations_spec.rb

24
app/models/lettings_log.rb

@ -660,6 +660,18 @@ class LettingsLog < Log
renttype == 1 || renttype == 2 renttype == 1 || renttype == 2
end 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 def duplicates
LettingsLog.where.not(duplicate_set_id: nil).where(duplicate_set_id:).where.not(id:) LettingsLog.where.not(duplicate_set_id: nil).where(duplicate_set_id:).where.not(id:)
end end
@ -814,14 +826,6 @@ private
housingneeds_other == 1 housingneeds_other == 1
end 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? def no_housingneeds?
housingneeds == 2 housingneeds == 2
end end
@ -830,10 +834,6 @@ private
housingneeds == 3 housingneeds == 3
end end
def housingneeds_type_not_listed?
housingneeds_type == 3
end
def should_process_uprn_change? def should_process_uprn_change?
uprn && startdate && (uprn_changed? || startdate_changed?) && collection_start_year_for_date(startdate) >= 2023 uprn && startdate && (uprn_changed? || startdate_changed?) && collection_start_year_for_date(startdate) >= 2023
end end

45
spec/models/validations/household_validations_spec.rb

@ -674,18 +674,45 @@ RSpec.describe Validations::HouseholdValidations do
end end
describe "housing needs validations" do 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 context "with housingneeds == 2 (yes) && housingneeds_type == 3" do
record.housingneeds = 1 before do
record.housingneeds_type = 3 record.housingneeds = 1
record.housingneeds_other = 0 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"]).to eq(error_message)
expect(record.errors["housingneeds_type"]).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_other"]).to eq(error_message)
end
end
end end
end end
end end

Loading…
Cancel
Save