From 213a4bf2290a6ec2d0cdd587e16d4f6ba816ec6e Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Tue, 12 Sep 2023 13:45:01 +0100 Subject: [PATCH] Blank invalid combined income and proplen values on migration (#1907) * feat: clear invalid combine incomes * feat: clear out of range proplen values --- .../sales/financial_validations.rb | 4 +- .../imports/sales_logs_import_service.rb | 5 ++ .../imports/sales_logs_import_service_spec.rb | 81 ++++++++++++++++++- 3 files changed, 87 insertions(+), 3 deletions(-) diff --git a/app/models/validations/sales/financial_validations.rb b/app/models/validations/sales/financial_validations.rb index ffdee561a..82c57e75d 100644 --- a/app/models/validations/sales/financial_validations.rb +++ b/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 diff --git a/app/services/imports/sales_logs_import_service.rb b/app/services/imports/sales_logs_import_service.rb index 68d8e95ce..1a9fe54a0 100644 --- a/app/services/imports/sales_logs_import_service.rb +++ b/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)| diff --git a/spec/services/imports/sales_logs_import_service_spec.rb b/spec/services/imports/sales_logs_import_service_spec.rb index 2357618d0..e4d5b9473 100644 --- a/spec/services/imports/sales_logs_import_service_spec.rb +++ b/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" }