diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index 3a0014119..59a5f716a 100644 --- a/app/models/validations/financial_validations.rb +++ b/app/models/validations/financial_validations.rb @@ -99,7 +99,7 @@ module Validations::FinancialValidations end if record.tcharge.present? && weekly_value_in_range(record, "tcharge", 0, 9.99) - record.errors.add :tcharge, I18n.t("validations.financial.tcharge.under_10") + record.errors.add :tcharge, :under_10, message: I18n.t("validations.financial.tcharge.under_10") end answered_questions = [record.tcharge, record.chcharge].concat(record.household_charge && record.household_charge == 1 ? [record.household_charge] : []) diff --git a/app/services/imports/lettings_logs_import_service.rb b/app/services/imports/lettings_logs_import_service.rb index 94fb2ec3e..9a30ed689 100644 --- a/app/services/imports/lettings_logs_import_service.rb +++ b/app/services/imports/lettings_logs_import_service.rb @@ -302,6 +302,7 @@ module Imports %i[supcharg outside_the_range] => %w[brent scharge pscharge supcharg tcharge], %i[scharge outside_the_range] => %w[brent scharge pscharge supcharg tcharge], %i[location_id not_active] => %w[location_id scheme_id], + %i[tcharge under_10] => %w[brent scharge pscharge supcharg tcharge], } (2..8).each do |person| diff --git a/spec/services/imports/lettings_logs_import_service_spec.rb b/spec/services/imports/lettings_logs_import_service_spec.rb index deccde0c0..648ebbd67 100644 --- a/spec/services/imports/lettings_logs_import_service_spec.rb +++ b/spec/services/imports/lettings_logs_import_service_spec.rb @@ -719,6 +719,36 @@ RSpec.describe Imports::LettingsLogsImportService do end end + context "and tcharge is less than £10 per week" do + before do + lettings_log_xml.at_xpath("//xmlns:Q18ai").content = "1" + lettings_log_xml.at_xpath("//xmlns:Q18aii").content = "2" + lettings_log_xml.at_xpath("//xmlns:Q18aiii").content = "3" + lettings_log_xml.at_xpath("//xmlns:Q18aiv").content = "3" + lettings_log_xml.at_xpath("//xmlns:Q18av").content = "9" + end + + it "intercepts the relevant validation error" do + expect(logger).to receive(:warn).with(/Removing brent with error: Enter a total charge that is at least £10 per week/) + expect(logger).to receive(:warn).with(/Removing scharge with error: Enter a total charge that is at least £10 per week/) + expect(logger).to receive(:warn).with(/Removing pscharge with error: Enter a total charge that is at least £10 per week/) + expect(logger).to receive(:warn).with(/Removing supcharg with error: Enter a total charge that is at least £10 per week/) + expect(logger).to receive(:warn).with(/Removing tcharge with error: Enter a total charge that is at least £10 per week/) + expect { lettings_log_service.send(:create_log, lettings_log_xml) } + .not_to raise_error + end + + it "clears out the charges 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.tcharge).to be_nil + end + end + context "and location is not active during the period" do let(:lettings_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" }