Browse Source

Add remaining 23/24 import mappings

pull/1560/head
Kat 3 years ago
parent
commit
e210d2a72b
  1. 22
      app/services/imports/sales_logs_import_service.rb
  2. 1
      spec/fixtures/imports/sales_logs/outright_sale_sales_log.xml
  3. 9
      spec/fixtures/imports/sales_logs/shared_ownership_sales_log.xml
  4. 81
      spec/services/imports/sales_logs_import_service_spec.rb

22
app/services/imports/sales_logs_import_service.rb

@ -166,6 +166,18 @@ module Imports
attributes["address_line2"] = string_or_nil(xml_doc, "AddressLine2")
attributes["town_or_city"] = string_or_nil(xml_doc, "TownCity")
attributes["county"] = string_or_nil(xml_doc, "County")
attributes["proplen_asked"] = 0 if attributes["proplen"]&.positive?
attributes["proplen_asked"] = 1 if attributes["proplen"]&.zero?
attributes["prevshared"] = unsafe_string_as_integer(xml_doc, "PREVSHARED")
attributes["ethnicbuy2"] = unsafe_string_as_integer(xml_doc, "P2Eth")
attributes["ethnic_group2"] = ethnic_group(attributes["ethnicbuy2"])
attributes["nationalbuy2"] = unsafe_string_as_integer(xml_doc, "P2Nat")
attributes["buy2living"] = unsafe_string_as_integer(xml_doc, "buy2livein")
attributes["staircasesale"] = unsafe_string_as_integer(xml_doc, "STAIRCASESALE")
attributes["prevtenbuy2"] = unsafe_string_as_integer(xml_doc, "PREVTENBUY2")
end
# Sets the log creator
@ -297,7 +309,9 @@ module Imports
student_not_child_value_check
discounted_sale_value_check
buyer_livein_value_check
percentage_discount_value_check]
percentage_discount_value_check
uprn_known
uprn_confirmed]
end
def check_status_completed(sales_log, previous_status)
@ -476,12 +490,14 @@ module Imports
safe_string_as_decimal(xml_doc, "Q29MonthlyCharges")
when 2
safe_string_as_decimal(xml_doc, "Q37MonthlyCharges")
when 3
safe_string_as_decimal(xml_doc, "Q44MonthlyCharges")
end
end
def ownership_from_type(attributes)
case attributes["type"]
when 2, 24, 18, 16, 28, 31, 30
when 2, 24, 18, 16, 28, 31, 30, 32
1 # shared ownership
when 8, 14, 27, 9, 29, 21, 22
2 # discounted ownership
@ -564,6 +580,8 @@ module Imports
attributes["sex1"] ||= "R"
attributes["ethnic_group"] ||= 17
attributes["ethnic"] ||= 17
# attributes["ethnic_group2"] ||= 17
# attributes["ethnicbuy2"] ||= 17
attributes["national"] ||= 13
attributes["ecstat1"] ||= 10
attributes["income1nk"] ||= attributes["income1"].present? ? 0 : 1

1
spec/fixtures/imports/sales_logs/outright_sale_sales_log.xml vendored

@ -280,6 +280,7 @@
<Q41b/>
<Q42Borrowing/>
<Q43CashDeposit override-field="">300000</Q43CashDeposit>
<Q44MonthlyCharges/>
</Group>
<Group>
<HHMEMB>1</HHMEMB>

9
spec/fixtures/imports/sales_logs/shared_ownership_sales_log.xml vendored

