Browse Source

CLDC-4071: update export service

CLDC-4071-show-telephone-extensions-and-export
Nat Dean-Lewis 2 weeks ago
parent
commit
11c605367a
  1. 7
      app/models/user.rb
  2. 1
      app/services/exports/user_export_constants.rb
  3. 3
      app/services/exports/user_export_service.rb
  4. 3
      spec/fixtures/exports/user.xml
  5. 2
      spec/services/exports/user_export_service_spec.rb

7
app/models/user.rb

@ -334,13 +334,6 @@ class User < ApplicationRecord
save!(validate: false) save!(validate: false)
end end
def phone_with_extension
#use this
return phone if phone_extension.blank?
"#{phone}, Ext. #{phone_extension}"
end
def assigned_to_lettings_logs def assigned_to_lettings_logs
lettings_logs.where(assigned_to: self) lettings_logs.where(assigned_to: self)
end end

1
app/services/exports/user_export_constants.rb

@ -6,6 +6,7 @@ module Exports::UserExportConstants
"email", "email",
"name", "name",
"phone", "phone",
"extension_number",
"organisation_id", "organisation_id",
"organisation_name", "organisation_name",
"role", "role",

3
app/services/exports/user_export_service.rb

@ -64,7 +64,8 @@ module Exports
attribute_hash["role"] = user.role attribute_hash["role"] = user.role
attribute_hash["organisation_name"] = user.organisation.name attribute_hash["organisation_name"] = user.organisation.name
attribute_hash["active"] = user.active? attribute_hash["active"] = user.active?
attribute_hash["phone"] = [user.phone, user.phone_extension].compact.join(" ") attribute_hash["phone"] = user.phone
attribute_hash["extension_number"] = user.phone_extension
attribute_hash["last_sign_in_at"] = user.last_sign_in_at&.iso8601 attribute_hash["last_sign_in_at"] = user.last_sign_in_at&.iso8601
attribute_hash attribute_hash
end end

3
spec/fixtures/exports/user.xml vendored

@ -8,7 +8,8 @@
<sign_in_count>5</sign_in_count> <sign_in_count>5</sign_in_count>
<last_sign_in_at>2022-03-03T00:00:00+00:00</last_sign_in_at> <last_sign_in_at>2022-03-03T00:00:00+00:00</last_sign_in_at>
<role>data_provider</role> <role>data_provider</role>
<phone>1234512345123 123</phone> <phone>1234512345123</phone>
<extension_number>ext. 123</extension_number>
<is_dpo>false</is_dpo> <is_dpo>false</is_dpo>
<is_key_contact>false</is_key_contact> <is_key_contact>false</is_key_contact>
<active>true</active> <active>true</active>

2
spec/services/exports/user_export_service_spec.rb

@ -45,7 +45,7 @@ RSpec.describe Exports::UserExportService do
end end
context "and one user is available for export" do context "and one user is available for export" do
let!(:user) { create(:user, organisation:, name: "Danny Rojas", phone_extension: "123", last_sign_in_at: Time.zone.local(2022, 3, 3)) } let!(:user) { create(:user, organisation:, name: "Danny Rojas", phone_extension: "ext. 123", last_sign_in_at: Time.zone.local(2022, 3, 3)) }
it "generates a ZIP export file with the expected filename" do it "generates a ZIP export file with the expected filename" do
expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args) expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args)

Loading…
Cancel
Save