From d2cc5452ec5c89966e89acb994b85efddf2f0618 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Wed, 25 Apr 2018 09:42:42 +0530 Subject: [PATCH] add spec for user csv export --- spec/jobs/export_csv_file_spec.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/jobs/export_csv_file_spec.rb b/spec/jobs/export_csv_file_spec.rb index c9c5e96bd6..92426c8bfe 100644 --- a/spec/jobs/export_csv_file_spec.rb +++ b/spec/jobs/export_csv_file_spec.rb @@ -3,8 +3,20 @@ 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: "1") }.to raise_error(Discourse::InvalidParameters) + 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 end end