Sha256: 75790904d0bf402d0ef4e312993a785651e7f356efe790104b5aa079b9d29db0

Contents?: true

Size: 1.58 KB

Versions: 2

Compression:

Stored size: 1.58 KB

Contents

require 'spec_helper'
require 'uri'

describe FiveMobilePush::Notifier do
  let(:client) { Fabricate.build(:client) }

  subject { FiveMobilePush::Notifier.new(client) }

  describe "#broadcast" do
    let(:broadcast_endpoint) { notifier_endpoint('broadcast') }

    it "broadcasts a notification to one or more platforms of the application" do
      stub_request(:post, broadcast_endpoint)

      subject.broadcast(:iphone) do |message|
        message.body "Minor downtime tonight from 7PM-9PM EST"
        message.meta_data :a => '/a/b/c'
      end

      a_request(:post, broadcast_endpoint).should have_been_made
    end
  end

  describe '#notify_devices' do
    let(:notify_devices_endpoint) { notifier_endpoint('toDevices') }

    it "notifies a list of devices" do
      stub_request(:post, notify_devices_endpoint)

      subject.notify_devices(['abc', 'def']) do |message|
        message.body 'You win a prize!'
        message.meta_data :a => '/a/b/c'
      end

      a_request(:post, notify_devices_endpoint).should have_been_made
    end
  end

  describe "#notify_by_tags" do
    let(:notify_by_tags_endpoint) { notifier_endpoint('toTags') }

    it "notifies devices by tags" do
      stub_request(:post, notify_by_tags_endpoint)

      subject.notify_by_tags([:iphone, :android], ['tag1', 'tag2']) do |message|
        message.body 'tag1 and tag2'
        message.meta_data :a => '/a/b/c'
      end

      a_request(:post, notify_by_tags_endpoint).should have_been_made
    end
  end

  def notifier_endpoint(name)
    (FiveMobilePush::Client.default_endpoint + "notify/#{name}").to_s
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
five_mobile_push-0.4.5 spec/five_mobile_push/notifier_spec.rb
five_mobile_push-0.4.4-x86_64-darwin-10 spec/five_mobile_push/notifier_spec.rb