Sha256: 86e9e9ba89d545cddbee22bf6a3126edd287c54338375c773d99983fe194f8c5

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.7 spec/five_mobile_push/notifier_spec.rb
five_mobile_push-0.4.6 spec/five_mobile_push/notifier_spec.rb