Sha256: 5022e1172d3391e95b8cd436991ae137ea404278020b7de3c977d20c2bd84e73

Contents?: true

Size: 1.75 KB

Versions: 31

Compression:

Stored size: 1.75 KB

Contents

require 'unit_spec_helper'

describe Rpush::Daemon::Delivery do
  class DeliverySpecDelivery < Rpush::Daemon::Delivery
    def initialize(batch)
      @batch = batch
    end
  end

  let(:now) { Time.parse("2014-10-14 00:00:00") }
  let(:batch) { double(Rpush::Daemon::Batch) }
  let(:delivery) { DeliverySpecDelivery.new(batch) }
  let(:notification) { Rpush::Apns::Notification.new }

  before { allow(Time).to receive_messages(now: now) }

  describe 'mark_retryable' do
    it 'does not retry a notification with an expired fail_after' do
      expect(batch).to receive(:mark_failed).with(notification, nil, "Notification failed to be delivered before 2014-10-13 23:00:00.")
      notification.fail_after = Time.now - 1.hour
      delivery.mark_retryable(notification, Time.now + 1.hour)
    end

    it 'retries the notification if does not have a fail_after time' do
      expect(batch).to receive(:mark_retryable)
      notification.fail_after = nil
      delivery.mark_retryable(notification, Time.now + 1.hour)
    end

    it 'retries the notification if the fail_after time has not been reached' do
      expect(batch).to receive(:mark_retryable)
      notification.fail_after = Time.now + 1.hour
      delivery.mark_retryable(notification, Time.now + 1.hour)
    end
  end

  describe 'mark_batch_delivered' do
    it 'marks all notifications as delivered' do
      expect(batch).to receive(:mark_all_delivered)
      delivery.mark_batch_delivered
    end
  end

  describe 'mark_batch_failed' do
    it 'marks all notifications as delivered' do
      error = Rpush::DeliveryError.new(1, 42, 'an error')
      expect(batch).to receive(:mark_all_failed).with(1, 'Unable to deliver notification 42, received error 1 (an error)')
      delivery.mark_batch_failed(error)
    end
  end
end

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
rpush-5.1.0 spec/unit/daemon/delivery_spec.rb
rpush-5.0.0 spec/unit/daemon/delivery_spec.rb
rpush-4.2.0 spec/unit/daemon/delivery_spec.rb
rpush-4.1.1 spec/unit/daemon/delivery_spec.rb
rpush-4.1.0 spec/unit/daemon/delivery_spec.rb
rpush-4.0.1 spec/unit/daemon/delivery_spec.rb
rpush-4.0.0 spec/unit/daemon/delivery_spec.rb
rpush-3.3.1 spec/unit/daemon/delivery_spec.rb
rpush-3.3.0 spec/unit/daemon/delivery_spec.rb
rpush_extended-3.2.6 spec/unit/daemon/delivery_spec.rb
rpush_extended-3.2.5 spec/unit/daemon/delivery_spec.rb
rpush-3.2.4 spec/unit/daemon/delivery_spec.rb
rpush-3.2.3 spec/unit/daemon/delivery_spec.rb
rpush-3.2.2 spec/unit/daemon/delivery_spec.rb
rpush-3.2.1 spec/unit/daemon/delivery_spec.rb
rpush-3.2.0 spec/unit/daemon/delivery_spec.rb
rpush-3.1.1 spec/unit/daemon/delivery_spec.rb
rpush-3.1.0 spec/unit/daemon/delivery_spec.rb
rpush-3.0.2 spec/unit/daemon/delivery_spec.rb
rpush-3.0.1 spec/unit/daemon/delivery_spec.rb