Browse Source

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.
pull/1360/head
James Rose 2 years ago committed by GitHub
parent
commit
e22414cd73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/models/validations/financial_validations.rb
  2. 2
      spec/models/validations/financial_validations_spec.rb
  3. 29
      spec/services/imports/lettings_logs_import_service_spec.rb

6
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)

2
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)

29
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"

Loading…
Cancel
Save