Sha256: be07137d133eaf54aef40df621b4915457ee2e0743ab068da9c44d34940023ff

Contents?: true

Size: 1.81 KB

Versions: 39

Compression:

Stored size: 1.81 KB

Contents

require 'spec_helper'

RSpec.describe CanvasSync::Jobs::ReportChecker do
  let(:client_double) { double('client') }
  let(:report_id) { 1 }
  let(:report_name) { 'provisioning_csv' }
  let(:processor) { 'FakeProcessor' }
  let(:job_chain) { { jobs: [], global_options: {} } }

  describe '#perform' do
    def start_job
      CanvasSync::Jobs::ReportChecker.perform_now(
        job_chain,
        'provisioning_csv',
        report_id,
        processor,
        {}
      )
    end

    context 'the report has finished' do
      it 'enqueues the report processor job' do
        expect_any_instance_of(Bearcat::Client).to receive(:report_status)
          .with('self', report_name, report_id)
          .and_return({ 'status' => 'complete', 'attachment' => { 'url' => 'blah' } })

        expect(CanvasSync::Jobs::ReportProcessorJob).to receive(:perform_later)
          .with(job_chain, report_name, 'blah', processor, {})

        start_job
      end
    end

    context 'the report is still running' do
      it 're-enqueues the report checker' do
        expect_any_instance_of(Bearcat::Client).to receive(:report_status)
          .with('self', report_name, report_id)
          .and_return({ 'status' => 'running' })

        expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_call_original

        start_job
      end
    end

    context 'the report has errored' do
      it 'does not re-enqueue the job or enqueue the processor' do
        expect_any_instance_of(Bearcat::Client).to receive(:report_status)
          .with('self', report_name, report_id)
          .and_return({ 'status' => 'error' })

        expect(CanvasSync::Jobs::ReportChecker).to_not receive(:set)
        expect(CanvasSync::Jobs::ReportProcessorJob).to_not receive(:perform_later)

        expect { start_job }.to raise_error
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
canvas_sync-0.6.4 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.6.3 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.6.2 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.6.1 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.6.0 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.5.4 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.5.3 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.5.2 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.5.1 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.4.1 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.4.0 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.3.23 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.3.22 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.3.21 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.3.20 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.3.19 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.3.18 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.3.17 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.3.16 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.3.15 spec/canvas_sync/jobs/report_checker_spec.rb