Sha256: 30d943d45e176671035da1e5df3f7b9b4504f095427a7e41f39613689e670568

Contents?: true

Size: 1.74 KB

Versions: 124

Compression:

Stored size: 1.74 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' }

  describe '#perform' do
    def start_job
      CanvasSync::Jobs::ReportChecker.perform_now(
        '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(report_name, 'blah', processor, {}, report_id)

        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

124 entries across 124 versions & 1 rubygems

Version Path
canvas_sync-0.22.6 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.22.5 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.22.4 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.22.3 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.22.2 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.22.1 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.22.0 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.22.0.beta8 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.22.0.beta7 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.22.0.beta6 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.22.0.beta5 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.22.0.beta4 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.22.0.beta3 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.22.0.beta2 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.22.0.beta1 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.21.1 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.21.1.beta1 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.21.0 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.21.0.beta5 spec/canvas_sync/jobs/report_checker_spec.rb
canvas_sync-0.21.0.beta4 spec/canvas_sync/jobs/report_checker_spec.rb