Browse Source

CLDC-679: Update main tenancy type mappings (#91)

* Update main tenancy type mappins

* Fix the tests and validations
pull/92/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
b358a67dde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      app/constants/db_enums.rb
  2. 2
      app/models/case_log.rb
  3. 6
      app/validations/tenancy_validations.rb
  4. 11
      config/forms/2021_2022.json
  5. 2
      docs/api/DLUHC-CORE-Data.v1.json
  6. 2
      spec/fixtures/complete_case_log.json
  7. 18
      spec/models/case_log_spec.rb

9
app/constants/db_enums.rb

@ -166,11 +166,10 @@ module DbEnums
def self.tenancy
{
"Fixed term – Secure" => 1,
"Fixed term – Assured Shorthold Tenancy (AST)" => 4,
"Lifetime – Secure" => 100,
"Lifetime – Assured" => 2,
"License agreement" => 5,
"Secure (including flexible)" => 1,
"Assured" => 2,
"Assured Shorthold" => 4,
"Licence agreement (almshouses only)" => 5,
"Other" => 3,
}
end

2
app/models/case_log.rb

@ -230,7 +230,7 @@ private
dynamically_not_required << "incfreq"
end
if tenancy == "Fixed term – Secure"
if tenancy == "Secure (including flexible)"
dynamically_not_required << "tenancylength"
end

6
app/validations/tenancy_validations.rb

@ -4,12 +4,12 @@ module TenancyValidations
def validate_fixed_term_tenancy(record)
is_present = record.tenancylength.present?
is_in_range = record.tenancylength.to_i.between?(2, 99)
is_secure = record.tenancy == "Fixed term – Secure"
is_ast = record.tenancy == "Fixed term – Assured Shorthold Tenancy (AST)"
is_secure = record.tenancy == "Secure (including flexible)"
is_ast = record.tenancy == "Assured Shorthold"
conditions = [
{ condition: !(is_secure || is_ast) && is_present, error: "You must only answer the fixed term tenancy length question if the tenancy type is fixed term" },
{ condition: is_ast && !is_in_range, error: "Fixed term – Assured Shorthold Tenancy (AST) should be between 2 and 99 years" },
{ condition: is_secure && (!is_in_range && is_present), error: "Fixed term – Secure should be between 2 and 99 years or not specified" },
{ condition: is_secure && (!is_in_range && is_present), error: "Secure (including flexible) should be between 2 and 99 years or not specified" },
]
conditions.each { |condition| condition[:condition] ? (record.errors.add :tenancylength, condition[:error]) : nil }

11
config/forms/2021_2022.json

@ -1068,12 +1068,11 @@
"hint_text": "",
"type": "radio",
"answer_options": {
"0": "Fixed term – Secure",
"1": "Fixed term – Assured Shorthold Tenancy (AST)",
"2": "Lifetime – Secure",
"3": "Lifetime – Assured",
"4": "License agreement",
"5": "Other"
"0": "Secure (including flexible)",
"1": "Assured",
"2": "Assured Shorthold",
"3": "Licence agreement (almshouses only)",
"4": "Other"
},
"conditional_for": {
"other_tenancy_type": ["Other"]

2
docs/api/DLUHC-CORE-Data.v1.json

@ -306,7 +306,7 @@
"startdate": "12/03/2019",
"startertenancy": "No",
"tenancylength": "No",
"tenancy": "Fixed term – Secure",
"tenancy": "Secure (including flexible)",
"lettype": "Affordable Rent - General Needs",
"landlord": "This landlord",
"la": "Barnet",

2
spec/fixtures/complete_case_log.json vendored

@ -52,7 +52,7 @@
"startdate": "12/03/2019",
"startertenancy": "No",
"tenancylength": "5",
"tenancy": "Fixed term – Secure",
"tenancy": "Secure (including flexible)",
"lettype": "Affordable Rent - General Needs",
"landlord": "This landlord",
"la": "Barnet",

18
spec/models/case_log_spec.rb

@ -182,39 +182,39 @@ RSpec.describe Form, type: :model do
it "Must be completed and between 2 and 99 if type of tenancy is Assured shorthold" do
expect {
CaseLog.create!(tenancy: "Fixed term – Assured Shorthold Tenancy (AST)",
CaseLog.create!(tenancy: "Assured Shorthold",
tenancylength: 1)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(tenancy: "Fixed term – Assured Shorthold Tenancy (AST)",
CaseLog.create!(tenancy: "Assured Shorthold",
tenancylength: nil)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(tenancy: "Fixed term – Assured Shorthold Tenancy (AST)",
CaseLog.create!(tenancy: "Assured Shorthold",
tenancylength: 2)
}.not_to raise_error
end
it "Must be empty or between 2 and 99 if type of tenancy is Secure" do
expect {
CaseLog.create!(tenancy: "Fixed term – Secure",
CaseLog.create!(tenancy: "Secure (including flexible)",
tenancylength: 1)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(tenancy: "Fixed term – Secure",
CaseLog.create!(tenancy: "Secure (including flexible)",
tenancylength: 100)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(tenancy: "Fixed term – Secure",
CaseLog.create!(tenancy: "Secure (including flexible)",
tenancylength: nil)
}.not_to raise_error
expect {
CaseLog.create!(tenancy: "Fixed term – Secure",
CaseLog.create!(tenancy: "Secure (including flexible)",
tenancylength: 2)
}.not_to raise_error
end
@ -294,12 +294,12 @@ RSpec.describe Form, type: :model do
it "must not be provided if tenancy type is not other" do
expect {
CaseLog.create!(tenancy: "Fixed term – Secure",
CaseLog.create!(tenancy: "Secure (including flexible)",
tenancyother: "the other reason provided")
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(tenancy: "Fixed term – Secure",
CaseLog.create!(tenancy: "Secure (including flexible)",
tenancyother: nil)
}.not_to raise_error
end

Loading…
Cancel
Save