Browse Source

Log user email address if validation fails on user import

pull/1883/head
Kat 3 years ago
parent
commit
e1ba41d34e
  1. 12
      app/services/imports/user_import_service.rb
  2. 16
      spec/services/imports/user_import_service_spec.rb

12
app/services/imports/user_import_service.rb

@ -39,9 +39,15 @@ module Imports
user.active = user_field_value(xml_document, "active") user.active = user_field_value(xml_document, "active")
user.skip_confirmation_notification! user.skip_confirmation_notification!
user.save!
user.legacy_users.create!(old_user_id:) begin
user user.save!
user.legacy_users.create!(old_user_id:)
user
rescue ActiveRecord::RecordInvalid => e
@logger.error(e.message)
@logger.error("Could not save user with email: #{email}")
end
end end
end end

16
spec/services/imports/user_import_service_spec.rb

@ -44,10 +44,24 @@ RSpec.describe Imports::UserImportService do
end end
it "refuses to create a user belonging to a non existing organisation" do it "refuses to create a user belonging to a non existing organisation" do
expect(logger).to receive(:error).with(/ActiveRecord::RecordInvalid/) expect(logger).to receive(:error).with(/Could not save user with email: john.doe@gov.uk/)
expect(logger).to receive(:error).with(/Validation failed: Organisation Select the user’s organisation/)
import_service.create_users("user_directory") import_service.create_users("user_directory")
end end
context "when the user with the same email already exists" do
before do
create(:organisation, old_org_id:)
create(:user, email: "john.doe@gov.uk")
end
it "logs an error and user email" do
expect(logger).to receive(:error).with(/Could not save user with email: john.doe@gov.uk/)
expect(logger).to receive(:error).with(/Validation failed: email Enter an email address that hasn’t already been used to sign up/)
import_service.create_users("user_directory")
end
end
context "when the user is a data coordinator" do context "when the user is a data coordinator" do
let(:old_user_id) { "d4729b1a5dfb68bb1e01c08445830c0add40907c" } let(:old_user_id) { "d4729b1a5dfb68bb1e01c08445830c0add40907c" }

Loading…
Cancel
Save