Sha256: 64f3083a5482843c8db6a1d3d11e163ce28921cd71716a3df31de79fe7ea64e8

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 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 |payload|
        payload.message "Minor downtime tonight from 7PM-9PM EST"
      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 |payload|
        payload.message 'You win a prize!'
      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 |payload|
        payload.message 'tag1 and tag2'
      end

      a_request(:post, notify_by_tags_endpoint).should have_been_made
    end

  end

  def notifier_endpoint(name)
    "https://push.fivemobile.com/rest/notify/#{name}"
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
five_mobile_push-0.3.1 spec/five_mobile_push/notifier_spec.rb
five_mobile_push-0.3.0 spec/five_mobile_push/notifier_spec.rb