Browse Source

Clear age out of range for all people

pull/1479/head
Kat 3 years ago
parent
commit
1064b8dfa8
  1. 5
      app/services/imports/lettings_logs_import_service.rb
  2. 25
      spec/services/imports/lettings_logs_import_service_spec.rb

5
app/services/imports/lettings_logs_import_service.rb

@ -307,7 +307,6 @@ module Imports
%i[offered over_20] => { to_delete: %w[offered], message: "Removing offered as the value is above the maximum of 20" },
%i[earnings over_hard_max] => { to_delete: %w[ecstat1], message: "Removing working situation because income is too high for it" },
%i[tshortfall no_outstanding_charges] => { to_delete: %w[tshortfall hbrentshortfall], message: "Removing tshortfall as there are no outstanding charges" },
%i[age2 outside_the_range] => { to_delete: %w[age2 age2_known], message: "Removing age2 because it is outside the allowed range" },
%i[beds over_max] => { to_delete: %w[beds], message: "Removing number of bedrooms because it is over the max" },
%i[tcharge complete_1_of_3] => { to_delete: %w[brent scharge pscharge supcharg tcharge], message: "Removing charges, because multiple household charges are selected" },
%i[scharge under_min] => { to_delete: %w[brent scharge pscharge supcharg tcharge], message: "Removing charges, because service charge is under 0" },
@ -319,6 +318,10 @@ module Imports
%i[location_id not_active] => { to_delete: %w[location_id scheme_id], message: "Removing scheme and location because it was not active during the tenancy start date" },
}
(2..8).each do |person|
errors[["age#{person}".to_sym, :outside_the_range]] = { to_delete: ["age#{person}", "age#{person}_known"], message: "Removing age#{person} because it is outside the allowed range" }
end
errors.each do |(error, fields)|
next unless lettings_log.errors.of_kind?(*error)

25
spec/services/imports/lettings_logs_import_service_spec.rb

@ -466,6 +466,31 @@ RSpec.describe Imports::LettingsLogsImportService do
end
end
context "and age 3 over the max" do
before do
lettings_log_xml.at_xpath("//xmlns:P3Age").content = "121"
lettings_log_xml.at_xpath("//xmlns:P3Eco").content = "7"
lettings_log_xml.at_xpath("//xmlns:HHMEMB").content = "3"
end
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing age3 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 age 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.age3).to be_nil
expect(lettings_log.age3_known).to be_nil
end
end
context "and beds over the max" do
before do
lettings_log_xml.at_xpath("//xmlns:Q22").content = "13"

Loading…
Cancel
Save