Browse Source

clear age2 if it's out of range

pull/1479/head
Kat 3 years ago
parent
commit
b214ce41e9
  1. 2
      app/models/validations/shared_validations.rb
  2. 6
      app/services/imports/lettings_logs_import_service.rb
  3. 24
      spec/services/imports/lettings_logs_import_service_spec.rb

2
app/models/validations/shared_validations.rb

@ -120,7 +120,7 @@ private
max = [question.prefix, number_with_delimiter(question.max, delimiter: ","), question.suffix].join("") if question.max
if min && max
record.errors.add question.id.to_sym, I18n.t("validations.numeric.within_range", field:, min:, max:)
record.errors.add question.id.to_sym, :outside_the_range, message: I18n.t("validations.numeric.within_range", field:, min:, max:)
elsif min
record.errors.add question.id.to_sym, I18n.t("validations.numeric.above_min", field:, min:)
end

6
app/services/imports/lettings_logs_import_service.rb

@ -338,6 +338,12 @@ module Imports
attributes.delete("tshortfall")
attributes.delete("hbrentshortfall")
save_lettings_log(attributes, previous_status)
elsif lettings_log.errors.of_kind?(:age2, :outside_the_range)
@logger.warn("Log #{lettings_log.old_id}: Removing age2 because it is outside the allowed range")
@logs_overridden << lettings_log.old_id
attributes.delete("age2")
attributes.delete("age2_known")
save_lettings_log(attributes, previous_status)
else
@logger.error("Log #{lettings_log.old_id}: Failed to import")
lettings_log.errors.each do |error|

24
spec/services/imports/lettings_logs_import_service_spec.rb

@ -441,6 +441,30 @@ RSpec.describe Imports::LettingsLogsImportService do
end
end
context "and age over the max" do
before do
lettings_log_xml.at_xpath("//xmlns:P2Age").content = "121"
lettings_log_xml.at_xpath("//xmlns:P2Eco").content = "7"
end
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing age2 because it is outside the allowed range/)
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.age2).to be_nil
expect(lettings_log.age2_known).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