Browse Source

Clear charges if there are carehome charges given

pull/1479/head
Kat 3 years ago
parent
commit
3f44d1855d
  1. 2
      app/models/validations/financial_validations.rb
  2. 8
      app/services/imports/lettings_logs_import_service.rb
  3. 32
      spec/services/imports/lettings_logs_import_service_spec.rb

2
app/models/validations/financial_validations.rb

@ -89,7 +89,7 @@ module Validations::FinancialValidations
answered_questions = [record.tcharge, record.chcharge].concat(record.household_charge && record.household_charge == 1 ? [record.household_charge] : [])
if answered_questions.count(&:present?) > 1
record.errors.add :tcharge, I18n.t("validations.financial.charges.complete_1_of_3") if record.tcharge.present?
record.errors.add :tcharge, :complete_1_of_3, message: I18n.t("validations.financial.charges.complete_1_of_3") if record.tcharge.present?
record.errors.add :chcharge, I18n.t("validations.financial.charges.complete_1_of_3") if record.chcharge.present?
record.errors.add :household_charge, I18n.t("validations.financial.charges.complete_1_of_3") if record.household_charge.present?
end

8
app/services/imports/lettings_logs_import_service.rb

@ -349,6 +349,14 @@ module Imports
@logs_overridden << lettings_log.old_id
attributes.delete("beds")
save_lettings_log(attributes, previous_status)
elsif lettings_log.errors.of_kind?(:tcharge, :complete_1_of_3)
@logger.warn("Log #{lettings_log.old_id}: Removing charges, because multiple household charges are selected/")
@logs_overridden << lettings_log.old_id
attributes.delete("brent")
attributes.delete("scharge")
attributes.delete("pscharge")
attributes.delete("supcharg")
save_lettings_log(attributes, previous_status)
else
@logger.error("Log #{lettings_log.old_id}: Failed to import")
lettings_log.errors.each do |error|

32
spec/services/imports/lettings_logs_import_service_spec.rb

@ -198,7 +198,7 @@ RSpec.describe Imports::LettingsLogsImportService do
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing field age2 from log triggering validation: Answer cannot be over 16/)
expect(logger).to receive(:warn).with(/Removing field age2 from log triggering validation: Person 2’s age must be between/)
expect(logger).to receive(:warn).with(/Removing field age2 from log triggering validation: outside_the_range/)
expect(logger).to receive(:warn).with(/Removing field ecstat2 from log triggering validation: Answer cannot be ‘child under 16’/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error
@ -487,6 +487,36 @@ RSpec.describe Imports::LettingsLogsImportService do
end
end
context "and carehome charges and other charges are entered" do
let(:lettings_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" }
before do
lettings_log_xml.at_xpath("//xmlns:Q18b").content = "20"
lettings_log_xml.at_xpath("//xmlns:Q18c").content = ""
lettings_log_xml.at_xpath("//xmlns:Q18ai").content = ""
lettings_log_xml.at_xpath("//xmlns:Q18aii").content = "0"
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 charges, because multiple household charges are selected/)
expect { lettings_log_service.send(:create_log, lettings_log_xml) }
.not_to raise_error
end
it "clears out the referral 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.tcharge).to be_nil
end
end
context "and the net income soft validation is triggered (net_income_value_check)" do
before do
lettings_log_xml.at_xpath("//xmlns:Q8a").content = "1 Weekly"

Loading…
Cancel
Save