Browse Source

Do not raise an error if an incomplete log is missing location and scheme (#1565)

pull/1566/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
7d6374a338
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      app/services/imports/lettings_logs_import_service.rb
  2. 21
      spec/services/imports/lettings_logs_import_service_spec.rb

22
app/services/imports/lettings_logs_import_service.rb

@ -219,15 +219,19 @@ module Imports
schemes = Scheme.where(old_visible_id: scheme_old_visible_id, owning_organisation_id: attributes["owning_organisation_id"]) schemes = Scheme.where(old_visible_id: scheme_old_visible_id, owning_organisation_id: attributes["owning_organisation_id"])
location = Location.find_by(old_visible_id: location_old_visible_id, scheme: schemes) location = Location.find_by(old_visible_id: location_old_visible_id, scheme: schemes)
raise "No matching location for scheme #{scheme_old_visible_id} and location #{location_old_visible_id} (visible IDs)" if location.nil? if location.nil? && [location_old_visible_id, scheme_old_visible_id].all?(&:present?) && previous_status != "saved"
raise "No matching location for scheme #{scheme_old_visible_id} and location #{location_old_visible_id} (visible IDs)"
# Set the scheme via location, because the scheme old visible ID can be duplicated at import end
attributes["location_id"] = location.id
attributes["scheme_id"] = location.scheme.id if location.present?
attributes["sheltered"] = unsafe_string_as_integer(xml_doc, "Q1e") # Set the scheme via location, because the scheme old visible ID can be duplicated at import
attributes["chcharge"] = safe_string_as_decimal(xml_doc, "Q18b") attributes["location_id"] = location.id
attributes["household_charge"] = household_charge(xml_doc) attributes["scheme_id"] = location.scheme.id
attributes["is_carehome"] = is_carehome(location.scheme) attributes["sheltered"] = unsafe_string_as_integer(xml_doc, "Q1e")
attributes["chcharge"] = safe_string_as_decimal(xml_doc, "Q18b")
attributes["household_charge"] = household_charge(xml_doc)
attributes["is_carehome"] = is_carehome(location.scheme)
end
end end
# Handles confidential schemes # Handles confidential schemes

21
spec/services/imports/lettings_logs_import_service_spec.rb

@ -963,6 +963,27 @@ RSpec.describe Imports::LettingsLogsImportService do
end end
end end
context "and the scheme and location is not given" do
let(:lettings_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" }
before do
lettings_log_xml.at_xpath("//xmlns:_1cmangroupcode").content = ""
lettings_log_xml.at_xpath("//xmlns:_1cschemecode").content = ""
lettings_log_xml.at_xpath("//xmlns:Q25").content = ""
lettings_log_xml.at_xpath("//meta:status").content = "saved"
end
it "saves log without location and scheme" do
expect(logger).not_to receive(:warn)
lettings_log_service.send(:create_log, lettings_log_xml)
lettings_log = LettingsLog.find_by(old_id: lettings_log_id)
expect(lettings_log.scheme_id).to be_nil
expect(lettings_log.location_id).to be_nil
expect(lettings_log.status).to eq("in_progress")
end
end
context "and this is a supported housing log with a single location under a scheme" do context "and this is a supported housing log with a single location under a scheme" do
let(:lettings_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" } let(:lettings_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" }

Loading…
Cancel
Save