discourse/spec/jobs/export_csv_file_spec.rb
Sam Saffron 4ea21fa2d0 DEV: use #frozen_string_literal: true on all spec
This change both speeds up specs (less strings to allocate) and helps catch
cases where methods in Discourse are mutating inputs.

Overall we will be migrating everything to use #frozen_string_literal: true
it will take a while, but this is the first and safest move in this direction
2019-04-30 10:27:42 +10:00

71 lines
2.3 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
describe Jobs::ExportCsvFile do
context '.execute' do
let(:user) { Fabricate(:user, username: "john_doe") }
it 'raises an error when the entity is missing' do
expect { Jobs::ExportCsvFile.new.execute(user_id: user.id) }.to raise_error(Discourse::InvalidParameters)
end
it 'works' do
begin
Jobs::ExportCsvFile.new.execute(user_id: user.id, entity: "user_archive")
expect(user.topics_allowed.last.title).to eq(I18n.t(
"system_messages.csv_export_succeeded.subject_template",
export_title: "User Archive"
))
expect(user.topics_allowed.last.first_post.raw).to include("user-archive-john_doe-")
ensure
user.uploads.each(&:destroy!)
end
end
end
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
active admin moderator ip_address staged secondary_emails topics_entered
posts_read_count 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)
Hash[*user_list_header.zip(row).flatten]
end
it "exports secondary emails" do
user = Fabricate(:user)
Fabricate(:secondary_email, user: user, primary: false)
secondary_emails = user.secondary_emails
user = to_hash(user_list_export.find { |u| u[0].to_i == user.id })
expect(user["secondary_emails"].split(";")).to match_array(secondary_emails)
end
it 'exports sso data' do
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')
user = to_hash(user_list_export.find { |u| u[0].to_i == user.id })
expect(user["location"]).to eq('"La,La Land"')
expect(user["external_id"]).to eq("123")
expect(user["external_email"]).to eq("test@test.com")
end
end