discourse/spec/jobs/export_csv_file_spec.rb

54 lines
1.8 KiB
Ruby
Raw Normal View History

require 'rails_helper'
2014-08-09 05:28:57 -05:00
describe Jobs::ExportCsvFile do
context '.execute' do
2018-04-24 23:12:42 -05:00
let(:user) { Fabricate(:user, username: "john_doe") }
2014-08-09 05:28:57 -05:00
it 'raises an error when the entity is missing' do
2018-04-24 23:12:42 -05:00
expect { Jobs::ExportCsvFile.new.execute(user_id: user.id) }.to raise_error(Discourse::InvalidParameters)
end
it 'works' do
begin
expect { Jobs::ExportCsvFile.new.execute(user_id: user.id, entity: "user_archive") }.to_not raise_error
expect(user.topics_allowed.last.title).to eq("[User Archive] Data export complete")
expect(user.topics_allowed.last.first_post.raw).to include("user-archive-john_doe-")
ensure
user.uploads.find_each { |upload| upload.destroy }
end
2014-08-09 05:28:57 -05:00
end
end
2017-09-13 11:09:11 -05:00
let(:user_list_header) {
%w{
id name username email title created_at last_seen_at last_posted_at
last_emailed_at trust_level approved suspended_at suspended_till blocked
2017-09-13 11:25:58 -05:00
active admin moderator ip_address staged topics_entered posts_read_count
2017-09-13 11:09:11 -05:00
time_read topic_count post_count likes_given likes_received location
website views external_id external_email external_username external_name
external_avatar_url
}
}
let(:user_list_export) { Jobs::ExportCsvFile.new.user_list_export }
def to_hash(row)
2015-01-02 00:59:05 -06:00
Hash[*user_list_header.zip(row).flatten]
end
it 'exports sso data' do
2017-12-23 02:46:48 -06:00
SiteSetting.sso_url = "https://www.example.com/sso"
SiteSetting.enable_sso = true
user = Fabricate(:user)
user.user_profile.update_column(:location, "La La Land")
user.create_single_sign_on_record(external_id: "123", last_payload: "xxx", external_email: 'test@test.com')
2017-07-27 20:20:09 -05:00
user = to_hash(user_list_export.find { |u| u[0].to_i == user.id })
2014-08-09 05:28:57 -05:00
expect(user["location"]).to eq("La La Land")
expect(user["external_id"]).to eq("123")
expect(user["external_email"]).to eq("test@test.com")
2014-08-09 05:28:57 -05:00
end
end