Browse Source

Persist org and user data at import

pull/1766/head
Jack S 3 years ago
parent
commit
f28da07f10
  1. 6
      app/services/imports/data_protection_confirmation_import_service.rb
  2. 20
      spec/services/imports/data_protection_confirmation_import_service_spec.rb

6
app/services/imports/data_protection_confirmation_import_service.rb

@ -38,6 +38,12 @@ module Imports
old_id: record_field_value(xml_document, "id"),
old_org_id: record_field_value(xml_document, "institution"),
created_at: record_field_value(xml_document, "change-date").to_time(:utc),
signed_at: record_field_value(xml_document, "change-date").to_time(:utc),
organisation_name: org.name,
organisation_address: org.address_row,
organisation_phone_number: org.phone,
data_protection_officer_email: dp_officer.email,
data_protection_officer_name: dp_officer.name,
)
end

20
spec/services/imports/data_protection_confirmation_import_service_spec.rb

@ -29,7 +29,7 @@ RSpec.describe Imports::DataProtectionConfirmationImportService do
end
context "when the organisation does exist" do
let!(:organisation) { create(:organisation, :without_dpc, old_org_id:) }
let!(:organisation) { create(:organisation, :without_dpc, old_org_id:, phone: "123") }
context "when a data protection officer with matching name does not exists for the organisation" do
it "creates an inactive data protection officer" do
@ -40,12 +40,18 @@ RSpec.describe Imports::DataProtectionConfirmationImportService do
expect(data_protection_officer.active).to be false
end
it "successfully create a data protection confirmation record with the expected data" do
it "successfully create a data protection confirmation record with the expected data", :aggregate_failures do
import_service.create_data_protection_confirmations("data_protection_directory")
confirmation = Organisation.find_by(old_org_id:).data_protection_confirmation
expect(confirmation.data_protection_officer.name).to eq("John Doe")
expect(confirmation.confirmed).to be_truthy
expect(confirmation.data_protection_officer.name).to eq("John Doe")
expect(confirmation.data_protection_officer_name).to eq("John Doe")
expect(confirmation.organisation_address).to eq("2 Marsham Street, London, SW1P 4DF")
expect(confirmation.organisation_name).to eq("DLUHC")
expect(confirmation.organisation_phone_number).to eq("123")
expect(Time.zone.local_to_utc(confirmation.created_at)).to eq(Time.utc(2018, 0o6, 0o5, 10, 36, 49))
expect(Time.zone.local_to_utc(confirmation.signed_at)).to eq(Time.utc(2018, 0o6, 0o5, 10, 36, 49))
end
end
@ -60,7 +66,15 @@ RSpec.describe Imports::DataProtectionConfirmationImportService do
confirmation = Organisation.find_by(old_org_id:).data_protection_confirmation
expect(confirmation.data_protection_officer.id).to eq(data_protection_officer.id)
expect(confirmation.confirmed).to be_truthy
expect(confirmation.data_protection_officer.name).to eq(data_protection_officer.name)
expect(confirmation.data_protection_officer_name).to eq(data_protection_officer.name)
expect(confirmation.data_protection_officer_email).to eq(data_protection_officer.email)
expect(confirmation.organisation_address).to eq("2 Marsham Street, London, SW1P 4DF")
expect(confirmation.organisation_name).to eq("DLUHC")
expect(confirmation.organisation_phone_number).to eq("123")
expect(Time.zone.local_to_utc(confirmation.created_at)).to eq(Time.utc(2018, 0o6, 0o5, 10, 36, 49))
expect(Time.zone.local_to_utc(confirmation.signed_at)).to eq(Time.utc(2018, 0o6, 0o5, 10, 36, 49))
end
context "when the data protection record has already been imported previously" do

Loading…
Cancel
Save