Browse Source

Clear fields on import validations (#1540)

* Clear charge values if they fail under_10 validation on import

* Clear charges if brent is over_hard_max when importing
pull/1541/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
5d36752d34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/validations/financial_validations.rb
  2. 2
      app/services/imports/lettings_logs_import_service.rb
  3. 72
      spec/services/imports/lettings_logs_import_service_spec.rb

4
app/models/validations/financial_validations.rb

@ -99,7 +99,7 @@ module Validations::FinancialValidations
end end
if record.tcharge.present? && weekly_value_in_range(record, "tcharge", 0, 9.99) 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 end
answered_questions = [record.tcharge, record.chcharge].concat(record.household_charge && record.household_charge == 1 ? [record.household_charge] : []) answered_questions = [record.tcharge, record.chcharge].concat(record.household_charge && record.household_charge == 1 ? [record.household_charge] : [])
@ -224,7 +224,7 @@ private
end end
if record.weekly_value(record["brent"]) > rent_range.hard_max if record.weekly_value(record["brent"]) > rent_range.hard_max
record.errors.add :brent, I18n.t("validations.financial.brent.above_hard_max") record.errors.add :brent, :over_hard_max, message: I18n.t("validations.financial.brent.above_hard_max")
record.errors.add :beds, I18n.t("validations.financial.brent.beds.above_hard_max") record.errors.add :beds, I18n.t("validations.financial.brent.beds.above_hard_max")
record.errors.add :la, I18n.t("validations.financial.brent.la.above_hard_max") record.errors.add :la, I18n.t("validations.financial.brent.la.above_hard_max")
record.errors.add :postcode_known, I18n.t("validations.financial.brent.postcode_known.above_hard_max") record.errors.add :postcode_known, I18n.t("validations.financial.brent.postcode_known.above_hard_max")

2
app/services/imports/lettings_logs_import_service.rb

@ -302,6 +302,8 @@ module Imports
%i[supcharg outside_the_range] => %w[brent scharge pscharge supcharg tcharge], %i[supcharg outside_the_range] => %w[brent scharge pscharge supcharg tcharge],
%i[scharge 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[location_id not_active] => %w[location_id scheme_id],
%i[tcharge under_10] => %w[brent scharge pscharge supcharg tcharge],
%i[brent over_hard_max] => %w[brent scharge pscharge supcharg tcharge],
} }
(2..8).each do |person| (2..8).each do |person|

72
spec/services/imports/lettings_logs_import_service_spec.rb

@ -719,6 +719,78 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
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 rent is higher than the absolute maximum expected for a property " do
before do
LaRentRange.create!(
ranges_rent_id: "2",
la: "E08000035",
beds: 2,
lettype: 1,
soft_min: 12.41,
soft_max: 89.54,
hard_min: 9.87,
hard_max: 100.99,
start_year: 2021,
)
lettings_log_xml.at_xpath("//xmlns:Q18ai").content = "500"
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 = "508"
end
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with("Log 0ead17cb-1668-442d-898c-0d52879ff592: Removing brent with error: Rent is higher than the absolute maximum expected for a property of this type. Please check the rent, rent period, local authority and (if general needs) number of bedrooms")
expect(logger).to receive(:warn).with("Log 0ead17cb-1668-442d-898c-0d52879ff592: Removing scharge with error: Rent is higher than the absolute maximum expected for a property of this type. Please check the rent, rent period, local authority and (if general needs) number of bedrooms")
expect(logger).to receive(:warn).with("Log 0ead17cb-1668-442d-898c-0d52879ff592: Removing pscharge with error: Rent is higher than the absolute maximum expected for a property of this type. Please check the rent, rent period, local authority and (if general needs) number of bedrooms")
expect(logger).to receive(:warn).with("Log 0ead17cb-1668-442d-898c-0d52879ff592: Removing supcharg with error: Rent is higher than the absolute maximum expected for a property of this type. Please check the rent, rent period, local authority and (if general needs) number of bedrooms")
expect(logger).to receive(:warn).with("Log 0ead17cb-1668-442d-898c-0d52879ff592: Removing tcharge with error: Rent is higher than the absolute maximum expected for a property of this type. Please check the rent, rent period, local authority and (if general needs) number of bedrooms")
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 context "and location is not active during the period" do
let(:lettings_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" } let(:lettings_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" }

Loading…
Cancel
Save