Sha256: ebf5430adbf75cc4b63ce38dbb41e51f39acfad20ce3c16bba613e2d93f91b64

Contents?: true

Size: 1.75 KB

Versions: 10

Compression:

Stored size: 1.75 KB

Contents

require File.join(File.dirname(__FILE__),'..','spec_helper')

describe "Ping using RhoConnect push" do
  include_examples "SharedRhoconnectHelper", :rhoconnect_data => false

  before do
    @params = {"device_pin" => @c.device_pin,
      "sources" => [@s.name], "message" => 'hello world',
      "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3'}
    @response = double('response')

  end

  it "should ping rhoconnect push successfully" do
    result = ''
    @response.stub(:code).and_return(204)
    @response.stub(:body).and_return(result)
    @response.stub(:return!).and_return(@response)
    RestClient.stub(:post).and_return(@response)
    res = RhoconnectPush.ping(@params)
    res.body.should == result
    res.code.should == 204
  end

  it "should ping rhoconnect push with missing push_server property" do
    RhoconnectPush.stub(:get_config).and_return({:test => {}})
    lambda { RhoconnectPush.ping(@params) }.should raise_error(
      RhoconnectPush::InvalidPushServer, "Missing or invalid `:push_server` in settings/settings.yml."
    )
  end


  it "should ping rhoconnect push with 400 response" do
    result = ''
    @response.stub(:code).and_return(400)
    @response.stub(:body).and_return(result)
    @response.stub(:return!).and_return(@response)
    setup_post_yield(@response)
    lambda { RhoconnectPush.ping(@params) }.should raise_error(
      RhoconnectPush::InvalidPushRequest, "Invalid push request."
    )
  end

  it "should compute push_message" do
    expected = {
      'collapseId' => 5,
      'data' => {
        'do_sync' => [@s.name],
        'alert' => "hello world",
        'vibrate' => '5',
        'sound' => "hello.mp3"
      }
    }
    actual = RhoconnectPush.push_message(@params)
    JSON.parse(actual).should == expected
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rhoconnect-6.0.11 spec/ping/rhoconnect_push_spec.rb
rhoconnect-5.5.18 spec/ping/rhoconnect_push_spec.rb
rhoconnect-5.5.17 spec/ping/rhoconnect_push_spec.rb
rhoconnect-5.5.15 spec/ping/rhoconnect_push_spec.rb
rhoconnect-5.5.0.22 spec/ping/rhoconnect_push_spec.rb
rhoconnect-5.5.2 spec/ping/rhoconnect_push_spec.rb
rhoconnect-5.5.0.7 spec/ping/rhoconnect_push_spec.rb
rhoconnect-5.5.0.3 spec/ping/rhoconnect_push_spec.rb
rhoconnect-5.5.0 spec/ping/rhoconnect_push_spec.rb
rhoconnect-5.1.1 spec/ping/rhoconnect_push_spec.rb