Browse Source

feat: use old visible org id

pull/1850/head
natdeanlewissoftwire 3 years ago
parent
commit
b8645ca309
  1. 7
      app/services/imports/sales_logs_field_import_service.rb
  2. 6
      spec/services/imports/sales_logs_field_import_service_spec.rb

7
app/services/imports/sales_logs_field_import_service.rb

@ -43,9 +43,10 @@ module Imports
if record.owning_organisation_id.present?
@logger.info("sales log #{record.id} has a value for owning_organisation_id, skipping update")
else
owning_organisation_id = safe_string_as_integer(xml_doc, "OWNINGORGID")
record.update!(owning_organisation_id:)
@logger.info("sales log #{record.id}'s owning_organisation_id value has been set to #{owning_organisation_id}")
old_owning_organisation_id = safe_string_as_integer(xml_doc, "OWNINGORGID")
new_owning_organisation_id = Organisation.find_by(old_visible_id: old_owning_organisation_id).id
record.update!(owning_organisation_id: new_owning_organisation_id)
@logger.info("sales log #{record.id}'s owning_organisation_id value has been set to #{new_owning_organisation_id}")
end
else
@logger.warn("sales log with old id #{old_id} not found")

6
spec/services/imports/sales_logs_field_import_service_spec.rb

@ -9,7 +9,7 @@ RSpec.describe Imports::SalesLogsFieldImportService do
let(:fixture_directory) { "spec/fixtures/imports/sales_logs" }
let(:sales_log_filename) { "shared_ownership_sales_log" }
let(:sales_log_file) { File.open("#{fixture_directory}/#{sales_log_filename}.xml") }
let(:organisation) { create(:organisation, old_visible_id: "1", id: "1") }
let(:organisation) { create(:organisation, old_visible_id: "1", id: "101") }
let(:old_user_id) { "c3061a2e6ea0b702e6f6210d5c52d2a92612d2aa" }
let(:remote_folder) { "sales_logs" }
@ -88,9 +88,9 @@ RSpec.describe Imports::SalesLogsFieldImportService do
end
it "updates the sales_log owning_organisation_id value" do
expect(logger).to receive(:info).with(/sales log \d+'s owning_organisation_id value has been set to 1/)
expect(logger).to receive(:info).with(/sales log \d+'s owning_organisation_id value has been set to 101/)
expect { import_service.send(:update_field, field, remote_folder) }
.to(change { sales_log.reload.owning_organisation_id }.from(nil).to(1))
.to(change { sales_log.reload.owning_organisation_id }.from(nil).to(101))
end
end

Loading…
Cancel
Save