diff --git a/app/services/imports/sales_logs_import_service.rb b/app/services/imports/sales_logs_import_service.rb index 59ce65d60..bc39fcb16 100644 --- a/app/services/imports/sales_logs_import_service.rb +++ b/app/services/imports/sales_logs_import_service.rb @@ -238,6 +238,7 @@ module Imports %i[mscharge under_min] => %w[mscharge has_mscharge], %i[mortgage cannot_be_0] => %w[mortgage], %i[frombeds outside_the_range] => %w[frombeds], + %i[age1 outside_the_range] => %w[age1 age1_known], } errors.each do |(error, fields)| diff --git a/spec/services/imports/sales_logs_import_service_spec.rb b/spec/services/imports/sales_logs_import_service_spec.rb index 295d727e8..aed2b1124 100644 --- a/spec/services/imports/sales_logs_import_service_spec.rb +++ b/spec/services/imports/sales_logs_import_service_spec.rb @@ -961,6 +961,31 @@ RSpec.describe Imports::SalesLogsImportService do end end + context "and it has an invalid age1" do + let(:sales_log_id) { "shared_ownership_sales_log" } + + before do + sales_log_xml.at_xpath("//xmlns:P1Age").content = "1" + end + + it "intercepts the relevant validation error" do + expect(logger).to receive(:warn).with(/Removing age1 with error: Lead buyer’s age must be between 16 and 110/) + expect(logger).to receive(:warn).with(/Removing age1_known with error: Lead buyer’s age must be between 16 and 110/) + expect { sales_log_service.send(:create_log, sales_log_xml) } + .not_to raise_error + end + + it "clears out the invalid answers" do + allow(logger).to receive(:warn) + + sales_log_service.send(:create_log, sales_log_xml) + sales_log = SalesLog.find_by(old_id: sales_log_id) + + expect(sales_log).not_to be_nil + expect(sales_log.age1).to be_nil + end + end + context "when inferring default answers for completed sales logs" do context "when the armedforcesspouse is not answered" do let(:sales_log_id) { "discounted_ownership_sales_log" }