Browse Source

Assume mortgage is used if information about it is given

pull/1379/head
Kat 3 years ago
parent
commit
88f59312db
  1. 13
      app/services/imports/sales_logs_import_service.rb
  2. 53
      spec/services/imports/sales_logs_import_service_spec.rb

13
app/services/imports/sales_logs_import_service.rb

@ -110,7 +110,7 @@ module Imports
attributes["prevten"] = unsafe_string_as_integer(xml_doc, "Q6PrevTenure")
attributes["mortlen"] = mortgage_length(xml_doc, attributes)
attributes["extrabor"] = borrowing(xml_doc, attributes)
attributes["mortgageused"] = unsafe_string_as_integer(xml_doc, "MORTGAGEUSED")
attributes["mortgageused"] = mortgage_used(xml_doc, attributes)
attributes["wchair"] = unsafe_string_as_integer(xml_doc, "Q15Wheelchair")
attributes["armedforcesspouse"] = unsafe_string_as_integer(xml_doc, "ARMEDFORCESSPOUSE")
attributes["hodate"] = compose_date(xml_doc, "HODAY", "HOMONTH", "HOYEAR")
@ -444,6 +444,17 @@ module Imports
UKPostcode.parse(postcode).to_s
end
def mortgage_used(xml_doc, attributes)
mortgageused = unsafe_string_as_integer(xml_doc, "MORTGAGEUSED")
return mortgageused unless mortgageused == 3
if attributes["mortgage"].present? || attributes["mortlen"].present? || attributes["extrabor"].present?
1 # yes
else
3 # don't know
end
end
def set_default_values(attributes)
attributes["armedforcesspouse"] ||= 7
attributes["hhregres"] ||= 8

53
spec/services/imports/sales_logs_import_service_spec.rb

@ -829,6 +829,59 @@ RSpec.describe Imports::SalesLogsImportService do
expect(sales_log&.prevten).to eq(2)
end
end
context "when mortgage used is don't know" do
let(:sales_log_id) { "discounted_ownership_sales_log" }
before do
allow(logger).to receive(:warn).and_return(nil)
end
it "sets mortgageused to don't know if mortlen, mortgage and extrabor are blank" do
sales_log_xml.at_xpath("//xmlns:MORTGAGEUSED").content = "3 Don't know"
sales_log_xml.at_xpath("//xmlns:Q35Borrowing").content = ""
sales_log_xml.at_xpath("//xmlns:Q34b").content = ""
sales_log_xml.at_xpath("//xmlns:CALCMORT").content = ""
sales_log_xml.at_xpath("//xmlns:Q36CashDeposit").content = "134750"
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.mortgageused).to eq(3)
end
it "sets mortgageused to yes if mortgage is given" do
sales_log_xml.at_xpath("//xmlns:MORTGAGEUSED").content = "3 Don't know"
sales_log_xml.at_xpath("//xmlns:Q35Borrowing").content = ""
sales_log_xml.at_xpath("//xmlns:Q34b").content = ""
sales_log_xml.at_xpath("//xmlns:CALCMORT").content = "134750"
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.mortgageused).to eq(1)
end
it "sets mortgageused to yes if mortlen is given" do
sales_log_xml.at_xpath("//xmlns:MORTGAGEUSED").content = "3 Don't know"
sales_log_xml.at_xpath("//xmlns:Q35Borrowing").content = ""
sales_log_xml.at_xpath("//xmlns:Q34b").content = "10"
sales_log_xml.at_xpath("//xmlns:CALCMORT").content = ""
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.mortgageused).to eq(1)
end
it "sets mortgageused to yes if extrabor is given" do
sales_log_xml.at_xpath("//xmlns:MORTGAGEUSED").content = "3 Don't know"
sales_log_xml.at_xpath("//xmlns:Q35Borrowing").content = "3000"
sales_log_xml.at_xpath("//xmlns:Q34b").content = ""
sales_log_xml.at_xpath("//xmlns:CALCMORT").content = ""
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.mortgageused).to eq(1)
end
end
end
end
end

Loading…
Cancel
Save