Sha256: 5d0d1ae8d2f100db78a52f9b51ec9d1ea7b5261d9eabc92447f60827117b330a

Contents?: true

Size: 1.34 KB

Versions: 5

Compression:

Stored size: 1.34 KB

Contents

require 'functional_spec_helper'

describe 'GCM' do
  let(:app) { Rpush::Gcm::App.new }
  let(:notification) { Rpush::Gcm::Notification.new }
  let(:response) { double(Net::HTTPResponse, code: 200) }
  let(:http) { double(Net::HTTP::Persistent, request: response, shutdown: nil) }

  before do
    app.name = 'test'
    app.auth_key = 'abc123'
    app.save!

    notification.app_id = app.id
    notification.registration_ids = ['foo']
    notification.data = { message: 'test' }
    notification.save!

    Net::HTTP::Persistent.stub(new: http)
  end

  it 'delivers a notification successfully' do
    response.stub(body: JSON.dump(results: [{ message_id: notification.registration_ids.first.to_s }]))

    expect do
      Rpush.push
      notification.reload
    end.to change(notification, :delivered).to(true)
  end

  it 'fails to deliver a notification successfully' do
    response.stub(body: JSON.dump(results: [{ error: 'Err' }]))

    expect do
      Rpush.push
      notification.reload
    end.to_not change(notification, :delivered).to(true)
  end

  it 'retries notification that fail due to a SocketError' do
    expect(http).to receive(:request).and_raise(SocketError.new)
    expect(notification.deliver_after).to be_nil
    expect do
      Rpush.push
      notification.reload
    end.to change(notification, :deliver_after).to(kind_of(Time))
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rpush-2.3.1-java spec/functional/gcm_spec.rb
rpush-2.3.1 spec/functional/gcm_spec.rb
rpush-2.3.0-java spec/functional/gcm_spec.rb
rpush-2.3.0 spec/functional/gcm_spec.rb
rpush-2.3.0.rc1 spec/functional/gcm_spec.rb