Browse Source

Safely import schemes with empty `registered_under_care_act` values (#1075)

pull/1076/head v0.2.26
James Rose 2 years ago committed by GitHub
parent
commit
5aedb79bdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/services/imports/scheme_location_import_service.rb
  2. 16
      spec/services/imports/scheme_location_import_service_spec.rb

2
app/services/imports/scheme_location_import_service.rb

@ -79,7 +79,7 @@ module Imports
attributes = {} attributes = {}
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"] = safe_string_as_integer(xml_doc, "support-type")
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")

16
spec/services/imports/scheme_location_import_service_spec.rb

@ -170,7 +170,7 @@ RSpec.describe Imports::SchemeLocationImportService do
end end
end end
context "and the registered under care act value is missing" do context "and the registered under care act value is zero" do
before { location_xml.at_xpath("//scheme:reg-home-type").content = "0" } before { location_xml.at_xpath("//scheme:reg-home-type").content = "0" }
it "sets the registered under care act to nil" do it "sets the registered under care act to nil" do
@ -183,5 +183,19 @@ 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 the registered under care act value is missing" do
before { location_xml.at_xpath("//scheme:reg-home-type").content = "" }
it "sets the registered under care act to nil" do
location = location_service.create_scheme_location(location_xml)
expect(location.scheme.registered_under_care_act).to be_nil
end
it "sets the confirmed status to false" do
location = location_service.create_scheme_location(location_xml)
expect(location.scheme.confirmed).to be_falsey
end
end
end end
end end

Loading…
Cancel
Save