Sha256: dfd93dfc99bc6aa0f8cb97ecd15907f98c926b36fbac5aa20257af3eee4e5c20

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

require 'unit_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 = app
    notification.registration_ids = ['foo']
    notification.data = { message: 'test' }
    notification.save!

    Rails.stub(root: File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp')))
    Rpush.config.logger = ::Logger.new(STDOUT)

    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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rpush-1.0.0-java spec/functional/gcm_spec.rb
rpush-1.0.0 spec/functional/gcm_spec.rb