Sha256: 441091bf0ee04db5e45fab71b4cddc86fe9f342c767eaa76c7eeec81d32abdb5

Contents?: true

Size: 1.93 KB

Versions: 3

Compression:

Stored size: 1.93 KB

Contents

require 'spec_helper'

RSpec.describe CanvasSync::JobBatches::Batch::Status do
  let(:bid) { 'BID' }
  let(:batch) { CanvasSync::JobBatches::Batch.new(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 { 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

3 entries across 3 versions & 1 rubygems

Version Path
canvas_sync-0.17.3.beta3 spec/job_batching/status_spec.rb
canvas_sync-0.17.3.beta2 spec/job_batching/status_spec.rb
canvas_sync-0.17.3.beta1 spec/job_batching/status_spec.rb