From e22414cd7397261848412309a5377800e3f1f1c4 Mon Sep 17 00:00:00 2001 From: James Rose Date: Wed, 1 Mar 2023 14:34:49 +0000 Subject: [PATCH] Allow empty `chcharge` values whilst `is_carehome` is set to true (#1359) - This validation is new to this service. The old CORE did not do it. - A decision was decided to move this to a soft validation in CLDC-2074 - As a temporary fix to allow us to migrate values that are currently incompatible with our validation, we will relax this constraint. --- .../validations/financial_validations.rb | 6 ++-- .../validations/financial_validations_spec.rb | 2 +- .../lettings_logs_import_service_spec.rb | 29 +++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index 175b0b1bd..6179d05aa 100644 --- a/app/models/validations/financial_validations.rb +++ b/app/models/validations/financial_validations.rb @@ -111,9 +111,11 @@ module Validations::FinancialValidations def validate_care_home_charges(record) if record.is_carehome? period = record.form.get_question("period", record).label_from_value(record.period).downcase + # NOTE: This is a temporary change to allow `ccharge` values despite `is_carehome` being true. This value + # is going to be moved to a soft validation in CLDC-2074, so we can safely do this. if record.chcharge.blank? - record.errors.add :is_carehome, I18n.t("validations.financial.carehome.not_provided", period:) - record.errors.add :chcharge, I18n.t("validations.financial.carehome.not_provided", period:) + # record.errors.add :is_carehome, I18n.t("validations.financial.carehome.not_provided", period:) + # record.errors.add :chcharge, I18n.t("validations.financial.carehome.not_provided", period:) elsif !weekly_value_in_range(record, "chcharge", 10, 1000) max_chcharge = record.weekly_to_value_per_period(1000) min_chcharge = record.weekly_to_value_per_period(10) diff --git a/spec/models/validations/financial_validations_spec.rb b/spec/models/validations/financial_validations_spec.rb index ae7875e08..bdd76cded 100644 --- a/spec/models/validations/financial_validations_spec.rb +++ b/spec/models/validations/financial_validations_spec.rb @@ -990,7 +990,7 @@ RSpec.describe Validations::FinancialValidations do end context "and charges are not provided" do - it "throws and error" do + xit "throws and error" do record.period = 3 record.chcharge = nil financial_validator.validate_care_home_charges(record) diff --git a/spec/services/imports/lettings_logs_import_service_spec.rb b/spec/services/imports/lettings_logs_import_service_spec.rb index e3f04b74c..be650c484 100644 --- a/spec/services/imports/lettings_logs_import_service_spec.rb +++ b/spec/services/imports/lettings_logs_import_service_spec.rb @@ -280,6 +280,35 @@ RSpec.describe Imports::LettingsLogsImportService do end end + context "and is a carehome but missing carehome charge" do + let(:lettings_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" } + + before do + lettings_log_xml.at_xpath("//meta:status").content = "submitted" + lettings_log_xml.at_xpath("//xmlns:_1cmangroupcode").content = scheme2.old_visible_id + scheme2.update!(registered_under_care_act: 2) + lettings_log_xml.at_xpath("//xmlns:Q18b").content = "" + end + + it "intercepts the relevant validation error" do + allow(logger).to receive(:warn) + + expect { lettings_log_service.send(:create_log, lettings_log_xml) } + .not_to raise_error + end + + it "clears out the invalid answers" do + allow(logger).to receive(:warn) + + lettings_log_service.send(:create_log, lettings_log_xml) + lettings_log = LettingsLog.find_by(old_id: lettings_log_id) + + expect(lettings_log).not_to be_nil + expect(lettings_log.is_carehome).to be_truthy + expect(lettings_log.chcharge).to be_nil + end + end + context "and this is an internal transfer from a non social housing" do before do lettings_log_xml.at_xpath("//xmlns:Q11").content = "9 Residential care home"