Browse Source

Import support type as missing (#1561)

* Import support type as missing

* Set support_type to nil if it's not given

* Fix casing
pull/1564/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
c5dc8ebd12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/services/imports/sales_logs_import_service.rb
  2. 9
      app/services/imports/scheme_location_import_service.rb
  3. 2
      spec/fixtures/imports/sales_logs/shared_ownership_sales_log.xml
  4. 2
      spec/services/imports/sales_logs_import_service_spec.rb
  5. 18
      spec/services/imports/scheme_location_import_service_spec.rb

2
app/services/imports/sales_logs_import_service.rb

@ -170,7 +170,7 @@ module Imports
attributes["ethnicbuy2"] = unsafe_string_as_integer(xml_doc, "P2Eth") attributes["ethnicbuy2"] = unsafe_string_as_integer(xml_doc, "P2Eth")
attributes["ethnic_group2"] = ethnic_group(attributes["ethnicbuy2"]) attributes["ethnic_group2"] = ethnic_group(attributes["ethnicbuy2"])
attributes["nationalbuy2"] = unsafe_string_as_integer(xml_doc, "P2Nat") attributes["nationalbuy2"] = unsafe_string_as_integer(xml_doc, "P2Nat")
attributes["buy2living"] = unsafe_string_as_integer(xml_doc, "buy2livein") attributes["buy2living"] = unsafe_string_as_integer(xml_doc, "BUY2LIVEIN")
attributes["staircasesale"] = unsafe_string_as_integer(xml_doc, "STAIRCASESALE") attributes["staircasesale"] = unsafe_string_as_integer(xml_doc, "STAIRCASESALE")
attributes["prevtenbuy2"] = unsafe_string_as_integer(xml_doc, "PREVTENBUY2") attributes["prevtenbuy2"] = unsafe_string_as_integer(xml_doc, "PREVTENBUY2")

9
app/services/imports/scheme_location_import_service.rb

@ -77,7 +77,7 @@ module Imports
attributes["scheme_type"] = safe_string_as_integer(xml_doc, "scheme-type") attributes["scheme_type"] = safe_string_as_integer(xml_doc, "scheme-type")
registered_under_care_act = safe_string_as_integer(xml_doc, "reg-home-type") registered_under_care_act = safe_string_as_integer(xml_doc, "reg-home-type")
attributes["registered_under_care_act"] = registered_under_care_act&.zero? ? nil : registered_under_care_act attributes["registered_under_care_act"] = registered_under_care_act&.zero? ? nil : registered_under_care_act
attributes["support_type"] = safe_string_as_integer(xml_doc, "support-type") attributes["support_type"] = support_type(xml_doc)
attributes["intended_stay"] = string_or_nil(xml_doc, "intended-stay") attributes["intended_stay"] = string_or_nil(xml_doc, "intended-stay")
attributes["mobility_type"] = string_or_nil(xml_doc, "mobility-type") attributes["mobility_type"] = string_or_nil(xml_doc, "mobility-type")
attributes["primary_client_group"] = string_or_nil(xml_doc, "client-group-1") attributes["primary_client_group"] = string_or_nil(xml_doc, "client-group-1")
@ -205,5 +205,12 @@ module Imports
date = string_or_nil(xml_doc, attribute) date = string_or_nil(xml_doc, attribute)
Time.zone.parse(date) if date Time.zone.parse(date) if date
end end
def support_type(xml_doc)
type = safe_string_as_integer(xml_doc, "support-type")
return unless type
Scheme::SUPPORT_TYPE.value?(type) ? type : 0
end
end end
end end

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

@ -24,7 +24,7 @@
<Q38OtherSale/> <Q38OtherSale/>
<company>2 No</company> <company>2 No</company>
<LiveInBuyer>1 Yes</LiveInBuyer> <LiveInBuyer>1 Yes</LiveInBuyer>
<buy2livein/> <BUY2LIVEIN/>
<joint>2 No</joint> <joint>2 No</joint>
<JointMore/> <JointMore/>
<PartAPurchaser>2 Yes</PartAPurchaser> <PartAPurchaser>2 Yes</PartAPurchaser>

2
spec/services/imports/sales_logs_import_service_spec.rb

@ -269,7 +269,7 @@ RSpec.describe Imports::SalesLogsImportService do
sales_log_xml.at_xpath("//xmlns:Q20Bedrooms").content = "2" 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:P2Eth").content = "2 White: Irish"
sales_log_xml.at_xpath("//xmlns:P2Nat").content = "18 United Kingdom" sales_log_xml.at_xpath("//xmlns:P2Nat").content = "18 United Kingdom"
sales_log_xml.at_xpath("//xmlns:buy2livein").content = "1" sales_log_xml.at_xpath("//xmlns:BUY2LIVEIN").content = "1"
end end
it "successfully creates a completed shared sale log" do it "successfully creates a completed shared sale log" do

18
spec/services/imports/scheme_location_import_service_spec.rb

@ -208,5 +208,23 @@ RSpec.describe Imports::SchemeLocationImportService do
expect(location.scheme.confirmed).to be_falsey expect(location.scheme.confirmed).to be_falsey
end end
end end
context "and support_type is not a valid one" do
before { location_xml.at_xpath("//scheme:support-type").content = "1" }
it "sets the support type to missing" do
location = location_service.create_scheme_location(location_xml)
expect(location.scheme.support_type).to eq("Missing")
end
end
context "and support_type is not answered" do
before { location_xml.at_xpath("//scheme:support-type").content = "" }
it "sets the support type to nil" do
location = location_service.create_scheme_location(location_xml)
expect(location.scheme.support_type).to eq(nil)
end
end
end end
end end

Loading…
Cancel
Save