@ -24,6 +24,7 @@
<Q38OtherSale/>
<company>2 No</company>
<LiveInBuyer>1 Yes</LiveInBuyer>
<buy2livein/>
<joint>2 No</joint>
<JointMore/>
<PartAPurchaser>2 Yes</PartAPurchaser>
@ -32,6 +33,12 @@
<Q11Bedrooms override-field="">2</Q11Bedrooms>
<Q12PropertyType>1 Flat or maisonette</Q12PropertyType>
<Q13BuildingType>1 Purpose built</Q13BuildingType>
<UPRN/>
<AddressLine1/>
<AddressLine2/>
<TownCity/>
<County/>
<PREVSHARED/>
<Q14Postcode override-field="">SW1A 1AA</Q14Postcode>
<Q14PropertyLocation>Westminster</Q14PropertyLocation>
<Q14ONSLACode>E09000033</Q14ONSLACode>
@ -47,6 +54,8 @@
<P2Sex override-field=""/>
<P2Rel/>
<P2Eco/>
<P2Eth/>
<P2Nat/>
<P3Age/>
<P3Sex override-field=""/>
<P3Rel/>

81
spec/services/imports/sales_logs_import_service_spec.rb

@ -220,6 +220,87 @@ RSpec.describe Imports::SalesLogsImportService do
end
end
context "with 23/24 logs" do
around do |example|
Timecop.freeze(Time.zone.local(2023, 4, 1)) do
Singleton.__init__(FormHandler)
example.run
end
Timecop.return
Singleton.__init__(FormHandler)
end
before do
sales_log_xml.at_xpath("//xmlns:DAY").content = "10"
sales_log_xml.at_xpath("//xmlns:MONTH").content = "4"
sales_log_xml.at_xpath("//xmlns:YEAR").content = "2023"
sales_log_xml.at_xpath("//xmlns:UPRN").content = ""
sales_log_xml.at_xpath("//xmlns:AddressLine1").content = "address 1"
sales_log_xml.at_xpath("//xmlns:AddressLine2").content = "address 2"
sales_log_xml.at_xpath("//xmlns:TownCity").content = "towncity"
sales_log_xml.at_xpath("//xmlns:County").content = "county"
sales_log_xml.at_xpath("//xmlns:Q14Postcode").content = "A1 1AA"
end
context "with outright sale type" do
let(:sales_log_id) { "outright_sale_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:Q44MonthlyCharges").content = "40"
end
it "successfully creates a completed outright sale log" do
expect(logger).not_to receive(:error)
expect(logger).not_to receive(:warn)
expect(logger).not_to receive(:info)
expect { sales_log_service.send(:create_log, sales_log_xml) }
.to change(SalesLog, :count).by(1)
end
end
context "with shared sale type" 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:JointMore").content = "2 No"
sales_log_xml.at_xpath("//xmlns:PREVSHARED").content = "1"
sales_log_xml.at_xpath("//xmlns:Q16aProplen2").content = "0"
sales_log_xml.at_xpath("//xmlns:Q20Bedrooms").content = "2"
sales_log_xml.at_xpath("//xmlns:P2Eth").content = "2 White: Irish"
sales_log_xml.at_xpath("//xmlns:P2Nat").content = "18 United Kingdom"
sales_log_xml.at_xpath("//xmlns:buy2livein").content = "1"
end
it "successfully creates a completed shared sale log" do
expect(logger).not_to receive(:error)
expect(logger).not_to receive(:warn)
expect(logger).not_to receive(:info)
expect { sales_log_service.send(:create_log, sales_log_xml) }
.to change(SalesLog, :count).by(1)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log.proplen_asked).to eq(1)
end
end
context "with discounted sale type" do
let(:sales_log_id) { "shared_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:PREVSHARED").content = "1"
sales_log_xml.at_xpath("//xmlns:Q20Bedrooms").content = "2"
end
it "successfully creates a completed shared sale log" do
expect(logger).not_to receive(:error)
expect(logger).not_to receive(:warn)
expect(logger).not_to receive(:info)
expect { sales_log_service.send(:create_log, sales_log_xml) }
.to change(SalesLog, :count).by(1)
end
end
end
context "and the mortgage soft validation is triggered (mortgage_value_check)" do
let(:sales_log_id) { "discounted_ownership_sales_log" }

Loading…
Cancel
Save