Browse Source

Create an unassigned user per organisation (#1885)

pull/1886/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
2920917292
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/services/imports/lettings_logs_import_service.rb
  2. 6
      app/services/imports/sales_logs_import_service.rb
  3. 13
      spec/services/imports/lettings_logs_import_service_spec.rb
  4. 13
      spec/services/imports/sales_logs_import_service_spec.rb

4
app/services/imports/lettings_logs_import_service.rb

@ -253,8 +253,8 @@ module Imports
user = LegacyUser.find_by(old_user_id: owner_id)&.user
if user.blank?
@logger.error("Lettings log '#{attributes['old_id']}' belongs to legacy user with owner-user-id: '#{owner_id}' which cannot be found. Assigning log to 'Unassigned' user.")
if User.find_by(name: "Unassigned")
user = User.find_by(name: "Unassigned")
if User.find_by(name: "Unassigned", organisation_id: attributes["managing_organisation_id"])
user = User.find_by(name: "Unassigned", organisation_id: attributes["managing_organisation_id"])
else
user = User.new(
name: "Unassigned",

6
app/services/imports/sales_logs_import_service.rb

@ -181,12 +181,12 @@ module Imports
if user.blank?
@logger.error("Sales log '#{attributes['old_id']}' belongs to legacy user with owner-user-id: '#{owner_id}' which cannot be found. Assigning log to 'Unassigned' user.")
if User.find_by(name: "Unassigned")
user = User.find_by(name: "Unassigned")
if User.find_by(name: "Unassigned", organisation_id: attributes["owning_organisation_id"])
user = User.find_by(name: "Unassigned", organisation_id: attributes["owning_organisation_id"])
else
user = User.new(
name: "Unassigned",
organisation_id: attributes["managing_organisation_id"],
organisation_id: attributes["owning_organisation_id"],
is_dpo: false,
encrypted_password: SecureRandom.hex(10),
email: SecureRandom.uuid,

13
spec/services/imports/lettings_logs_import_service_spec.rb

@ -157,6 +157,19 @@ RSpec.describe Imports::LettingsLogsImportService do
second_lettings_log = LettingsLog.where(old_id: "fake_id").first
expect(lettings_log&.created_by).to eq(second_lettings_log&.created_by)
end
context "when unassigned user exist for a different organisation" do
let!(:other_unassigned_user) { create(:user, name: "Unassigned") }
it "creates a new unassigned user for current organisation" do
expect(logger).to receive(:error).with("Lettings log '0ead17cb-1668-442d-898c-0d52879ff592' belongs to legacy user with owner-user-id: 'fake_id' which cannot be found. Assigning log to 'Unassigned' user.")
lettings_log_service.send(:create_log, lettings_log_xml)
lettings_log = LettingsLog.where(old_id: lettings_log_id).first
expect(lettings_log&.created_by&.name).to eq("Unassigned")
expect(lettings_log&.created_by).not_to eq(other_unassigned_user)
end
end
end
it "correctly sets imported at date" do

13
spec/services/imports/sales_logs_import_service_spec.rb

@ -148,6 +148,19 @@ RSpec.describe Imports::SalesLogsImportService do
second_sales_log = SalesLog.where(old_id: "fake_id").first
expect(sales_log&.created_by).to eq(second_sales_log&.created_by)
end
context "when unassigned user exist for a different organisation" do
let!(:other_unassigned_user) { create(:user, name: "Unassigned") }
it "creates a new unassigned user for current organisation" do
expect(logger).to receive(:error).with("Sales log 'shared_ownership_sales_log' belongs to legacy user with owner-user-id: 'fake_id' which cannot be found. Assigning log to 'Unassigned' user.")
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.where(old_id: sales_log_id).first
expect(sales_log&.created_by&.name).to eq("Unassigned")
expect(sales_log&.created_by).not_to eq(other_unassigned_user)
end
end
end
context "and the log startdate is before 22/23 collection period" do

Loading…
Cancel
Save