Skip to content

Commit

Permalink
presence interval test
Browse files Browse the repository at this point in the history
  • Loading branch information
blazeroot committed Mar 31, 2017
1 parent d2d75db commit db0bff0
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Expand Up @@ -13,9 +13,9 @@ script: bundle exec rspec

matrix:
include:
- rvm: 2.4.0
- rvm: 2.3.3
- rvm: 2.2.6
- rvm: 2.4.1
- rvm: 2.3.4
- rvm: 2.2.7
- rvm: 2.1.10
- rvm: jruby-9.1.8.0
env: JRUBY_OPTS="--server -J-Xms1500m -J-Xmx1500m -J-XX:+UseConcMarkSweepGC -J-XX:-UseGCOverheadLimit -J-XX:+CMSClassUnloadingEnabled"
Expand Down
193 changes: 193 additions & 0 deletions fixtures/vcr_cassettes/lib/events/presence_delta.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions spec/lib/events/presence_delta_spec.rb
@@ -0,0 +1,38 @@
require 'spec_helper'

describe Pubnub::Presence do
around :each do |example|
Celluloid.boot
example.run
Celluloid.shutdown
end

context 'with interval events and delta' do
before :each do
@messages = []
@statuses = []

@callbacks = Pubnub::SubscribeCallback.new(
message: ->(_envelope) { },
presence: ->(envelope) { @messages << envelope },
status: ->(envelope) { @statuses << envelope }
)
end

it 'works' do
pubnub = Pubnub.new(subscribe_key: 'sub-c-9fb06248-0a21-11e7-91d0-02ee2ddab7fe', publish_key: 'pub-c-7a6fa2a4-a4c4-4eb4-9a21-a3334d38209d', uuid: '')
pubnub.add_listener(callback: @callbacks)

VCR.use_cassette('lib/events/presence_delta', record: :once) do
pubnub.presence(channel: :demo) # timestamp

eventually do
expect(@messages[0].result[:data]).to eq({:message=>{"action"=>"interval", "timestamp"=>1490958575, "occupancy"=>3}, :subscribed_channel=>"demo-pnpres", :actual_channel=>"demo-pnpres", :publish_time_object=>{:timetoken=>"14909585750910131", :region_code=>1}, :message_meta_data=>nil, :presence_event=>"interval", :presence=>{:uuid=>nil, :timestamp=>1490958575, :state=>nil, :occupancy=>3}})
expect(@messages[1].result[:data]).to eq({:message=>{"action"=>"interval", "timestamp"=>1490958585, "occupancy"=>4, "join"=>["Client-d39lr"]}, :subscribed_channel=>"demo-pnpres", :actual_channel=>"demo-pnpres", :publish_time_object=>{:timetoken=>"14909585850925693", :region_code=>1}, :message_meta_data=>nil, :presence_event=>"interval", :presence=>{:uuid=>nil, :timestamp=>1490958585, :state=>nil, :occupancy=>4}})
expect(@messages[2].result[:data]).to eq({:message=>{"action"=>"interval", "timestamp"=>1490958595, "occupancy"=>3, "leave"=>["another-client"]}, :subscribed_channel=>"demo-pnpres", :actual_channel=>"demo-pnpres", :publish_time_object=>{:timetoken=>"14909585950916556", :region_code=>1}, :message_meta_data=>nil, :presence_event=>"interval", :presence=>{:uuid=>nil, :timestamp=>1490958595, :state=>nil, :occupancy=>3}})
expect(@messages[3].result[:data]).to eq({:message=>{"action"=>"interval", "timestamp"=>1490958605, "occupancy"=>2, "join"=>["another-client"], "leave"=>["Client-d39lr", "client0"]}, :subscribed_channel=>"demo-pnpres", :actual_channel=>"demo-pnpres", :publish_time_object=>{:timetoken=>"14909586050915528", :region_code=>1}, :message_meta_data=>nil, :presence_event=>"interval", :presence=>{:uuid=>nil, :timestamp=>1490958605, :state=>nil, :occupancy=>2}})
end
end
end
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Expand Up @@ -73,6 +73,6 @@ def loop_it(interval, time_limit)
c.ignore_hosts 'api.codacy.com'
c.default_cassette_options = {
match_requests_on: [:method,
VCR.request_matchers.uri_without_param(:pnsdk, :uuid, :ortt, :seqn)]
VCR.request_matchers.uri_without_param(:pnsdk, :uuid, :ortt, :seqn, :t)]
}
end

0 comments on commit db0bff0

Please sign in to comment.