Browse Source

Cldc 465 tenancy type validation (#312)

* Validate internal referrals and secure tenancy

* Fix referral validations and move referral validation from local_authority to household

* Move validation

* Add more error messages

* lint

* fix typo in test

* Check that the methods get called

* Fix lint
pull/318/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
ab1a16fb58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/models/constants/case_log.rb
  2. 7
      app/models/validations/household_validations.rb
  3. 6
      app/models/validations/local_authority_validations.rb
  4. 1
      app/models/validations/property_validations.rb
  5. 7
      app/models/validations/tenancy_validations.rb
  6. 10
      config/locales/en.yml
  7. 5
      spec/models/case_log_spec.rb
  8. 19
      spec/models/validations/household_validations_spec.rb
  9. 19
      spec/models/validations/tenancy_validations_spec.rb

2
app/models/constants/case_log.rb

@ -164,7 +164,7 @@ module Constants::CaseLog
}.freeze
RSNVAC = {
"Internal transfer (excluding renewals of a fixed-term tenancy)" => 13,
"Internal transfer" => 13,
"Previous tenant died with no succession" => 5,
"Re-let to tenant who occupied same property as temporary accommodation" => 9,
"Renewal of fixed-term tenancy" => 14,

7
app/models/validations/household_validations.rb

@ -73,6 +73,13 @@ module Validations::HouseholdValidations
end
end
def validate_referral(record)
if record.referral.present? && record.tenancy.present? && record.referral != "Internal transfer" && record.tenancy == "Secure (including flexible)"
record.errors.add :referral, I18n.t("validations.household.referral.secure_tenancy")
record.errors.add :tenancy, I18n.t("validations.tenancy.cannot_be_internal_transfer")
end
end
private
def women_of_child_bearing_age_in_household(record)

6
app/models/validations/local_authority_validations.rb

@ -9,10 +9,4 @@ module Validations::LocalAuthorityValidations
record.errors.add :previous_postcode, error_message
end
end
def validate_referral(record)
if record.rsnvac == "Re-let to tenant who occupied same property as temporary accommodation" && REFERRAL_INVALID_TMP.include?(record.referral)
record.errors.add :referral, I18n.t("validations.local_authority.referral.rsnvac_non_temp")
end
end
end

1
app/models/validations/property_validations.rb

@ -47,6 +47,7 @@ module Validations::PropertyValidations
if record.rsnvac == "Re-let to tenant who occupied same property as temporary accommodation" && REFERRAL_INVALID_TMP.include?(record.referral)
record.errors.add :rsnvac, I18n.t("validations.property.rsnvac.referral_invalid")
record.errors.add :referral, I18n.t("validations.household.referral.rsnvac_non_temp")
end
end

7
app/models/validations/tenancy_validations.rb

@ -25,4 +25,11 @@ module Validations::TenancyValidations
def validate_other_tenancy_type(record)
validate_other_field(record, :tenancy, :tenancyother)
end
def validate_tenancy_type(record)
if record.tenancy.present? && record.tenancy != "Secure (including flexible)" && record.referral == "Internal transfer"
record.errors.add :tenancy, I18n.t("validations.tenancy.internal_transfer")
record.errors.add :referral, I18n.t("validations.household.referral.cannot_be_secure_tenancy")
end
end
end

10
config/locales/en.yml

@ -110,16 +110,18 @@ en:
one_or_two_choices: "Only one box must be ticked or 'other disabilities' plus one of mobility disabilities"
prevten:
non_temp_accommodation: "Answer cannot be non-temporary accommodation as you already told us this is a re-let to tenant who occupied the same property as temporary accommodation"
referral:
secure_tenancy: "Answer must be internal transfer as you already told us this is a secure tenancy"
rsnvac_non_temp: "Answer cannot be this source of referral as you already told us this is a re-let to tenant who occupied the same property as temporary accommodation"
cannot_be_secure_tenancy: "Answer cannot be secure tenancy as you already told us this is not an internal transfer"
tenancy:
length:
fixed_term_not_required: "You must only answer the fixed term tenancy length question if the tenancy type is fixed term"
shorthold: "Fixed term – Assured Shorthold Tenancy (AST) should be between 2 and 99 years"
secure: "Secure (including flexible) should be between 2 and 99 years or not specified"
local_authority:
referral:
rsnvac_non_temp: "Answer cannot be this source of referral as you already told us this is a re-let to tenant who occupied the same property as temporary accommodation"
internal_transfer: "Answer must be secure tenancy as you already told us this tenancy is an internal transfer"
cannot_be_internal_transfer: "Answer cannot be internal transfer as you already told us this is not a secure tenancy"
declaration:
missing: "You must show the DLUHC privacy notice to the tenant before you can submit this log."

5
spec/models/case_log_spec.rb

@ -104,6 +104,7 @@ RSpec.describe CaseLog do
it "validates tenancy type" do
expect(validator).to receive(:validate_fixed_term_tenancy)
expect(validator).to receive(:validate_other_tenancy_type)
expect(validator).to receive(:validate_tenancy_type)
end
it "validates the previous postcode" do
@ -161,6 +162,10 @@ RSpec.describe CaseLog do
it "validates accessibility requirements" do
expect(validator).to receive(:validate_accessibility_requirements)
end
it "validates referral" do
expect(validator).to receive(:validate_referral)
end
end
describe "status" do

19
spec/models/validations/household_validations_spec.rb

@ -477,4 +477,23 @@ RSpec.describe Validations::HouseholdValidations do
expect(record.errors["accessibility_requirements"]).to be_empty
end
end
describe "referral validations" do
context "when type of tenancy is not secure" do
it "cannot be not internal transfer" do
record.tenancy = "Secure (including flexible)"
record.referral = "Other social landlord"
household_validator.validate_referral(record)
expect(record.errors["referral"])
.to include(match I18n.t("validations.household.referral.secure_tenancy"))
end
it "can be internal transfer" do
record.tenancy = "Secure (including flexible)"
record.referral = "Internal transfer"
household_validator.validate_referral(record)
expect(record.errors["referral"]).to be_empty
end
end
end
end

19
spec/models/validations/tenancy_validations_spec.rb

@ -106,6 +106,25 @@ RSpec.describe Validations::TenancyValidations do
expect(record.errors["tenancy"]).to be_empty
end
end
context "when referral is not internal transfer" do
it "adds an error" do
record.tenancy = "Assured"
record.referral = "Internal transfer"
tenancy_validator.validate_tenancy_type(record)
expect(record.errors["tenancy"])
.to include(match I18n.t("validations.tenancy.internal_transfer"))
end
end
context "when referral is internal transfer" do
it "does not add an error" do
record.tenancy = "Secure (including flexible)"
record.referral = "Internal transfer"
tenancy_validator.validate_tenancy_type(record)
expect(record.errors["tenancy"]).to be_empty
end
end
end
end
end

Loading…
Cancel
Save