Browse Source

Map mortgage lender and mortgage lender other

pull/1331/head
Kat 3 years ago
parent
commit
1be8023d13
  1. 67
      app/services/imports/sales_logs_import_service.rb
  2. 37
      spec/services/imports/sales_logs_import_service_spec.rb

67
app/services/imports/sales_logs_import_service.rb

@ -116,7 +116,7 @@ module Imports
attributes["fromprop"] = unsafe_string_as_integer(xml_doc, "Q21PropertyType")
attributes["socprevten"] = unsafe_string_as_integer(xml_doc, "PrevRentType")
attributes["mortgagelender"] = mortgage_lender(xml_doc, attributes)
attributes["mortgagelenderother"] = nil # Q24AMORTGAGELENDEROTHER Q34AMORTGAGELENDEROTHER Q41AMORTGAGELENDEROTHER
attributes["mortgagelenderother"] = mortgage_lender_other(xml_doc, attributes)
attributes["mortlen"] = mortgage_length(xml_doc, attributes)
attributes["extrabor"] = borrowing(xml_doc, attributes)
attributes["totadult"] = safe_string_as_integer(xml_doc, "TOTADULT") # would get overridden
@ -232,15 +232,74 @@ module Imports
end
end
MORNTGAGE_LENDER_OPTIONS = {
"atom bank" => 1,
"barclays bank plc" => 2,
"bath building society" => 3,
"buckinghamshire building society" => 4,
"cambridge building society" => 5,
"coventry building society" => 6,
"cumberland building society" => 7,
"darlington building society" => 8,
"dudley building society" => 9,
"ecology building society" => 10,
"halifax" => 11,
"hanley economic building society" => 12,
"hinckley and rugby building society" => 13,
"holmesdale building society" => 14,
"ipswich building society" => 15,
"leeds building society" => 16,
"lloyds bank" => 17,
"mansfield building society" => 18,
"market harborough building society" => 19,
"melton mowbray building society" => 20,
"nationwide building society" => 21,
"natwest" => 22,
"nedbank private wealth" => 23,
"newbury building society" => 24,
"oneSavings bank" => 25,
"parity trust" => 26,
"penrith building society" => 27,
"pepper homeloans" => 28,
"royal bank of scotland" => 29,
"santander" => 30,
"skipton building society" => 31,
"teachers building society" => 32,
"the co-operative bank" => 33,
"tipton & coseley building society" => 34,
"tss" => 35,
"ulster bank" => 36,
"virgin money" => 37,
"west bromwich building society" => 38,
"yorkshire building society" => 39,
"other" => 40,
}.freeze
# this comes through as a string, need to map to a corresponding integer
def mortgage_lender(xml_doc, attributes)
lender = case attributes["ownershipsch"]
when 1
string_or_nil(xml_doc, "Q24aMortgageLender")
when 2
string_or_nil(xml_doc, "Q34a")
when 3
string_or_nil(xml_doc, "Q41aMortgageLender")
end
return if lender.blank?
MORNTGAGE_LENDER_OPTIONS[lender.downcase] || MORNTGAGE_LENDER_OPTIONS["other"]
end
def mortgage_lender_other(xml_doc, attributes)
return unless attributes["mortgagelender"] == MORNTGAGE_LENDER_OPTIONS["other"]
case attributes["ownershipsch"]
when 1
unsafe_string_as_integer(xml_doc, "Q24aMortgageLender")
string_or_nil(xml_doc, "Q24aMortgageLender")
when 2
unsafe_string_as_integer(xml_doc, "Q34a")
string_or_nil(xml_doc, "Q34a")
when 3
unsafe_string_as_integer(xml_doc, "Q41aMortgageLender")
string_or_nil(xml_doc, "Q41aMortgageLender")
end
end

37
spec/services/imports/sales_logs_import_service_spec.rb

@ -16,8 +16,8 @@ RSpec.describe Imports::SalesLogsImportService do
end
before do
WebMock.stub_request(:get, /api.postcodes.io\/postcodes/)
.to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Westminster","codes":{"admin_district":"E08000035"}}}', headers: {})
WebMock.stub_request(:get, /api.postcodes.io\/postcodes\/GL519EX/)
.to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Westminster","codes":{"admin_district":"E09000033"}}}', headers: {})
allow(Organisation).to receive(:find_by).and_return(nil)
allow(Organisation).to receive(:find_by).with(old_visible_id: organisation.old_visible_id).and_return(organisation)
@ -118,6 +118,39 @@ RSpec.describe Imports::SalesLogsImportService do
end
end
context "when the mortgage lender is set to an existing option" do
let(:sales_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" }
before do
sales_log_xml.at_xpath("//xmlns:Q34a").content = "halifax"
allow(logger).to receive(:warn).and_return(nil)
end
it "correctly sets mortgage lender" do
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.mortgagelender).to be(11)
end
end
context "when the mortgage lender is set to a non existing option" do
let(:sales_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" }
before do
sales_log_xml.at_xpath("//xmlns:Q34a").content = "something else"
allow(logger).to receive(:warn).and_return(nil)
end
it "correctly sets mortgage lender and mortgage lender other" do
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.mortgagelender).to be(40)
expect(sales_log&.mortgagelenderother).to eq("something else")
end
end
context "with shared ownership type" do
let(:sales_log_id) { "0ead17cb-1668-442d-898c-0d52879ff592" }

Loading…
Cancel
Save