diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 068b148fc..6809d8a9c 100644 --- a/app/models/case_log.rb +++ b/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" diff --git a/app/models/constants/db_enums.rb b/app/models/constants/db_enums.rb index 00442cc38..e4c5ace27 100644 --- a/app/models/constants/db_enums.rb +++ b/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 diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index de92df6e6..6f9ed06a3 100644 --- a/app/models/validations/household_validations.rb +++ b/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 diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index d640825ae..d369344b1 100644 --- a/config/forms/2021_2022.json +++ b/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": "", diff --git a/db/schema.rb b/db/schema.rb index fe6ed0955..255b55aa4 100644 --- a/db/schema.rb +++ b/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" diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index 80f05b7da..cca98c002 100644 --- a/spec/factories/case_log.rb +++ b/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" } diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index e70a7a2f0..b41538a8f 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -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", diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index b94710b1b..28bbc877a 100644 --- a/spec/models/case_log_spec.rb +++ b/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