Browse Source

CLDC-498: property type validation (#142)

* Update mappings based on content changes and add tests for property type validation

* move out RENT_TYPE_MAPPING to constants file
pull/144/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
5bc78a6a5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      app/models/case_log.rb
  2. 37
      app/models/constants/db_enums.rb
  3. 2
      app/models/validations/household_validations.rb
  4. 2
      config/forms/2021_2022.json
  5. 2
      db/schema.rb
  6. 2
      spec/factories/case_log.rb
  7. 2
      spec/fixtures/complete_case_log.json
  8. 24
      spec/models/case_log_spec.rb

9
app/models/case_log.rb

@ -156,15 +156,6 @@ class CaseLog < ApplicationRecord
private
RENT_TYPE_MAPPING = {
"Social Rent" => "Social Rent",
"Affordable Rent" => "Affordable Rent",
"London Affordable Rent" => "Affordable Rent",
"Rent To Buy" => "Intermediate Rent",
"London Living Rent" => "Intermediate Rent",
"Other Intermediate Rent Product" => "Intermediate Rent",
}.freeze
def update_status!
self.status = if all_fields_completed? && errors.empty?
"completed"

37
app/models/constants/db_enums.rb

@ -672,8 +672,8 @@ module Constants::DbEnums
}.freeze
NEEDS_TYPE = {
"General Needs" => 1,
"Supported Housing" => 2,
"General needs" => 1,
"Supported housing" => 2,
}.freeze
ORG_TYPE = {
@ -682,17 +682,26 @@ module Constants::DbEnums
}.freeze
LET_TYPE = {
"Social Rent General Needs PRP" => 1,
"Social Rent Supported Housing PRP" => 2,
"Social Rent General Needs LA" => 3,
"Social Rent Supported Housing LA" => 4,
"Affordable Rent General Needs PRP" => 5,
"Affordable Rent Supported Housing PRP" => 6,
"Affordable Rent General Needs LA" => 7,
"Affordable Rent Supported Housing LA" => 8,
"Intermediate Rent General Needs PRP" => 9,
"Intermediate Rent Supported Housing PRP" => 10,
"Intermediate Rent General Needs LA" => 11,
"Intermediate Rent Supported Housing LA" => 12,
"Social Rent General needs PRP" => 1,
"Social Rent Supported housing PRP" => 2,
"Social Rent General needs LA" => 3,
"Social Rent Supported housing LA" => 4,
"Affordable Rent General needs PRP" => 5,
"Affordable Rent Supported housing PRP" => 6,
"Affordable Rent General needs LA" => 7,
"Affordable Rent Supported housing LA" => 8,
"Intermediate Rent General needs PRP" => 9,
"Intermediate Rent Supported housing PRP" => 10,
"Intermediate Rent General needs LA" => 11,
"Intermediate Rent Supported housing LA" => 12,
}.freeze
RENT_TYPE_MAPPING = {
"Social rent" => "Social Rent",
"Affordable rent" => "Affordable Rent",
"London Affordable rent" => "Affordable Rent",
"Rent to buy" => "Intermediate Rent",
"London living rent" => "Intermediate Rent",
"Other intermediate rent product" => "Intermediate Rent",
}.freeze
end

2
app/models/validations/household_validations.rb

@ -76,7 +76,7 @@ module Validations::HouseholdValidations
def validate_shared_housing_rooms(record)
unless record.unittype_gn.nil?
if record.unittype_gn == "Bed-sit" && record.beds != 1
if record.unittype_gn == "Bed-sit" && record.beds != 1 && record.beds.present?
record.errors.add :unittype_gn, "A bedsit can only have one bedroom"
end

2
config/forms/2021_2022.json

@ -1668,7 +1668,7 @@
"step": 1
}
},
"depends_on": { "needstype": "General Needs" }
"depends_on": { "needstype": "General needs" }
},
"void_or_renewal_date": {
"header": "",

2
db/schema.rb

@ -163,9 +163,9 @@ ActiveRecord::Schema.define(version: 2021_12_02_124802) do
t.string "why_dont_you_know_la"
t.integer "unitletas"
t.integer "builtype"
t.datetime "property_void_date"
t.bigint "owning_organisation_id"
t.bigint "managing_organisation_id"
t.datetime "property_void_date"
t.integer "renttype"
t.integer "needstype"
t.integer "lettype"

2
spec/factories/case_log.rb

@ -52,7 +52,7 @@ FactoryBot.define do
startertenancy { "No" }
tenancylength { 5 }
tenancy { "Secure (including flexible)" }
lettype { "Affordable Rent General Needs LA" }
lettype { "Affordable Rent General needs LA" }
landlord { "This landlord" }
previous_postcode { "SE2 6RT" }
rsnvac { "Tenant abandoned property" }

2
spec/fixtures/complete_case_log.json vendored

@ -127,7 +127,7 @@
"sale_or_letting": "",
"rent_type": "Social Rent",
"intermediate_rent_product_name": "",
"needstype": "General Needs",
"needstype": "General needs",
"sale_completion_date": "01/01/2020",
"purchaser_code": "",
"propcode": "123",

24
spec/models/case_log_spec.rb

@ -790,6 +790,24 @@ RSpec.describe Form, type: :model do
}.not_to raise_error
end
end
context "Validate type of unit" do
it "Cannot be bedsit if no of bedrooms is greater than 1" do
expect {
CaseLog.create!(unittype_gn: "Bed-sit",
beds: 2,
owning_organisation: owning_organisation,
managing_organisation: managing_organisation)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(unittype_gn: "Bed-sit",
beds: 1,
owning_organisation: owning_organisation,
managing_organisation: managing_organisation)
}.not_to raise_error
end
end
end
describe "status" do
@ -850,8 +868,8 @@ RSpec.describe Form, type: :model do
# rubocop:enable Style/DateTime
net_income_known: "Prefer not to say",
other_hhmemb: 6,
rent_type: "London Living Rent",
needstype: "General Needs",
rent_type: "London living rent",
needstype: "General needs",
})
end
@ -909,7 +927,7 @@ RSpec.describe Form, type: :model do
case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select lettype from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.lettype).to eq("Intermediate Rent General Needs PRP")
expect(case_log.lettype).to eq("Intermediate Rent General needs PRP")
expect(record_from_db["lettype"]).to eq(9)
end
end

Loading…
Cancel
Save