Browse Source

Remove care home charge if it's outside the range

pull/1479/head
Kat 3 years ago
parent
commit
97a72fafec
  1. 2
      app/models/validations/financial_validations.rb
  2. 5
      app/services/imports/lettings_logs_import_service.rb
  3. 31
      spec/services/imports/lettings_logs_import_service_spec.rb

2
app/models/validations/financial_validations.rb

@ -123,7 +123,7 @@ module Validations::FinancialValidations
max_chcharge = [record.form.get_question("chcharge", record).prefix, max_chcharge].join("") if record.form.get_question("chcharge", record).present? max_chcharge = [record.form.get_question("chcharge", record).prefix, max_chcharge].join("") if record.form.get_question("chcharge", record).present?
min_chcharge = [record.form.get_question("chcharge", record).prefix, min_chcharge].join("") if record.form.get_question("chcharge", record).present? min_chcharge = [record.form.get_question("chcharge", record).prefix, min_chcharge].join("") if record.form.get_question("chcharge", record).present?
record.errors.add :period, I18n.t("validations.financial.carehome.out_of_range", period:, min_chcharge:, max_chcharge:) record.errors.add :period, I18n.t("validations.financial.carehome.out_of_range", period:, min_chcharge:, max_chcharge:)
record.errors.add :chcharge, I18n.t("validations.financial.carehome.out_of_range", period:, min_chcharge:, max_chcharge:) record.errors.add :chcharge, :out_of_range, message: I18n.t("validations.financial.carehome.out_of_range", period:, min_chcharge:, max_chcharge:)
end end
end end
end end

5
app/services/imports/lettings_logs_import_service.rb

@ -390,6 +390,11 @@ module Imports
@logs_overridden << lettings_log.old_id @logs_overridden << lettings_log.old_id
%w[location_id scheme_id].each { |name| attributes.delete(name) } %w[location_id scheme_id].each { |name| attributes.delete(name) }
save_lettings_log(attributes, previous_status) save_lettings_log(attributes, previous_status)
elsif lettings_log.errors.of_kind?(:chcharge, :out_of_range)
@logger.warn("Log #{lettings_log.old_id}: Removing chcharge, because it is outside the expected range/")
@logs_overridden << lettings_log.old_id
attributes.delete("chcharge")
save_lettings_log(attributes, previous_status)
else else
@logger.error("Log #{lettings_log.old_id}: Failed to import") @logger.error("Log #{lettings_log.old_id}: Failed to import")
lettings_log.errors.each do |error| lettings_log.errors.each do |error|

31
spec/services/imports/lettings_logs_import_service_spec.rb

@ -694,6 +694,37 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
end end
context "and carehome charges are out of range" do
let(:lettings_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" }
before do
scheme1.update!(registered_under_care_act: 2)
lettings_log_xml.at_xpath("//xmlns:Q18b").content = "2000"
lettings_log_xml.at_xpath("//xmlns:Q17").content = "1"
lettings_log_xml.at_xpath("//xmlns:Q18ai").content = ""
lettings_log_xml.at_xpath("//xmlns:Q18aii").content = ""
lettings_log_xml.at_xpath("//xmlns:Q18aiii").content = ""
lettings_log_xml.at_xpath("//xmlns:Q18aiv").content = ""
lettings_log_xml.at_xpath("//xmlns:Q18av").content = ""
end
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing chcharge, because it is outside the expected range/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error
end
it "clears out the chcharge answer" 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.chcharge).to be_nil
end
end
context "and the net income soft validation is triggered (net_income_value_check)" do context "and the net income soft validation is triggered (net_income_value_check)" do
before do before do
lettings_log_xml.at_xpath("//xmlns:Q8a").content = "1 Weekly" lettings_log_xml.at_xpath("//xmlns:Q8a").content = "1 Weekly"

Loading…
Cancel
Save