docbrown/spec/workers/export_content_worker_spec.rb
Andy Zhao b80dae1436
Update data exporter to handle admin send (#10274)
* Update data exporter to handle admin send

* Match button with everything else

* Use proper redirect path

* Stub SiteConfig definition instead of setting it

Co-authored-by: Mac Siri <krairit.siri@gmail.com>

* Removed if statement by accident oops

* Remove non-functional boolean param and pass email directly

* Use refinement to conv to boolean instead of JSON.parse

* Rename to StringToBoolean

* Use 'using' in proper scope (not in method)

* Rename to_bool to to_boolean

* Refactor if statement, thanks rhymes!

* Fix small bugs in tests

* Remove tracking for export_email b/c no @user

Co-authored-by: Mac Siri <krairit.siri@gmail.com>
2020-10-26 18:00:56 -04:00

27 lines
791 B
Ruby

require "rails_helper"
RSpec.describe ExportContentWorker, type: :worker do
let(:worker) { subject }
include_examples "#enqueues_on_correct_queue", "medium_priority", [9999]
describe "#perform_now" do
let(:exporter_service) { instance_double(Exporter::Service) }
let(:user) { create(:user) }
before do
allow(Exporter::Service).to receive(:new).and_return(exporter_service)
allow(exporter_service).to receive(:export)
end
it "calls the service" do
worker.perform(user.id, user.email)
expect(exporter_service).to have_received(:export).once
end
it "doesn't call the service if non existent user ID is given" do
worker.perform(9999, user.email)
expect(exporter_service).not_to have_received(:export)
end
end
end