From f0f50701353e6e6f5d7b2c545506792ea70e8303 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Wed, 9 Feb 2022 10:19:57 +0000 Subject: [PATCH] Renewal inferred variables (#285) * Infer layear if it is a renewal * Infer underoccupation_benefitcap if it is a renewal * Infer homelessness if it is a renewal --- app/models/case_log.rb | 3 +++ spec/fixtures/complete_case_log.json | 7 +++---- spec/models/case_log_spec.rb | 29 ++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index a4c331b4b..bfcf09913 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -252,6 +252,9 @@ private self.tcharge = brent.to_f + scharge.to_f + pscharge.to_f + supcharg.to_f self.has_benefits = get_has_benefits self.nocharge = household_charge == "Yes" ? "No" : "Yes" + self.layear = "Less than 1 year" if renewal == "Yes" + self.underoccupation_benefitcap = "No" if renewal == "Yes" && year == 2021 + self.homeless = "No" if renewal == "Yes" end def process_postcode_changes! diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index 268283c2a..a172080c3 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -40,7 +40,7 @@ "age8": 2, "sex8": "Prefer not to say", "ecstat8": "Child under 16", - "homeless": "Yes - other homelessness", + "homeless": "No", "reason": 1, "underoccupation_benefitcap": "No", "leftreg": "No - they left up to 5 years ago", @@ -90,8 +90,7 @@ "lawaitlist": "Less than 1 year", "prevloc": "Ashford", "previous_postcode": "SE2 6RT", - "reasonpref": "Yes", - "reasonable_preference_reason": "dummy", + "reasonpref": "No", "cbl": "Yes", "chr": "Yes", "cap": "No", @@ -116,7 +115,7 @@ "illness_type_9": "No", "illness_type_10": "No", "condition_effects_prefer_not_to_say": "Yes", - "rp_homeless": "Yes", + "rp_homeless": "No", "rp_insan_unsat": "No", "rp_medwel": "No", "rp_hardship": "No", diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 6fb4f43be..cab941041 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -1153,6 +1153,35 @@ RSpec.describe CaseLog do record_from_db = ActiveRecord::Base.connection.execute("select has_benefits from case_logs where id=#{case_log.id}").to_a[0] expect(record_from_db["has_benefits"]).to eq("Yes") end + + context "when it is a renewal" do + let!(:case_log) do + described_class.create({ + managing_organisation: organisation, + owning_organisation: organisation, + renewal: "Yes", + year: 2021, + }) + end + + it "correctly derives and saves layear" do + record_from_db = ActiveRecord::Base.connection.execute("select layear from case_logs where id=#{case_log.id}").to_a[0] + expect(record_from_db["layear"]).to eq(2) + expect(case_log["layear"]).to eq("Less than 1 year") + end + + it "correctly derives and saves underoccupation_benefitcap if year is 2021" do + record_from_db = ActiveRecord::Base.connection.execute("select underoccupation_benefitcap from case_logs where id=#{case_log.id}").to_a[0] + expect(record_from_db["underoccupation_benefitcap"]).to eq(2) + expect(case_log["underoccupation_benefitcap"]).to eq("No") + end + + it "correctly derives and saves homeless" do + record_from_db = ActiveRecord::Base.connection.execute("select homeless from case_logs where id=#{case_log.id}").to_a[0] + expect(record_from_db["homeless"]).to eq(1) + expect(case_log["homeless"]).to eq("No") + end + end end describe "resetting invalidated fields" do