Browse Source

Import location code

pull/1833/head
Kat 3 years ago
parent
commit
73698884eb
  1. 6
      app/services/imports/scheme_location_import_service.rb
  2. 13
      spec/services/imports/scheme_location_import_service_spec.rb

6
app/services/imports/scheme_location_import_service.rb

@ -26,6 +26,10 @@ module Imports
4 => "(Registered nursing care home)",
}.freeze
LA_NAME_TO_CODE = {
"134" => "E08000036",
}.freeze
def create_scheme(source_scheme, attributes)
scheme = Scheme.new(
scheme_type: attributes["scheme_type"],
@ -93,6 +97,7 @@ module Imports
attributes["location_old_id"] = string_or_nil(xml_doc, "id")
attributes["location_old_visible_id"] = string_or_nil(xml_doc, "visible-id")
attributes["scheme_old_id"] = string_or_nil(xml_doc, "mgmtgroup")
attributes["location_code"] = LA_NAME_TO_CODE[string_or_nil(xml_doc, "local-authority-name")]
attributes
end
@ -106,6 +111,7 @@ module Imports
old_visible_id: attributes["location_old_visible_id"],
old_id: attributes["location_old_id"],
startdate: attributes["start_date"],
location_code: attributes["location_code"],
scheme:,
)
if attributes["end_date"]

13
spec/services/imports/scheme_location_import_service_spec.rb

@ -17,7 +17,7 @@ RSpec.describe Imports::SchemeLocationImportService do
end
before do
WebMock.stub_request(:get, /api.postcodes.io\/postcodes/)
WebMock.stub_request(:get, /api.postcodes.io\/postcodes\/S446EJ/)
.to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Westminster","codes":{"admin_district":"E08000035"}}}', headers: {})
end
@ -143,6 +143,7 @@ RSpec.describe Imports::SchemeLocationImportService do
location = location_service.create_scheme_location(location_xml)
expect(location.name).to eq("Location 1")
expect(location.postcode).to eq("S44 6EJ")
expect(location.location_code).to eq("E08000035")
expect(location.units).to eq(5)
expect(location.mobility_type).to eq("Fitted with equipment and adaptations")
expect(location.type_of_unit).to eq("Bungalow")
@ -226,5 +227,15 @@ RSpec.describe Imports::SchemeLocationImportService do
expect(location.scheme.support_type).to eq(nil)
end
end
context "and postcode does not return a location code" do
before { location_xml.at_xpath("//scheme:postcode").content = "A1 1AA" }
it "imports location code correctly" do
location = location_service.create_scheme_location(location_xml)
expect(location.postcode).to eq("A1 1AA")
expect(location.location_code).to eq("E08000036")
end
end
end
end

Loading…
Cancel
Save