From 3a66137f5fbd57094f4b97dd542a0bcf85abfed2 Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 19 Apr 2023 11:12:16 +0100 Subject: [PATCH] Import support type as missing --- app/services/imports/scheme_location_import_service.rb | 7 ++++++- .../imports/scheme_location_import_service_spec.rb | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/services/imports/scheme_location_import_service.rb b/app/services/imports/scheme_location_import_service.rb index a26139aec..85ee06a40 100644 --- a/app/services/imports/scheme_location_import_service.rb +++ b/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") 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["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["mobility_type"] = string_or_nil(xml_doc, "mobility-type") attributes["primary_client_group"] = string_or_nil(xml_doc, "client-group-1") @@ -205,5 +205,10 @@ module Imports date = string_or_nil(xml_doc, attribute) Time.zone.parse(date) if date end + + def support_type(xml_doc) + type = safe_string_as_integer(xml_doc, "support-type") + Scheme::SUPPORT_TYPE.value?(type) ? type : 0 + end end end diff --git a/spec/services/imports/scheme_location_import_service_spec.rb b/spec/services/imports/scheme_location_import_service_spec.rb index 186fba818..053681e6d 100644 --- a/spec/services/imports/scheme_location_import_service_spec.rb +++ b/spec/services/imports/scheme_location_import_service_spec.rb @@ -208,5 +208,14 @@ RSpec.describe Imports::SchemeLocationImportService do expect(location.scheme.confirmed).to be_falsey 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 end end