From f1d14c2b6e830ffdc6e1473b58fae7c0300729bd Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 20 Mar 2023 13:06:47 +0000 Subject: [PATCH] infer soctenant values if not given --- .../imports/sales_logs_import_service.rb | 15 ++------- .../imports/sales_logs_import_service_spec.rb | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/app/services/imports/sales_logs_import_service.rb b/app/services/imports/sales_logs_import_service.rb index 11ff11c0e..e8cc9d82f 100644 --- a/app/services/imports/sales_logs_import_service.rb +++ b/app/services/imports/sales_logs_import_service.rb @@ -124,7 +124,7 @@ module Imports attributes["mortgagelenderother"] = mortgage_lender_other(xml_doc, attributes) attributes["postcode_full"] = parse_postcode(string_or_nil(xml_doc, "Q14Postcode")) attributes["pcodenk"] = 0 if attributes["postcode_full"].present? # known if given - attributes["soctenant"] = soctenant(attributes) + attributes["soctenant"] = 0 if attributes["ownershipsch"] == 1 attributes["ethnic_group2"] = nil # 23/24 variable attributes["ethnicbuy2"] = nil # 23/24 variable attributes["prevshared"] = nil # 23/24 variable @@ -364,17 +364,6 @@ module Imports end end - def soctenant(attributes) - return nil unless attributes["ownershipsch"] == 1 - - if attributes["frombeds"].blank? && attributes["fromprop"].blank? && attributes["socprevten"].blank? - 2 - else - 1 - end - # NO (2) if FROMBEDS, FROMPROP and socprevten are blank, and YES(1) if they are completed - end - def still_serving(xml_doc) case unsafe_string_as_integer(xml_doc, "LeftArmedF") when 4 @@ -511,6 +500,8 @@ module Imports attributes["pcodenk"] ||= 1 attributes["prevten"] ||= 0 attributes["extrabor"] ||= 3 if attributes["mortgageused"] == 1 + attributes["socprevten"] ||= 10 if attributes["ownershipsch"] == 1 + attributes["fromprop"] ||= 0 if attributes["ownershipsch"] == 1 # buyer 1 characteristics attributes["age1_known"] ||= 1 diff --git a/spec/services/imports/sales_logs_import_service_spec.rb b/spec/services/imports/sales_logs_import_service_spec.rb index b85cae0b0..000bb6f53 100644 --- a/spec/services/imports/sales_logs_import_service_spec.rb +++ b/spec/services/imports/sales_logs_import_service_spec.rb @@ -1142,6 +1142,38 @@ RSpec.describe Imports::SalesLogsImportService do expect(sales_log&.extrabor).to be(3) end end + + context "when the fromprop is not answered" do + let(:sales_log_id) { "shared_ownership_sales_log" } + + before do + sales_log_xml.at_xpath("//xmlns:Q21PropertyType").content = "" + allow(logger).to receive(:warn).and_return(nil) + end + + it "sets fromprop to don't know" do + sales_log_service.send(:create_log, sales_log_xml) + + sales_log = SalesLog.find_by(old_id: sales_log_id) + expect(sales_log&.fromprop).to be(0) + end + end + + context "when the socprevten is not answered" do + let(:sales_log_id) { "shared_ownership_sales_log" } + + before do + sales_log_xml.at_xpath("//xmlns:PrevRentType").content = "" + allow(logger).to receive(:warn).and_return(nil) + end + + it "sets socprevten to don't know" do + sales_log_service.send(:create_log, sales_log_xml) + + sales_log = SalesLog.find_by(old_id: sales_log_id) + expect(sales_log&.socprevten).to be(10) + end + end end end end