Browse Source

Import key contact field

pull/435/head
baarkerlounger 3 years ago
parent
commit
04cf89e91b
  1. 29
      app/services/imports/user_import_service.rb
  2. 13
      spec/fixtures/softwire_imports/users/d4729b1a5dfb68bb1e01c08445830c0add40907c.xml
  3. 13
      spec/fixtures/softwire_imports/users/d6717836154cd9a58f9e2f1d3077e3ab81e07613.xml
  4. 35
      spec/services/imports/user_import_service_spec.rb

29
app/services/imports/user_import_service.rb

@ -24,7 +24,9 @@ module Imports
phone: user_field_value(xml_document, "telephone-no"), phone: user_field_value(xml_document, "telephone-no"),
old_user_id:, old_user_id:,
organisation:, organisation:,
role: PROVIDER_TYPE[user_field_value(xml_document, "user-type")], role: role(user_field_value(xml_document, "user-type")),
is_dpo: is_dpo?(user_field_value(xml_document, "user-type")),
is_key_contact: is_key_contact?(user_field_value(xml_document, "contact-priority-id")),
) )
end end
end end
@ -32,5 +34,30 @@ module Imports
def user_field_value(xml_document, field) def user_field_value(xml_document, field)
field_value(xml_document, "user", field) field_value(xml_document, "user", field)
end end
def role(field_value)
return unless field_value
case field_value.downcase.strip
when "data provider"
"data_provider"
when "co-ordinator"
"data_coordinator"
when "private data downloader"
"data_accessor"
end
end
def is_dpo?(field_value)
return false unless field_value.present?
field_value.downcase.strip == "data protection officer"
end
def is_key_contact?(field_value)
return false unless field_value.present?
["ecore contact", "key performance contact"].include?(field_value.downcase.strip)
end
end end
end end

13
spec/fixtures/softwire_imports/users/d4729b1a5dfb68bb1e01c08445830c0add40907c.xml vendored

@ -0,0 +1,13 @@
<user:user xmlns:user="dclg:user">
<user:id>d4729b1a5dfb68bb1e01c08445830c0add40907c</user:id>
<user:password>xxx</user:password>
<user:full-name>John Doe</user:full-name>
<user:user-name>john.doe@gov.uk</user:user-name>
<user:institution>7c5bd5fb549c09a2c55d7cb90d7ba84927e64618</user:institution>
<user:email>john.doe@gov.uk</user:email>
<user:user-type>Co-ordinator</user:user-type>
<user:active>true</user:active>
<user:deleted>false</user:deleted>
<user:contact-priority-id>Key Performance Contact</user:contact-priority-id>
<user:telephone-no>02012345678</user:telephone-no>
</user:user>

13
spec/fixtures/softwire_imports/users/d6717836154cd9a58f9e2f1d3077e3ab81e07613.xml vendored

@ -0,0 +1,13 @@
<user:user xmlns:user="dclg:user">
<user:id>d6717836154cd9a58f9e2f1d3077e3ab81e07613</user:id>
<user:password>xxx</user:password>
<user:full-name>John Doe</user:full-name>
<user:user-name>john.doe@gov.uk</user:user-name>
<user:institution>7c5bd5fb549c09a2c55d7cb90d7ba84927e64618</user:institution>
<user:email>john.doe@gov.uk</user:email>
<user:user-type>Co-ordinator</user:user-type>
<user:active>true</user:active>
<user:deleted>false</user:deleted>
<user:contact-priority-id>eCORE Contact</user:contact-priority-id>
<user:telephone-no>02012345678</user:telephone-no>
</user:user>

35
spec/services/imports/user_import_service_spec.rb

@ -29,6 +29,7 @@ RSpec.describe Imports::UserImportService do
expect(user.phone).to eq("02012345678") expect(user.phone).to eq("02012345678")
expect(user).to be_data_provider expect(user).to be_data_provider
expect(user.organisation.old_org_id).to eq(old_org_id) expect(user.organisation.old_org_id).to eq(old_org_id)
expect(user.is_key_contact?).to be false
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
@ -36,6 +37,40 @@ RSpec.describe Imports::UserImportService do
.to raise_error(ActiveRecord::RecordInvalid, /Organisation must exist/) .to raise_error(ActiveRecord::RecordInvalid, /Organisation must exist/)
end end
context "when the user is a data coordinator" do
let(:old_user_id) { "d4729b1a5dfb68bb1e01c08445830c0add40907c" }
it "sets their role correctly" do
FactoryBot.create(:organisation, old_org_id:)
import_service.create_users("user_directory")
expect(User.find_by(old_user_id:)).to be_data_coordinator
end
end
context "when the user was a 'Key Performance Contact' in the old system" do
let(:old_user_id) { "d4729b1a5dfb68bb1e01c08445830c0add40907c" }
it "marks them as a key contact" do
FactoryBot.create(:organisation, old_org_id:)
import_service.create_users("user_directory")
user = User.find_by(old_user_id:)
expect(user.is_key_contact?).to be true
end
end
context "when the user was a 'eCORE Contact' in the old system" do
let(:old_user_id) { "d6717836154cd9a58f9e2f1d3077e3ab81e07613" }
it "marks them as a key contact" do
FactoryBot.create(:organisation, old_org_id:)
import_service.create_users("user_directory")
user = User.find_by(old_user_id:)
expect(user.is_key_contact?).to be true
end
end
context "when the user has already been imported previously" do context "when the user has already been imported previously" do
before do before do
org = FactoryBot.create(:organisation, old_org_id:) org = FactoryBot.create(:organisation, old_org_id:)

Loading…
Cancel
Save