Browse Source

CLDC-4325: Fix lettings household validations spec

pull/3250/head
samyou-softwire 2 weeks ago
parent
commit
b4e5550058
  1. 175
      spec/models/validations/household_validations_spec.rb

175
spec/models/validations/household_validations_spec.rb

@ -6,7 +6,7 @@ RSpec.describe Validations::HouseholdValidations do
subject(:household_validator) { validator_class.new } subject(:household_validator) { validator_class.new }
let(:validator_class) { Class.new { include Validations::HouseholdValidations } } let(:validator_class) { Class.new { include Validations::HouseholdValidations } }
let(:startdate) { Time.zone.now } let(:startdate) { current_collection_start_date }
let(:record) { FactoryBot.build(:lettings_log, :setup_completed, startdate:, assigned_to: create(:user)) } let(:record) { FactoryBot.build(:lettings_log, :setup_completed, startdate:, assigned_to: create(:user)) }
describe "reasonable preference validations" do describe "reasonable preference validations" do
@ -117,52 +117,57 @@ RSpec.describe Validations::HouseholdValidations do
end end
end end
context "when referral is not internal transfer" do context "when 2025", metadata: { year: 25 } do
it "can be permanently decanted from another property owned by this landlord" do # post 2025 we don't ask referral and referral_type any more
record.reason = 1 let(:startdate) { collection_start_date_for_year(2025) }
record.referral_type = 1
record.referral = 2
household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["reason"])
.to be_empty
expect(record.errors["referral"])
.to be_empty
expect(record.errors["referral_type"])
.to be_empty
end
end
context "when referral is internal transfer" do context "when referral is not internal transfer" do
it "can be permanently decanted from another property owned by this landlord" do it "can be permanently decanted from another property owned by this landlord" do
record.reason = 1 record.reason = 1
record.referral_type = 3 record.referral_type = 1
record.referral = 1 record.referral = 2
household_validator.validate_reason_for_leaving_last_settled_home(record) household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["reason"]) expect(record.errors["reason"])
.to be_empty .to be_empty
expect(record.errors["referral"]) expect(record.errors["referral"])
.to be_empty .to be_empty
expect(record.errors["referral_type"]) expect(record.errors["referral_type"])
.to be_empty .to be_empty
end
end end
it "cannot have a PRP as landlord and Housing situation before this letting cannot be LA general needs" do context "when referral is internal transfer" do
record.owning_organisation.provider_type = "PRP" it "can be permanently decanted from another property owned by this landlord" do
record.prevten = 30 record.reason = 1
record.referral_type = 3 record.referral_type = 3
record.referral = 1 record.referral = 1
household_validator.validate_referral(record) household_validator.validate_reason_for_leaving_last_settled_home(record)
expect(record.errors["referral"]) expect(record.errors["reason"])
.to include(match(I18n.t("validations.lettings.household.referral.la_general_needs.internal_transfer"))) .to be_empty
expect(record.errors["prevten"]) expect(record.errors["referral"])
.to include(match(I18n.t("validations.lettings.household.prevten.la_general_needs.internal_transfer"))) .to be_empty
expect(record.errors["referral_type"])
.to be_empty
end
record.prevten = 31 it "cannot have a PRP as landlord and Housing situation before this letting cannot be LA general needs" do
household_validator.validate_referral(record) record.owning_organisation.provider_type = "PRP"
expect(record.errors["referral"]) record.prevten = 30
.to include(match(I18n.t("validations.lettings.household.referral.la_general_needs.internal_transfer"))) record.referral_type = 3
expect(record.errors["prevten"]) record.referral = 1
.to include(match(I18n.t("validations.lettings.household.prevten.la_general_needs.internal_transfer"))) household_validator.validate_referral(record)
expect(record.errors["referral"])
.to include(match(I18n.t("validations.lettings.household.referral.la_general_needs.internal_transfer")))
expect(record.errors["prevten"])
.to include(match(I18n.t("validations.lettings.household.prevten.la_general_needs.internal_transfer")))
record.prevten = 31
household_validator.validate_referral(record)
expect(record.errors["referral"])
.to include(match(I18n.t("validations.lettings.household.referral.la_general_needs.internal_transfer")))
expect(record.errors["prevten"])
.to include(match(I18n.t("validations.lettings.household.prevten.la_general_needs.internal_transfer")))
end
end end
end end
end end
@ -445,53 +450,57 @@ RSpec.describe Validations::HouseholdValidations do
end end
describe "referral validations" do describe "referral validations" do
context "when homelessness is assessed" do context "when start year is 2025", metadata: { year: 25 } do
it "can be internal transfer" do let(:startdate) { collection_start_date_for_year(2025) }
record.homeless = 11
record.referral_type = 3
record.referral = 1
household_validator.validate_referral(record)
expect(record.errors["referral"]).to be_empty
expect(record.errors["referral_type"]).to be_empty
expect(record.errors["homeless"]).to be_empty
end
it "can be non internal transfer" do context "when homelessness is assessed" do
record.owning_organisation.provider_type = "PRP" it "can be internal transfer" do
record.homeless = 0 record.homeless = 11
record.referral_type = 2 record.referral_type = 3
record.referral = 3 record.referral = 1
household_validator.validate_referral(record) household_validator.validate_referral(record)
expect(record.errors["referral"]).to be_empty expect(record.errors["referral"]).to be_empty
expect(record.errors["referral_type"]).to be_empty expect(record.errors["referral_type"]).to be_empty
expect(record.errors["homeless"]).to be_empty expect(record.errors["homeless"]).to be_empty
end end
end
context "when homelessness is other" do it "can be non internal transfer" do
it "cannot be internal transfer" do record.owning_organisation.provider_type = "PRP"
record.referral_type = 3 record.homeless = 0
record.referral = 1 record.referral_type = 2
record.homeless = 7 record.referral = 3
household_validator.validate_referral(record) household_validator.validate_referral(record)
expect(record.errors["referral"]).to be_empty expect(record.errors["referral"]).to be_empty
expect(record.errors["referral_type"]).to be_empty expect(record.errors["referral_type"]).to be_empty
expect(record.errors["homeless"]).to be_empty expect(record.errors["homeless"]).to be_empty
end
end end
it "can be non internal transfer" do context "when homelessness is other" do
record.owning_organisation.provider_type = "PRP" it "cannot be internal transfer" do
record.referral_type = 2 record.referral_type = 3
record.referral = 3 record.referral = 1
record.homeless = 1 record.homeless = 7
household_validator.validate_referral(record) household_validator.validate_referral(record)
expect(record.errors["referral"]).to be_empty expect(record.errors["referral"]).to be_empty
expect(record.errors["referral_type"]).to be_empty expect(record.errors["referral_type"]).to be_empty
expect(record.errors["homeless"]).to be_empty expect(record.errors["homeless"]).to be_empty
end
it "can be non internal transfer" do
record.owning_organisation.provider_type = "PRP"
record.referral_type = 2
record.referral = 3
record.homeless = 1
household_validator.validate_referral(record)
expect(record.errors["referral"]).to be_empty
expect(record.errors["referral_type"]).to be_empty
expect(record.errors["homeless"]).to be_empty
end
end end
end end
context "when start year is 2026" do context "when start year is 2026", metadata: { year: 26 } do
let(:startdate) { collection_start_date_for_year(2026) } let(:startdate) { collection_start_date_for_year(2026) }
[ [

Loading…
Cancel
Save