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 def self.tenancy
{ {
"Fixed term – Secure" => 1, "Secure (including flexible)" => 1,
"Fixed term – Assured Shorthold Tenancy (AST)" => 4, "Assured" => 2,
"Lifetime – Secure" => 100, "Assured Shorthold" => 4,
"Lifetime – Assured" => 2, "Licence agreement (almshouses only)" => 5,
"License agreement" => 5,
"Other" => 3, "Other" => 3,
} }
end end

2
app/models/case_log.rb

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

6
app/validations/tenancy_validations.rb

@ -4,12 +4,12 @@ module TenancyValidations
def validate_fixed_term_tenancy(record) def validate_fixed_term_tenancy(record)
is_present = record.tenancylength.present? is_present = record.tenancylength.present?
is_in_range = record.tenancylength.to_i.between?(2, 99) is_in_range = record.tenancylength.to_i.between?(2, 99)
is_secure = record.tenancy == "Fixed term – Secure" is_secure = record.tenancy == "Secure (including flexible)"
is_ast = record.tenancy == "Fixed term – Assured Shorthold Tenancy (AST)" is_ast = record.tenancy == "Assured Shorthold"
conditions = [ 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_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_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 } conditions.each { |condition| condition[:condition] ? (record.errors.add :tenancylength, condition[:error]) : nil }

11
config/forms/2021_2022.json

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

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

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

2
spec/fixtures/complete_case_log.json vendored

@ -52,7 +52,7 @@
"startdate": "12/03/2019", "startdate": "12/03/2019",
"startertenancy": "No", "startertenancy": "No",
"tenancylength": "5", "tenancylength": "5",
"tenancy": "Fixed term – Secure", "tenancy": "Secure (including flexible)",
"lettype": "Affordable Rent - General Needs", "lettype": "Affordable Rent - General Needs",
"landlord": "This landlord", "landlord": "This landlord",
"la": "Barnet", "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 it "Must be completed and between 2 and 99 if type of tenancy is Assured shorthold" do
expect { expect {
CaseLog.create!(tenancy: "Fixed term – Assured Shorthold Tenancy (AST)", CaseLog.create!(tenancy: "Assured Shorthold",
tenancylength: 1) tenancylength: 1)
}.to raise_error(ActiveRecord::RecordInvalid) }.to raise_error(ActiveRecord::RecordInvalid)
expect { expect {
CaseLog.create!(tenancy: "Fixed term – Assured Shorthold Tenancy (AST)", CaseLog.create!(tenancy: "Assured Shorthold",
tenancylength: nil) tenancylength: nil)
}.to raise_error(ActiveRecord::RecordInvalid) }.to raise_error(ActiveRecord::RecordInvalid)
expect { expect {
CaseLog.create!(tenancy: "Fixed term – Assured Shorthold Tenancy (AST)", CaseLog.create!(tenancy: "Assured Shorthold",
tenancylength: 2) tenancylength: 2)
}.not_to raise_error }.not_to raise_error
end end
it "Must be empty or between 2 and 99 if type of tenancy is Secure" do it "Must be empty or between 2 and 99 if type of tenancy is Secure" do
expect { expect {
CaseLog.create!(tenancy: "Fixed term – Secure", CaseLog.create!(tenancy: "Secure (including flexible)",
tenancylength: 1) tenancylength: 1)
}.to raise_error(ActiveRecord::RecordInvalid) }.to raise_error(ActiveRecord::RecordInvalid)
expect { expect {
CaseLog.create!(tenancy: "Fixed term – Secure", CaseLog.create!(tenancy: "Secure (including flexible)",
tenancylength: 100) tenancylength: 100)
}.to raise_error(ActiveRecord::RecordInvalid) }.to raise_error(ActiveRecord::RecordInvalid)
expect { expect {
CaseLog.create!(tenancy: "Fixed term – Secure", CaseLog.create!(tenancy: "Secure (including flexible)",
tenancylength: nil) tenancylength: nil)
}.not_to raise_error }.not_to raise_error
expect { expect {
CaseLog.create!(tenancy: "Fixed term – Secure", CaseLog.create!(tenancy: "Secure (including flexible)",
tenancylength: 2) tenancylength: 2)
}.not_to raise_error }.not_to raise_error
end end
@ -294,12 +294,12 @@ RSpec.describe Form, type: :model do
it "must not be provided if tenancy type is not other" do it "must not be provided if tenancy type is not other" do
expect { expect {
CaseLog.create!(tenancy: "Fixed term – Secure", CaseLog.create!(tenancy: "Secure (including flexible)",
tenancyother: "the other reason provided") tenancyother: "the other reason provided")
}.to raise_error(ActiveRecord::RecordInvalid) }.to raise_error(ActiveRecord::RecordInvalid)
expect { expect {
CaseLog.create!(tenancy: "Fixed term – Secure", CaseLog.create!(tenancy: "Secure (including flexible)",
tenancyother: nil) tenancyother: nil)
}.not_to raise_error }.not_to raise_error
end end

Loading…
Cancel
Save