2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-10-01 23:50:54 -05:00
|
|
|
require "import_export"
|
2017-10-26 15:29:36 -05:00
|
|
|
|
2022-07-27 21:27:38 -05:00
|
|
|
RSpec.describe ImportExport::TopicExporter do
|
2023-01-09 05:18:21 -06:00
|
|
|
before { STDOUT.stubs(:write) }
|
2017-11-02 04:33:36 -05:00
|
|
|
|
2019-05-06 22:12:20 -05:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
fab!(:topic) { Fabricate(:topic, user: user) }
|
|
|
|
fab!(:post) { Fabricate(:post, topic: topic, user: user) }
|
2017-10-26 15:29:36 -05:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
describe ".perform" do
|
|
|
|
it "export a single topic" do
|
2017-10-26 15:29:36 -05:00
|
|
|
data = ImportExport::TopicExporter.new([topic.id]).perform.export_data
|
|
|
|
|
|
|
|
expect(data[:categories].blank?).to eq(true)
|
|
|
|
expect(data[:groups].blank?).to eq(true)
|
|
|
|
expect(data[:topics].count).to eq(1)
|
|
|
|
expect(data[:users].count).to eq(1)
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
it "export multiple topics" do
|
2017-10-26 15:29:36 -05:00
|
|
|
topic2 = Fabricate(:topic, user: user)
|
2019-10-01 23:50:54 -05:00
|
|
|
_post2 = Fabricate(:post, user: user, topic: topic2)
|
2017-10-26 15:29:36 -05:00
|
|
|
data = ImportExport::TopicExporter.new([topic.id, topic2.id]).perform.export_data
|
|
|
|
|
|
|
|
expect(data[:categories].blank?).to eq(true)
|
|
|
|
expect(data[:groups].blank?).to eq(true)
|
|
|
|
expect(data[:topics].count).to eq(2)
|
2018-01-16 11:51:37 -06:00
|
|
|
expect(data[:users].map { |u| u[:id] }).to match_array([user.id])
|
2017-10-26 15:29:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|