Browse Source

CLDC-1908 Update lettings compound validation (#1682)

* feat: add second half of age/relat/ecstat validation to lettings logs

* feat: add tests

* feat: add ecstat refused option

* feat: update tests

* refactor: typo

* feat: add extra test, typos
sales-collection-year-test-fixes^2
natdeanlewissoftwire 2 years ago committed by GitHub
parent
commit
258e7cc81e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      app/models/validations/household_validations.rb
  2. 13
      app/models/validations/sales/household_validations.rb
  3. 2
      spec/models/validations/financial_validations_spec.rb
  4. 39
      spec/models/validations/household_validations_spec.rb
  5. 12
      spec/models/validations/sales/household_validations_spec.rb

19
app/models/validations/household_validations.rb

@ -187,10 +187,21 @@ private
relationship = record.public_send("relat#{person_num}")
return unless age && economic_status && relationship
if age >= 16 && age <= 19 && tenant_is_child?(relationship) && (!tenant_is_fulltime_student?(economic_status) && !tenant_economic_status_refused?(economic_status))
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.not_student_16_19", person_num:)
record.errors.add "age#{person_num}", I18n.t("validations.household.age.not_student_16_19", person_num:)
record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.not_student_16_19", person_num:)
age_between_16_19 = age.between?(16, 19)
student = tenant_is_fulltime_student?(economic_status)
economic_status_refused = tenant_economic_status_refused?(economic_status)
child = tenant_is_child?(relationship)
if age_between_16_19 && !(student || economic_status_refused) && child
record.errors.add "age#{person_num}", I18n.t("validations.household.age.student_16_19.cannot_be_16_19.child_not_student")
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.student_16_19.must_be_student")
record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.student_16_19.cannot_be_child.16_19_not_student")
end
if !age_between_16_19 && student && child
record.errors.add "age#{person_num}", I18n.t("validations.household.age.student_16_19.must_be_16_19")
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.student_16_19.cannot_be_student.child_not_16_19")
record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.student_16_19.cannot_be_child.student_not_16_19")
end
end

13
app/models/validations/sales/household_validations.rb

@ -54,9 +54,10 @@ private
age_between_16_19 = age.between?(16, 19)
student = person_is_fulltime_student?(economic_status)
economic_status_refused = person_economic_status_refused?(economic_status)
child = person_is_child?(relationship)
if age_between_16_19 && !student && child
if age_between_16_19 && !(student || economic_status_refused) && child
record.errors.add "age#{person_num}", I18n.t("validations.household.age.student_16_19.cannot_be_16_19.child_not_student")
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.student_16_19.must_be_student")
record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.student_16_19.cannot_be_child.16_19_not_student")
@ -74,11 +75,11 @@ private
economic_status = record.public_send("ecstat#{person_num}")
return unless age && economic_status
if age < 16 && !tenant_is_economic_child?(economic_status)
if age < 16 && !person_is_economic_child?(economic_status)
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_under_16", person_num:)
record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16", person_num:)
end
if tenant_is_economic_child?(economic_status) && age > 16
if person_is_economic_child?(economic_status) && age > 16
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_over_16", person_num:)
record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_over_16", person_num:)
end
@ -109,7 +110,11 @@ private
relationship == "C"
end
def tenant_is_economic_child?(economic_status)
def person_is_economic_child?(economic_status)
economic_status == 9
end
def person_economic_status_refused?(economic_status)
economic_status == 10
end
end

2
spec/models/validations/financial_validations_spec.rb

@ -990,7 +990,7 @@ RSpec.describe Validations::FinancialValidations do
end
context "and charges are not provided" do
xit "throws and error" do
xit "throws an error" do
record.period = 3
record.chcharge = nil
financial_validator.validate_care_home_charges(record)

39
spec/models/validations/household_validations_spec.rb

@ -335,11 +335,11 @@ RSpec.describe Validations::HouseholdValidations do
record.ecstat2 = 1
household_validator.validate_household_number_of_other_members(record)
expect(record.errors["ecstat2"])
.to include(match I18n.t("validations.household.ecstat.not_student_16_19", person_num: 2))
.to include(match I18n.t("validations.household.ecstat.student_16_19.must_be_student", person_num: 2))
expect(record.errors["age2"])
.to include(match I18n.t("validations.household.age.not_student_16_19", person_num: 2))
.to include(match I18n.t("validations.household.age.student_16_19.cannot_be_16_19.child_not_student", person_num: 2))
expect(record.errors["relat2"])
.to include(match I18n.t("validations.household.relat.not_student_16_19", person_num: 2))
.to include(match I18n.t("validations.household.relat.student_16_19.cannot_be_child.16_19_not_student", person_num: 2))
end
it "expects that person can be a full time student" do
@ -363,6 +363,39 @@ RSpec.describe Validations::HouseholdValidations do
end
end
it "does not add an error for a person aged 16-19 who is a student but not a child of the lead tenant" do
record.age2 = 18
record.ecstat2 = "7"
record.relat2 = "P"
household_validator.validate_household_number_of_other_members(record)
expect(record.errors["relat2"]).to be_empty
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
it "does not add an error for a person not aged 16-19 who is a student but not a child of the lead tenant" do
record.age2 = 20
record.ecstat2 = "7"
record.relat2 = "P"
household_validator.validate_household_number_of_other_members(record)
expect(record.errors["relat2"]).to be_empty
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
it "adds errors for a person who is a child of the lead tenant and a student but not aged 16-19" do
record.age2 = 14
record.ecstat2 = "7"
record.relat2 = "C"
household_validator.validate_household_number_of_other_members(record)
expect(record.errors["relat2"])
.to include(match I18n.t("validations.household.relat.student_16_19.cannot_be_child.student_not_16_19"))
expect(record.errors["age2"])
.to include(match I18n.t("validations.household.age.student_16_19.must_be_16_19"))
expect(record.errors["ecstat2"])
.to include(match I18n.t("validations.household.ecstat.student_16_19.cannot_be_student.child_not_16_19"))
end
context "when the household contains a person over 70" do
it "expects that person under 70 does not need to be retired" do
record.age2 = 50

12
spec/models/validations/sales/household_validations_spec.rb

@ -107,7 +107,7 @@ RSpec.describe Validations::Sales::HouseholdValidations do
.to include(match I18n.t("validations.household.age.child_over_20"))
end
it "does not add and error for a person aged 16-19 who is a student but not a child of the buyer" do
it "does not add an error for a person aged 16-19 who is a student but not a child of the buyer" do
record.age2 = 18
record.ecstat2 = "7"
record.relat2 = "P"
@ -117,6 +117,16 @@ RSpec.describe Validations::Sales::HouseholdValidations do
expect(record.errors["age2"]).to be_empty
end
it "does not add an error for a person not aged 16-19 who is a student but not a child of the buyer" do
record.age2 = 20
record.ecstat2 = "7"
record.relat2 = "P"
household_validator.validate_household_number_of_other_members(record)
expect(record.errors["relat2"]).to be_empty
expect(record.errors["ecstat2"]).to be_empty
expect(record.errors["age2"]).to be_empty
end
it "adds errors for a person aged 16-19 who is a child of the buyer but not a student" do
record.age2 = 17
record.ecstat2 = "1"

Loading…
Cancel
Save