From 9fc705cc37fa6084c0837290f1643bbea7d794b7 Mon Sep 17 00:00:00 2001 From: Arthur Campbell <51094020+arfacamble@users.noreply.github.com> Date: Mon, 27 Feb 2023 09:31:44 +0000 Subject: [PATCH] CLDC-1905 infer vacancy reason when renewal (#1321) * add test for derivation of relet when renewal * derive rsnvac when renewal set to yes, reset rsnvac when renewal set to no * add test to ensure vacancy reasion is reset if letting is not a renewal --- .../lettings_log_variables.rb | 1 + app/models/lettings_log.rb | 1 + spec/models/lettings_log_spec.rb | 21 +++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/app/models/derived_variables/lettings_log_variables.rb b/app/models/derived_variables/lettings_log_variables.rb index 7d664e48f..37e659652 100644 --- a/app/models/derived_variables/lettings_log_variables.rb +++ b/app/models/derived_variables/lettings_log_variables.rb @@ -48,6 +48,7 @@ module DerivedVariables::LettingsLogVariables self.offered = 0 self.voiddate = startdate self.first_time_property_let_as_social_housing = 0 + self.rsnvac = 14 if is_general_needs? # fixed term self.prevten = 32 if managing_organisation&.provider_type == "PRP" diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 02236f70b..d9fe89509 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -518,6 +518,7 @@ private def reset_derived_questions dependent_questions = { waityear: [{ key: :renewal, value: 0 }], referral: [{ key: :renewal, value: 0 }], + rsnvac: [{ key: :renewal, value: 0 }], underoccupation_benefitcap: [{ key: :renewal, value: 0 }], wchair: [{ key: :needstype, value: 1 }], location_id: [{ key: :needstype, value: 1 }] } diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index d4bbd8378..b28f8bfea 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -1468,6 +1468,12 @@ RSpec.describe LettingsLog do expect(record_from_db["first_time_property_let_as_social_housing"]).to eq(0) expect(lettings_log["first_time_property_let_as_social_housing"]).to eq(0) end + + it "derives vacancy reason as relet" do + record_from_db = ActiveRecord::Base.connection.execute("select rsnvac from lettings_logs where id=#{lettings_log.id}").to_a[0] + expect(record_from_db["rsnvac"]).to eq(14) + expect(lettings_log["rsnvac"]).to eq(14) + end end context "when answering the household characteristics questions" do @@ -1992,6 +1998,21 @@ RSpec.describe LettingsLog do expect(record_from_db["waityear"]).to eq(nil) expect(lettings_log["waityear"]).to eq(nil) end + + it "resets inferred vacancy reason value" do + vacancy_reason = "rsnvac" + + lettings_log.update!({ renewal: 1 }) + + record_from_db = ActiveRecord::Base.connection.execute("select #{vacancy_reason} from lettings_logs where id=#{lettings_log.id}").to_a[0] + expect(record_from_db[vacancy_reason]).to eq(14) + expect(lettings_log[vacancy_reason]).to eq(14) + + lettings_log.update!({ renewal: 0 }) + record_from_db = ActiveRecord::Base.connection.execute("select #{vacancy_reason} from lettings_logs where id=#{lettings_log.id}").to_a[0] + expect(record_from_db[vacancy_reason]).to eq(nil) + expect(lettings_log[vacancy_reason]).to eq(nil) + end end context "when it changes from a supported housing to not a supported housing" do