Sha256: f0572c3fec49d4f387cca997de4f1f04d0ca7eb538d711a38757b44ae6d6c5f8

Contents?: true

Size: 1.94 KB

Versions: 88

Compression:

Stored size: 1.94 KB

Contents

require 'spec_helper'

RSpec.describe CanvasSync::JobBatches::Batch::Status do
  let(:batch) { CanvasSync::JobBatches::Batch.new() }
  let(:bid) { batch.bid }
  subject { described_class.new(bid) }

  describe '#join' do
    it 'raises info' do
      expect { subject.join }.to raise_error('Not supported')
    end
  end

  describe '#pending' do
    context 'when not initalized' do
      it 'returns 0 pending jobs' do
        expect(subject.pending).to eq(0)
      end
    end

    context 'when more than 0' do
      before { batch.jobs do TestWorker.perform_async end }
      it 'returns pending jobs' do
        expect(subject.pending).to eq(1)
      end
    end
  end

  describe '#failures' do
    context 'when not initalized' do
      it 'returns 0 failed jobs' do
        expect(subject.failures).to eq(0)
      end
    end

    context 'when more than 0' do
      before { batch.increment_job_queue(bid) }
      before { CanvasSync::JobBatches::Batch.process_failed_job(bid, 'FAILEDID') }

      it 'returns failed jobs' do
        expect(subject.failures).to eq(1)
      end
    end
  end

  describe '#failure_info' do
    context 'when not initalized' do
      it 'returns empty array' do
        expect(subject.failure_info).to eq([])
      end
    end

    context 'when with error' do
      before { batch.jobs{}; CanvasSync::JobBatches::Batch.process_failed_job(bid, 'jid123') }

      it 'returns array with failed jids' do
        expect(subject.failure_info).to eq(['jid123'])
      end
    end
  end

  describe '#data' do
    it 'returns batch description' do
      expect(subject.data).to include(failures: 0, pending: 0, created_at: nil, complete: false, failure_info: [], parent_bid: nil)
    end
  end

  describe '#created_at' do
    it 'returns time' do
      batch = CanvasSync::JobBatches::Batch.new
      batch.jobs do TestWorker.perform_async end
      status = described_class.new(batch.bid)
      expect(status.created_at).not_to be_nil
    end
  end
end

Version data entries

88 entries across 88 versions & 1 rubygems

Version Path
canvas_sync-0.19.0.beta4 spec/job_batching/status_spec.rb
canvas_sync-0.19.0.beta3 spec/job_batching/status_spec.rb
canvas_sync-0.19.0.beta2 spec/job_batching/status_spec.rb
canvas_sync-0.19.0.beta1 spec/job_batching/status_spec.rb
canvas_sync-0.18.12 spec/job_batching/status_spec.rb
canvas_sync-0.18.10 spec/job_batching/status_spec.rb
canvas_sync-0.18.9 spec/job_batching/status_spec.rb
canvas_sync-0.18.8 spec/job_batching/status_spec.rb
canvas_sync-0.18.7 spec/job_batching/status_spec.rb
canvas_sync-0.18.6 spec/job_batching/status_spec.rb
canvas_sync-0.18.5 spec/job_batching/status_spec.rb
canvas_sync-0.18.3 spec/job_batching/status_spec.rb
canvas_sync-0.18.2 spec/job_batching/status_spec.rb
canvas_sync-0.18.1 spec/job_batching/status_spec.rb
canvas_sync-0.18.0.beta2 spec/job_batching/status_spec.rb
canvas_sync-0.18.0.beta1 spec/job_batching/status_spec.rb
canvas_sync-0.17.43 spec/job_batching/status_spec.rb
canvas_sync-0.17.42 spec/job_batching/status_spec.rb
canvas_sync-0.17.41 spec/job_batching/status_spec.rb
canvas_sync-0.17.40 spec/job_batching/status_spec.rb