require 'spec_helper' RSpec.describe CanvasSync::Jobs::SyncProvisioningReportJob do describe '#perform' do let(:job_chain) { {jobs: [], global_options: {}} } context 'a term scope is specified' do let!(:active_term_1) { FactoryGirl.create(:term) } let!(:active_term_2) { FactoryGirl.create(:term) } let!(:inactive_term_1) { FactoryGirl.create(:term, workflow_state: 'inactive') } it 'enqueues a ReportStarter for a provisioning report for the specified models for each term' do expected_job_chain = Marshal.load(Marshal.dump(job_chain)) expected_job_chain[:global_options][:canvas_term_id] = active_term_1.canvas_term_id expect(CanvasSync::Jobs::ReportStarter).to receive(:perform_later) .with( expected_job_chain, 'proservices_provisioning_csv', { "parameters[include_deleted]" => true, "parameters[users]" => true, "parameters[courses]" => true, "parameters[enrollment_term_id]" => active_term_1.canvas_term_id }, CanvasSync::Processors::ProvisioningReportProcessor.to_s, { models: ['users', 'courses'], term_scope: 'active' } ) expected_job_chain_2 = Marshal.load(Marshal.dump(job_chain)) expected_job_chain_2[:global_options][:canvas_term_id] = active_term_2.canvas_term_id expect(CanvasSync::Jobs::ReportStarter).to receive(:perform_later) .with( expected_job_chain_2, 'proservices_provisioning_csv', { "parameters[include_deleted]" => true, "parameters[users]" => true, "parameters[courses]" => true, "parameters[enrollment_term_id]" => active_term_2.canvas_term_id }, CanvasSync::Processors::ProvisioningReportProcessor.to_s, { models: ['users', 'courses'], term_scope: 'active' } ) CanvasSync::Jobs::SyncProvisioningReportJob.perform_now( job_chain, { models: ['users', 'courses'], term_scope: 'active' } ) end end context 'a term scope is not specified' do it 'enqueues a single ReportStarter for a provisioning report across all terms for the specified models' do expect(CanvasSync::Jobs::ReportStarter).to receive(:perform_later) .with( job_chain, 'proservices_provisioning_csv', { "parameters[include_deleted]" => true, "parameters[users]" => true, "parameters[courses]" => true }, CanvasSync::Processors::ProvisioningReportProcessor.to_s, { models: ['users', 'courses'] } ) CanvasSync::Jobs::SyncProvisioningReportJob.perform_now( job_chain, { models: ['users', 'courses'] } ) end end end end