Browse Source

Blank invalid combined income and proplen values on migration (#1907)

* feat: clear invalid combine incomes

* feat: clear out of range proplen values
pull/1909/head
natdeanlewissoftwire 1 year ago committed by GitHub
parent
commit
213a4bf229
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/validations/sales/financial_validations.rb
  2. 5
      app/services/imports/sales_logs_import_service.rb
  3. 81
      spec/services/imports/sales_logs_import_service_spec.rb

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

@ -30,9 +30,9 @@ module Validations::Sales::FinancialValidations
combined_income = record.income1 + record.income2
relevant_fields = %i[income1 income2 ownershipsch uprn la postcode_full]
if record.london_property? && combined_income > 90_000
relevant_fields.each { |field| record.errors.add field, I18n.t("validations.financial.income.combined_over_hard_max_for_london") }
relevant_fields.each { |field| record.errors.add field, :over_combined_hard_max_for_london, message: I18n.t("validations.financial.income.combined_over_hard_max_for_london") }
elsif record.property_not_in_london? && combined_income > 80_000
relevant_fields.each { |field| record.errors.add field, I18n.t("validations.financial.income.combined_over_hard_max_for_outside_london") }
relevant_fields.each { |field| record.errors.add field, :over_combined_hard_max_for_outside_london, message: I18n.t("validations.financial.income.combined_over_hard_max_for_outside_london") }
end
end

5
app/services/imports/sales_logs_import_service.rb

@ -250,15 +250,20 @@ module Imports
%i[postcode_full postcodes_not_matching] => %w[ppcodenk ppostcode_full],
%i[exdate over_a_year_from_saledate] => %w[exdate],
%i[income1 over_hard_max_for_outside_london] => %w[income1],
%i[income1 over_combined_hard_max_for_outside_london] => %w[income1 income2],
%i[income1 over_hard_max_for_london] => %w[income1],
%i[income1 over_combined_hard_max_for_london] => %w[income1 income2],
%i[income2 over_hard_max_for_outside_london] => %w[income2],
%i[income2 over_combined_hard_max_for_outside_london] => %w[income1 income2],
%i[income2 over_hard_max_for_london] => %w[income2],
%i[income2 over_combined_hard_max_for_london] => %w[income1 income2],
%i[equity over_max] => %w[equity],
%i[equity under_min] => %w[equity],
%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],
%i[proplen outside_the_range] => %w[proplen],
}
errors.each do |(error, fields)|

81
spec/services/imports/sales_logs_import_service_spec.rb

@ -900,7 +900,7 @@ RSpec.describe Imports::SalesLogsImportService do
.not_to raise_error
end
it "clears out the referral answer" do
it "clears out the mortgage answer" do
allow(logger).to receive(:warn)
sales_log_service.send(:create_log, sales_log_xml)
@ -911,6 +911,29 @@ RSpec.describe Imports::SalesLogsImportService do
end
end
context "when proplen is out of range" do
let(:sales_log_id) { "shared_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:Q16aProplen2").content = "2000"
end
it "intercepts the relevant validation error" do
expect { sales_log_service.send(:create_log, sales_log_xml) }
.not_to raise_error
end
it "clears out the proplen answer" 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.proplen).to be_nil
end
end
context "and it has an invalid income 1" do
let(:sales_log_id) { "shared_ownership_sales_log" }
@ -961,6 +984,34 @@ RSpec.describe Imports::SalesLogsImportService do
end
end
context "and it has an invalid combined income outside london" do
let(:sales_log_id) { "shared_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:joint").content = "1 Yes"
sales_log_xml.at_xpath("//xmlns:Q2Person1Income").content = "45000"
sales_log_xml.at_xpath("//xmlns:P2IncKnown").content = "1 Yes"
sales_log_xml.at_xpath("//xmlns:Q2Person2Income").content = "40000"
sales_log_xml.at_xpath("//xmlns:Q14ONSLACode").content = "E07000223"
end
it "intercepts the relevant validation error" do
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.income1).to be_nil
expect(sales_log.income2).to be_nil
end
end
context "and it has an invalid income 1 for london" do
let(:sales_log_id) { "shared_ownership_sales_log" }
@ -1011,6 +1062,34 @@ RSpec.describe Imports::SalesLogsImportService do
end
end
context "and it has an invalid combined income for london" do
let(:sales_log_id) { "shared_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:joint").content = "1 Yes"
sales_log_xml.at_xpath("//xmlns:Q2Person1Income").content = "50000"
sales_log_xml.at_xpath("//xmlns:P2IncKnown").content = "1 Yes"
sales_log_xml.at_xpath("//xmlns:Q2Person2Income").content = "45000"
sales_log_xml.at_xpath("//xmlns:Q14ONSLACode").content = "E09000012"
end
it "intercepts the relevant validation error" do
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.income1).to be_nil
expect(sales_log.income2).to be_nil
end
end
context "and it has an invalid mscharge" do
let(:sales_log_id) { "shared_ownership_sales_log" }

Loading…
Cancel
Save