require 'spec_helper' RSpec.describe CanvasSync::Jobs::ReportStarter do let(:report_params) { { 'parameters[users]' => true } } let(:report_name) { 'provisioning_csv' } let(:processor) { 'CoolProcessor' } let(:report_checker_double) { double } let(:options) { { models: ['users'] } } describe '#perform' do it 'tells Canvas to start the report and then enqueues a ReportChecker with the report id' do expect_any_instance_of(Bearcat::Client).to receive(:start_report) .with('self', report_name, report_params) .and_return({ 'id' => 1 }) expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_call_original CanvasSync::Jobs::ReportStarter.perform_now( { jobs: [], global_options: {} }, report_name, report_params, processor, options) end context 'allow_redownloads is true' do context 'the report has already been cached' do it 'runs the report checker for the already started report' do expect_any_instance_of(Bearcat::Client).to_not receive(:start_report) job_chain = { jobs: [], global_options: { report_name => 1 } } expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_return(report_checker_double) expect(report_checker_double).to receive(:perform_later).with( job_chain, report_name, 1, processor, options ) CanvasSync::Jobs::ReportStarter.perform_now( job_chain, report_name, report_params, processor, options, allow_redownloads: true ) end end context 'the report has not been started before' do it 'starts a new report and caches the report id' do expect_any_instance_of(Bearcat::Client).to receive(:start_report) .with('self', report_name, report_params) .and_return({ 'id' => 1 }) orig_job_chain = { jobs: [], global_options: {} } new_job_chain = { jobs: [], global_options: { report_name => 1 } } expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_return(report_checker_double) expect(report_checker_double).to receive(:perform_later).with( new_job_chain, report_name, 1, processor, options ) CanvasSync::Jobs::ReportStarter.perform_now( orig_job_chain, report_name, report_params, processor, options, allow_redownloads: true ) end end end end end