diff --git a/app/services/imports/scheme_location_import_service.rb b/app/services/imports/scheme_location_import_service.rb index 85ee06a40..93093e6da 100644 --- a/app/services/imports/scheme_location_import_service.rb +++ b/app/services/imports/scheme_location_import_service.rb @@ -208,6 +208,8 @@ module Imports 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 diff --git a/spec/services/imports/scheme_location_import_service_spec.rb b/spec/services/imports/scheme_location_import_service_spec.rb index 053681e6d..5c45a92aa 100644 --- a/spec/services/imports/scheme_location_import_service_spec.rb +++ b/spec/services/imports/scheme_location_import_service_spec.rb @@ -217,5 +217,14 @@ RSpec.describe Imports::SchemeLocationImportService do 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