spec/slack/real_time/client_spec.rb in slack-ruby-client-0.5.4 vs spec/slack/real_time/client_spec.rb in slack-ruby-client-0.6.0
- old
+ new
@@ -57,33 +57,37 @@
context 'properties provided upon connection' do
it 'sets url' do
expect(client.url).to eq url
end
it 'sets team' do
- expect(client.team['domain']).to eq 'dblockdotorg'
+ expect(client.team.domain).to eq 'dblockdotorg'
end
+ it 'sets teams' do
+ expect(client.teams.count).to eq 1
+ expect(client.teams.values.first).to eq client.team
+ end
it 'sets self' do
- expect(client.self['id']).to eq 'U07518DTL'
+ expect(client.self.id).to eq 'U07518DTL'
end
it 'sets users' do
- expect(client.users.count).to eq 7
- expect(client.users.first['id']).to eq 'U07KECJ77'
+ expect(client.users.count).to eq 18
+ expect(client.users.values.first['id']).to eq 'U092BDCLV'
end
it 'sets channels' do
- expect(client.channels.count).to eq 8
- expect(client.channels.first['name']).to eq 'demo'
+ expect(client.channels.count).to eq 37
+ expect(client.channels.values.first['name']).to eq 'a1'
end
it 'sets ims' do
expect(client.ims.count).to eq 2
- expect(client.ims.first['user']).to eq 'USLACKBOT'
+ expect(client.ims.values.first['user']).to eq 'USLACKBOT'
end
it 'sets bots' do
- expect(client.bots.count).to eq 5
- expect(client.bots.first['name']).to eq 'bot'
+ expect(client.bots.count).to eq 16
+ expect(client.bots.values.first['name']).to eq 'bot'
end
it 'sets groups' do
- expect(client.groups.count).to eq 0
+ expect(client.groups.count).to eq 1
end
end
it 'uses web client to fetch url' do
expect(client.web_client).to be_a Slack::Web::Client
end
@@ -111,10 +115,41 @@
it 'increments' do
previous_id = client.send(:next_id)
expect(client.send(:next_id)).to eq previous_id + 1
end
end
+ context 'store_class: nil' do
+ let(:client) { Slack::RealTime::Client.new(store_class: nil) }
+ it 'sets store to nil' do
+ expect(client.store).to be nil
+ end
+ it "doesn't handle events" do
+ event = Slack::RealTime::Event.new(
+ 'type' => 'team_rename',
+ 'name' => 'New Team Name Inc.'
+ )
+ expect(client).to_not receive(:run_handlers)
+ client.send(:dispatch, event)
+ end
+ it 'self' do
+ expect(client.self).to be nil
+ end
+ it 'team' do
+ expect(client.team).to be nil
+ end
+ end
+ context 'subclassed' do
+ let(:client) { Class.new(Slack::RealTime::Client).new }
+ it 'runs event handlers' do
+ event = Slack::RealTime::Event.new(
+ 'type' => 'team_rename',
+ 'name' => 'New Team Name Inc.'
+ )
+ client.send(:dispatch, event)
+ expect(client.store.team.name).to eq 'New Team Name Inc.'
+ end
+ end
end
end
context 'with defaults' do
describe '#initialize' do
it 'sets ping' do
@@ -161,10 +196,13 @@
end
it 'creates a connection with custom ping' do
expect(Slack::RealTime::Concurrency::Mock::WebSocket).to receive(:new).with(url, nil, ping: 15).and_return(ws)
client.start!
end
+ it 'sets start_options' do
+ expect(client.start_options).to eq({})
+ end
end
end
context 'proxy' do
before do
Slack::RealTime::Client.configure do |config|
@@ -189,9 +227,33 @@
proxy: {
origin: 'http://username:password@proxy.example.com',
headers: { 'User-Agent' => 'ruby' }
}).and_return(ws)
client.start!
+ end
+ end
+ end
+ context 'start_options' do
+ before do
+ Slack::RealTime::Client.configure do |config|
+ config.start_options = { simple_latest: true }
+ end
+ end
+ describe '#initialize' do
+ it 'sets start_options' do
+ expect(client.start_options).to eq(simple_latest: true)
+ end
+ context 'start!' do
+ let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
+ before do
+ allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
+ allow(socket).to receive(:connect!)
+ allow(socket).to receive(:start_sync).and_yield
+ end
+ it 'calls rtm_start with start options' do
+ expect(client.web_client).to receive(:rtm_start).with(simple_latest: true).and_call_original
+ client.start!
+ end
end
end
end
end
end