Browse Source

Fix import with income 2 outside of london validation

pull/1609/head
Kat 3 years ago
parent
commit
2ac9ba3887
  1. 2
      app/models/validations/sales/financial_validations.rb
  2. 1
      app/services/imports/sales_logs_import_service.rb
  3. 26
      spec/services/imports/sales_logs_import_service_spec.rb

2
app/models/validations/sales/financial_validations.rb

@ -20,7 +20,7 @@ module Validations::Sales::FinancialValidations
if record.london_property? && record.income2 > 90_000 if record.london_property? && record.income2 > 90_000
relevant_fields.each { |field| record.errors.add field, :over_hard_max_for_london, message: I18n.t("validations.financial.income.over_hard_max_for_london") } relevant_fields.each { |field| record.errors.add field, :over_hard_max_for_london, message: I18n.t("validations.financial.income.over_hard_max_for_london") }
elsif record.property_not_in_london? && record.income2 > 80_000 elsif record.property_not_in_london? && record.income2 > 80_000
relevant_fields.each { |field| record.errors.add field, I18n.t("validations.financial.income.over_hard_max_for_outside_london") } relevant_fields.each { |field| record.errors.add field, :over_hard_max_for_outside_london, message: I18n.t("validations.financial.income.over_hard_max_for_outside_london") }
end end
end end

1
app/services/imports/sales_logs_import_service.rb

@ -225,6 +225,7 @@ module Imports
%i[exdate over_a_year_from_saledate] => %w[exdate], %i[exdate over_a_year_from_saledate] => %w[exdate],
%i[income1 over_hard_max_for_outside_london] => %w[income1], %i[income1 over_hard_max_for_outside_london] => %w[income1],
%i[income1 over_hard_max_for_london] => %w[income1], %i[income1 over_hard_max_for_london] => %w[income1],
%i[income2 over_hard_max_for_outside_london] => %w[income2],
%i[income2 over_hard_max_for_london] => %w[income2], %i[income2 over_hard_max_for_london] => %w[income2],
%i[equity over_max] => %w[equity], %i[equity over_max] => %w[equity],
%i[equity under_min] => %w[equity], %i[equity under_min] => %w[equity],

26
spec/services/imports/sales_logs_import_service_spec.rb

@ -795,6 +795,32 @@ RSpec.describe Imports::SalesLogsImportService do
end end
end end
context "and it has an invalid income 2" do
let(:sales_log_id) { "shared_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:Q2Person1Income").content = "0"
sales_log_xml.at_xpath("//xmlns:Q2Person2Income").content = "95000"
sales_log_xml.at_xpath("//xmlns:Q14ONSLACode").content = "E07000223"
end
it "intercepts the relevant validation error" do
expect(logger).to receive(:warn).with(/Removing income2 with error: Combined income must be £80,000 or lower for properties outside London local authorities, Income must be £80,000 or lower for properties outside London local authority/)
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.income2).to be_nil
end
end
context "and it has an invalid income 1 for london" do context "and it has an invalid income 1 for london" do
let(:sales_log_id) { "shared_ownership_sales_log" } let(:sales_log_id) { "shared_ownership_sales_log" }

Loading…
Cancel
Save