From 0e38ebd4b651c925968de1e3eed132f5bf87649f Mon Sep 17 00:00:00 2001 From: James Rose Date: Mon, 14 Nov 2022 11:39:27 +0000 Subject: [PATCH] Parse user fields where namespace declarations aren't included (#989) We import XML files that define logs from the previous CORE service. For an unknown reason, some of these files don't include the required namespace declarations to parse `user` values. Instead of changing the source, this change introduces a new method that forces the namespace declaration for user fields. --- app/services/imports/user_import_service.rb | 2 +- ...d9b73aa1c88b6e5c36ee49be9050b923b4a1bb.xml | 19 +++++++++++++++++++ .../imports/user_import_service_spec.rb | 13 +++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/imports/user/80d9b73aa1c88b6e5c36ee49be9050b923b4a1bb.xml diff --git a/app/services/imports/user_import_service.rb b/app/services/imports/user_import_service.rb index f5a730479..9ab8f6886 100644 --- a/app/services/imports/user_import_service.rb +++ b/app/services/imports/user_import_service.rb @@ -45,7 +45,7 @@ module Imports end def user_field_value(xml_document, field) - field_value(xml_document, "user", field) + field_value(xml_document, "user", field, { "user" => "dclg:user" }) end def role(field_value) diff --git a/spec/fixtures/imports/user/80d9b73aa1c88b6e5c36ee49be9050b923b4a1bb.xml b/spec/fixtures/imports/user/80d9b73aa1c88b6e5c36ee49be9050b923b4a1bb.xml new file mode 100644 index 000000000..8fd86a5b1 --- /dev/null +++ b/spec/fixtures/imports/user/80d9b73aa1c88b6e5c36ee49be9050b923b4a1bb.xml @@ -0,0 +1,19 @@ + + 80d9b73aa1c88b6e5c36ee49be9050b923b4a1bb + Jane Doe + 7c5bd5fb549c09a2c55d7cb90d7ba84927e64618 + 1158 1158 + true + Data Provider + + false + false + false + None + jane.doe@gov.uk + REDACTED + Jane Doe + 01111 000000 + false + 2021-09-28Z + \ No newline at end of file diff --git a/spec/services/imports/user_import_service_spec.rb b/spec/services/imports/user_import_service_spec.rb index b8a831dbc..ea3388169 100644 --- a/spec/services/imports/user_import_service_spec.rb +++ b/spec/services/imports/user_import_service_spec.rb @@ -107,6 +107,19 @@ RSpec.describe Imports::UserImportService do end end + context "when the user does not have namespace bindings" do + let(:old_user_id) { "80d9b73aa1c88b6e5c36ee49be9050b923b4a1bb" } + + it "imports them succesfully" do + FactoryBot.create(:organisation, old_org_id:) + import_service.create_users("user_directory") + + user = LegacyUser.find_by(old_user_id:)&.user + expect(user.name).to eq("Jane Doe") + expect(user.email).to eq("jane.doe@gov.uk") + end + end + context "when a user has already been imported with that email" do let!(:org) { FactoryBot.create(:organisation, old_org_id:) } let!(:user) { FactoryBot.create(:user, :data_provider, organisation: org, email: "john.doe@gov.uk") }