From 5aedb79bdf6d980da9582687e10372409c4ca2d3 Mon Sep 17 00:00:00 2001 From: James Rose Date: Fri, 9 Dec 2022 09:42:45 +0000 Subject: [PATCH] Safely import schemes with empty `registered_under_care_act` values (#1075) --- .../imports/scheme_location_import_service.rb | 2 +- .../scheme_location_import_service_spec.rb | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/services/imports/scheme_location_import_service.rb b/app/services/imports/scheme_location_import_service.rb index abd4a2f35..4a4292883 100644 --- a/app/services/imports/scheme_location_import_service.rb +++ b/app/services/imports/scheme_location_import_service.rb @@ -79,7 +79,7 @@ module Imports attributes = {} attributes["scheme_type"] = safe_string_as_integer(xml_doc, "scheme-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["intended_stay"] = string_or_nil(xml_doc, "intended-stay") attributes["mobility_type"] = string_or_nil(xml_doc, "mobility-type") diff --git a/spec/services/imports/scheme_location_import_service_spec.rb b/spec/services/imports/scheme_location_import_service_spec.rb index c11c2ca2d..e74067cae 100644 --- a/spec/services/imports/scheme_location_import_service_spec.rb +++ b/spec/services/imports/scheme_location_import_service_spec.rb @@ -170,7 +170,7 @@ RSpec.describe Imports::SchemeLocationImportService do 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" } 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 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