spec/slack/real_time/client_spec.rb in slack-ruby-client-0.13.1 vs spec/slack/real_time/client_spec.rb in slack-ruby-client-0.14.0
- old
+ new
@@ -40,11 +40,11 @@
expect(client.token).to eq 'local token'
expect(client.web_client.token).to eq 'local token'
end
end
end
- context 'client with a full store', vcr: { cassette_name: 'web/rtm_start' } do
+ context 'client with a full store', vcr: { cassette_name: 'web/rtm_start', allow_playback_repeats: true } do
let(:client) { Slack::RealTime::Client.new(store_class: Slack::RealTime::Stores::Store) }
let(:url) { 'wss://ms173.slack-msgs.com/websocket/lqcUiAvrKTP-uuid=' }
describe '#start!' do
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
before do
@@ -125,10 +125,33 @@
client.send(:dispatch, event)
expect(client.store.team.name).to eq 'New Team Name Inc.'
end
end
end
+ describe '#start_async' do
+ let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
+ before do
+ allow(Slack::RealTime::Socket).to receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
+ allow(socket).to receive(:connect!)
+ allow(socket).to receive(:start_async)
+ client.start_async
+ end
+ describe '#run_ping!' do
+ it 'sends ping messages when the websocket connection is idle' do
+ allow(socket).to receive(:time_since_last_message).and_return(30)
+ expect(socket).to receive(:send_data).with('{"type":"ping","id":1}')
+ client.run_ping!
+ end
+ it 'reconnects the websocket if it has been idle for too long' do
+ allow(socket).to receive(:time_since_last_message).and_return(75)
+ allow(socket).to receive(:connected?).and_return(true)
+ expect(socket).to receive(:close)
+ expect(socket).to receive(:restart_async)
+ client.run_ping!
+ end
+ end
+ end
end
context 'client with starter store', vcr: { cassette_name: 'web/rtm_connect' } do
let(:client) { Slack::RealTime::Client.new(store_class: Slack::RealTime::Stores::Starter) }
let(:url) { 'wss://mpmulti-w5tz.slack-msgs.com/websocket/uid' }
describe '#start!' do
@@ -237,9 +260,21 @@
end
(Slack::RealTime::Config::ATTRIBUTES - %i[logger store_class]).each do |key|
it "sets #{key}" do
expect(client.send(key)).to eq Slack::RealTime::Config.send(key)
end
+ end
+ end
+ describe '#run_ping?' do
+ it 'returns true when websocket_ping is greater than 0' do
+ client.websocket_ping = 30
+ expect(client.run_ping?).to be true
+ end
+ it 'returns false when websocket_ping is less than 1' do
+ client.websocket_ping = 0
+ expect(client.run_ping?).to be false
+ client.websocket_ping = nil
+ expect(client.run_ping?).to be false
end
end
end
context 'with custom settings' do
describe '#initialize' do