slack-ruby-client 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/{integtest.yml → integration_test.yml} +6 -5
- data/.github/workflows/{rubocop.yml → lint.yml} +5 -4
- data/.github/workflows/{danger.yml → pr_lint.yml} +8 -6
- data/.github/workflows/test.yml +4 -2
- data/.gitignore +0 -1
- data/.rubocop.yml +4 -0
- data/.rubocop_todo.yml +8 -14
- data/.ruby-version +1 -0
- data/CHANGELOG.md +14 -0
- data/CONTRIBUTING.md +5 -4
- data/Gemfile +1 -6
- data/README.md +60 -63
- data/RELEASING.md +1 -1
- data/UPGRADING.md +28 -0
- data/bin/commands/admin_audit_anomaly_allow.rb +23 -0
- data/bin/commands/admin_conversations.rb +12 -11
- data/bin/commands/admin_users.rb +1 -1
- data/bin/commands/admin_users_session.rb +1 -1
- data/bin/commands/apps_connections.rb +2 -2
- data/bin/commands/bookmarks.rb +1 -0
- data/bin/commands/chat.rb +9 -6
- data/bin/commands/conversations.rb +8 -6
- data/bin/commands/files.rb +24 -0
- data/bin/commands/rtm.rb +0 -15
- data/bin/commands/views.rb +4 -2
- data/bin/commands.rb +1 -0
- data/bin/slack +1 -1
- data/lib/slack/real_time/api/message.rb +3 -2
- data/lib/slack/real_time/api/templates/event_handler.erb +5 -1
- data/lib/slack/real_time/api/typing.rb +2 -1
- data/lib/slack/real_time/client.rb +8 -26
- data/lib/slack/real_time/config.rb +3 -3
- data/lib/slack/real_time/models/channel.rb +4 -0
- data/lib/slack/real_time/models/{group.rb → mpim.rb} +1 -1
- data/lib/slack/real_time/models.rb +2 -1
- data/lib/slack/real_time/stores/base.rb +25 -9
- data/lib/slack/real_time/stores/starter.rb +323 -309
- data/lib/slack/real_time/stores/store.rb +265 -198
- data/lib/slack/real_time/stores.rb +1 -7
- data/lib/slack/version.rb +1 -1
- data/lib/slack/web/api/endpoints/admin_analytics.rb +1 -1
- data/lib/slack/web/api/endpoints/admin_apps.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_apps_requests.rb +1 -1
- data/lib/slack/web/api/endpoints/admin_audit_anomaly_allow.rb +34 -0
- data/lib/slack/web/api/endpoints/admin_auth_policy.rb +7 -7
- data/lib/slack/web/api/endpoints/admin_barriers.rb +8 -8
- data/lib/slack/web/api/endpoints/admin_conversations.rb +30 -28
- data/lib/slack/web/api/endpoints/admin_conversations_restrictAccess.rb +6 -6
- data/lib/slack/web/api/endpoints/admin_emoji.rb +7 -7
- data/lib/slack/web/api/endpoints/admin_inviteRequests.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_teams.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_teams_admins.rb +1 -1
- data/lib/slack/web/api/endpoints/admin_teams_owners.rb +1 -1
- data/lib/slack/web/api/endpoints/admin_teams_settings.rb +11 -11
- data/lib/slack/web/api/endpoints/admin_usergroups.rb +7 -7
- data/lib/slack/web/api/endpoints/admin_users.rb +16 -16
- data/lib/slack/web/api/endpoints/admin_users_session.rb +8 -8
- data/lib/slack/web/api/endpoints/apps.rb +2 -2
- data/lib/slack/web/api/endpoints/apps_connections.rb +1 -1
- data/lib/slack/web/api/endpoints/apps_event_authorizations.rb +1 -1
- data/lib/slack/web/api/endpoints/apps_manifest.rb +6 -6
- data/lib/slack/web/api/endpoints/bookmarks.rb +10 -8
- data/lib/slack/web/api/endpoints/bots.rb +1 -1
- data/lib/slack/web/api/endpoints/calls.rb +5 -5
- data/lib/slack/web/api/endpoints/calls_participants.rb +4 -4
- data/lib/slack/web/api/endpoints/chat.rb +36 -30
- data/lib/slack/web/api/endpoints/conversations.rb +37 -33
- data/lib/slack/web/api/endpoints/dialog.rb +2 -2
- data/lib/slack/web/api/endpoints/dnd.rb +1 -1
- data/lib/slack/web/api/endpoints/files.rb +45 -8
- data/lib/slack/web/api/endpoints/files_comments.rb +2 -2
- data/lib/slack/web/api/endpoints/files_remote.rb +8 -8
- data/lib/slack/web/api/endpoints/migration.rb +1 -1
- data/lib/slack/web/api/endpoints/oauth_v2.rb +2 -2
- data/lib/slack/web/api/endpoints/pins.rb +3 -3
- data/lib/slack/web/api/endpoints/reactions.rb +4 -4
- data/lib/slack/web/api/endpoints/reminders.rb +5 -5
- data/lib/slack/web/api/endpoints/rtm.rb +0 -23
- data/lib/slack/web/api/endpoints/search.rb +3 -3
- data/lib/slack/web/api/endpoints/tooling_tokens.rb +1 -1
- data/lib/slack/web/api/endpoints/usergroups.rb +4 -4
- data/lib/slack/web/api/endpoints/usergroups_users.rb +3 -3
- data/lib/slack/web/api/endpoints/users.rb +4 -4
- data/lib/slack/web/api/endpoints/users_admin.rb +2 -2
- data/lib/slack/web/api/endpoints/views.rb +16 -11
- data/lib/slack/web/api/endpoints/workflows.rb +4 -4
- data/lib/slack/web/api/endpoints.rb +2 -0
- data/lib/slack/web/api/errors.rb +56 -6
- data/lib/slack/web/api/mixins/conversations.id.rb +1 -1
- data/lib/slack/web/api/mixins/users.id.rb +1 -1
- data/lib/slack/web/api/mixins/users.search.rb +2 -1
- data/lib/slack/web/api/patches/{chat.1.patch → chat.attachments-blocks.patch} +13 -14
- data/lib/slack/web/api/patches/{dialog.1.open-json-support.patch → dialog.encoded-json.patch} +4 -4
- data/lib/slack/web/api/patches/views.view-json.patch +55 -0
- data/lib/slack/web/api/templates/method.erb +1 -1
- data/lib/slack/web/config.rb +2 -2
- data/lib/tasks/real_time.rake +44 -22
- data/lib/tasks/web.rake +9 -2
- data/spec/fixtures/slack/web/rtm_connect.yml +85 -1
- data/spec/slack/events/config_spec.rb +2 -0
- data/spec/slack/events/request_spec.rb +4 -0
- data/spec/slack/messages/formatting_spec.rb +10 -0
- data/spec/slack/real_time/api/message_spec.rb +1 -1
- data/spec/slack/real_time/api/ping_spec.rb +1 -1
- data/spec/slack/real_time/api/typing_spec.rb +1 -1
- data/spec/slack/real_time/client_spec.rb +73 -111
- data/spec/slack/real_time/event_handlers/bot_spec.rb +19 -17
- data/spec/slack/real_time/event_handlers/event_handlers_spec.rb +1 -1
- data/spec/slack/real_time/event_handlers/im_spec.rb +28 -25
- data/spec/slack/real_time/event_handlers/{group_spec.rb → private_channel_spec.rb} +35 -27
- data/spec/slack/real_time/event_handlers/{channel_spec.rb → public_channel_spec.rb} +24 -20
- data/spec/slack/real_time/event_handlers/team_spec.rb +7 -8
- data/spec/slack/real_time/event_handlers/user_spec.rb +6 -5
- data/spec/slack/real_time/stores/store_spec.rb +50 -0
- data/spec/slack/slack_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/admin_audit_anomaly_allow_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +17 -1
- data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +2 -0
- data/spec/slack/web/api/endpoints/custom_specs/views_spec.rb +13 -4
- data/spec/slack/web/api/endpoints/files_spec.rb +13 -0
- data/spec/slack/web/api/mixins/conversations_spec.rb +2 -0
- data/spec/slack/web/api/mixins/users_spec.rb +2 -0
- data/spec/slack/web/api/pagination/cursor_spec.rb +4 -0
- data/spec/slack/web/client_spec.rb +14 -4
- data/spec/support/real_time/loaded_client.rb +120 -0
- metadata +18 -35
- data/bin/commands/admin_conversations_whitelist.rb +0 -37
- data/bin/commands/apps_permissions.rb +0 -23
- data/bin/commands/apps_permissions_resources.rb +0 -15
- data/bin/commands/apps_permissions_scopes.rb +0 -13
- data/bin/commands/apps_permissions_users.rb +0 -26
- data/bin/commands/channels.rb +0 -23
- data/bin/commands/groups.rb +0 -14
- data/bin/commands/im.rb +0 -6
- data/bin/commands/mpim.rb +0 -6
- data/lib/slack/web/api/endpoints/admin_conversations_whitelist.rb +0 -64
- data/lib/slack/web/api/endpoints/apps_permissions.rb +0 -36
- data/lib/slack/web/api/endpoints/apps_permissions_resources.rb +0 -31
- data/lib/slack/web/api/endpoints/apps_permissions_scopes.rb +0 -21
- data/lib/slack/web/api/endpoints/apps_permissions_users.rb +0 -50
- data/lib/slack/web/api/endpoints/channels.rb +0 -25
- data/lib/slack/web/api/endpoints/groups.rb +0 -13
- data/lib/slack/web/api/endpoints/im.rb +0 -13
- data/lib/slack/web/api/endpoints/mpim.rb +0 -13
- data/lib/slack/web/api/endpoints/presence.rb +0 -23
- data/lib/slack/web/api/patches/views.1.view-json.patch +0 -40
- data/lib/slack/web/api/patches/views.1.views-published.patch +0 -16
- data/spec/fixtures/slack/web/rtm_start.yml +0 -815
- data/spec/slack/real_time/rtm_start_spec.rb +0 -14
- data/spec/slack/real_time/store_spec.rb +0 -12
@@ -25,6 +25,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
25
25
|
expect(client.token).to eq '<SLACK_API_TOKEN>'
|
26
26
|
expect(client.web_client.token).to eq '<SLACK_API_TOKEN>'
|
27
27
|
end
|
28
|
+
|
28
29
|
context 'with real time config' do
|
29
30
|
before do
|
30
31
|
described_class.configure do |config|
|
@@ -37,6 +38,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
37
38
|
expect(client.token).to eq 'custom real time token'
|
38
39
|
expect(client.web_client.token).to eq 'custom real time token'
|
39
40
|
end
|
41
|
+
|
40
42
|
it 'overrides token to specific token' do
|
41
43
|
client = described_class.new(token: 'local token')
|
42
44
|
expect(client.token).to eq 'local token'
|
@@ -64,7 +66,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
64
66
|
end
|
65
67
|
|
66
68
|
context 'client with a full store',
|
67
|
-
vcr: { cassette_name: 'web/
|
69
|
+
vcr: { cassette_name: 'web/rtm_connect', allow_playback_repeats: true } do
|
68
70
|
let(:client) { described_class.new(store_class: Slack::RealTime::Stores::Store) }
|
69
71
|
let(:url) { 'wss://cerberus-xxxx.lb.slack-msgs.com/websocket/uid' }
|
70
72
|
|
@@ -84,35 +86,25 @@ RSpec.describe Slack::RealTime::Client do
|
|
84
86
|
it 'sets url' do
|
85
87
|
expect(client.url).to eq url
|
86
88
|
end
|
89
|
+
|
87
90
|
it 'sets team' do
|
88
91
|
expect(client.team.domain).to eq 'dblockdotorg'
|
89
92
|
end
|
93
|
+
|
90
94
|
it 'sets teams' do
|
91
95
|
expect(client.teams.count).to eq 1
|
92
96
|
expect(client.teams.values.first).to eq client.team
|
93
97
|
end
|
98
|
+
|
94
99
|
it 'sets self' do
|
95
100
|
expect(client.self.id).to eq 'U0J1GAHN1'
|
96
101
|
end
|
97
|
-
|
98
|
-
|
102
|
+
|
103
|
+
it 'sets user' do
|
104
|
+
expect(client.users.count).to eq 1
|
99
105
|
expect(client.users.values.first['id']).to eq 'U0J1GAHN1'
|
100
106
|
end
|
101
|
-
|
102
|
-
expect(client.channels.count).to eq 156
|
103
|
-
expect(client.channels.values.first['name']).to eq 'general'
|
104
|
-
end
|
105
|
-
it 'sets ims' do
|
106
|
-
expect(client.ims.count).to eq 10
|
107
|
-
expect(client.ims.values.first['user']).to eq 'U04KB5WQR'
|
108
|
-
end
|
109
|
-
it 'sets bots' do
|
110
|
-
expect(client.bots.count).to eq 83
|
111
|
-
expect(client.bots.values.first['name']).to eq 'bot'
|
112
|
-
end
|
113
|
-
it 'sets groups' do
|
114
|
-
expect(client.groups.count).to eq 1
|
115
|
-
end
|
107
|
+
|
116
108
|
it 'includes team name in to_s' do
|
117
109
|
expect(client.to_s).to eq(
|
118
110
|
"id=#{client.team.id}, name=#{client.team.name}, domain=#{client.team.domain}"
|
@@ -123,14 +115,17 @@ RSpec.describe Slack::RealTime::Client do
|
|
123
115
|
it 'uses web client to fetch url' do
|
124
116
|
expect(client.web_client).to be_a Slack::Web::Client
|
125
117
|
end
|
118
|
+
|
126
119
|
it 'remembers socket' do
|
127
120
|
expect(client.instance_variable_get(:@socket)).to eq socket
|
128
121
|
end
|
122
|
+
|
129
123
|
it 'cannot be invoked twice' do
|
130
124
|
expect do
|
131
125
|
client.start!
|
132
126
|
end.to raise_error Slack::RealTime::Client::ClientAlreadyStartedError
|
133
127
|
end
|
128
|
+
|
134
129
|
describe '#stop!' do
|
135
130
|
before do
|
136
131
|
allow(socket).to receive(:disconnect!)
|
@@ -164,18 +159,18 @@ RSpec.describe Slack::RealTime::Client do
|
|
164
159
|
end
|
165
160
|
|
166
161
|
describe '#run_handlers' do
|
167
|
-
|
162
|
+
context 'when store has no event hooks' do
|
168
163
|
before do
|
169
|
-
@
|
170
|
-
client.store.class.events
|
164
|
+
@events = client.store.class.events.dup
|
165
|
+
client.store.class.events.clear
|
171
166
|
end
|
172
167
|
|
173
168
|
after do
|
174
|
-
client.store.class.events
|
169
|
+
client.store.class.events.merge!(@events)
|
175
170
|
end
|
176
171
|
|
177
|
-
it 'returns
|
178
|
-
expect(client.send(:run_handlers, 'example', {})).to
|
172
|
+
it 'returns empty array of handlers' do
|
173
|
+
expect(client.send(:run_handlers, 'example', {})).to be_empty
|
179
174
|
end
|
180
175
|
end
|
181
176
|
end
|
@@ -199,6 +194,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
199
194
|
expect(socket).to receive(:send_data).with('{"type":"ping","id":1}')
|
200
195
|
client.run_ping!
|
201
196
|
end
|
197
|
+
|
202
198
|
it 'reconnects the websocket if it has been idle for too long' do
|
203
199
|
allow(socket).to receive(:time_since_last_message).and_return(75)
|
204
200
|
allow(socket).to receive(:connected?).and_return(true)
|
@@ -206,6 +202,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
206
202
|
expect(socket).to receive(:restart_async)
|
207
203
|
client.run_ping!
|
208
204
|
end
|
205
|
+
|
209
206
|
[
|
210
207
|
EOFError,
|
211
208
|
Errno::ECONNRESET,
|
@@ -266,30 +263,43 @@ RSpec.describe Slack::RealTime::Client do
|
|
266
263
|
it 'sets url' do
|
267
264
|
expect(client.url).to eq url
|
268
265
|
end
|
266
|
+
|
269
267
|
it 'sets team' do
|
270
268
|
expect(client.team.domain).to eq 'dblockdotorg'
|
271
269
|
end
|
270
|
+
|
272
271
|
it 'sets self' do
|
273
272
|
expect(client.self.id).to eq 'U0J1GAHN1'
|
274
273
|
end
|
274
|
+
|
275
|
+
it 'no teams' do
|
276
|
+
expect(client.teams).to be_nil
|
277
|
+
end
|
278
|
+
|
275
279
|
it 'no users' do
|
276
280
|
expect(client.users).to be_nil
|
277
281
|
end
|
278
|
-
|
279
|
-
|
282
|
+
|
283
|
+
it 'no bots' do
|
284
|
+
expect(client.bots).to be_nil
|
280
285
|
end
|
281
|
-
|
282
|
-
|
286
|
+
|
287
|
+
it 'no public channels' do
|
288
|
+
expect(client.public_channels).to be_nil
|
283
289
|
end
|
290
|
+
|
291
|
+
it 'no private channels' do
|
292
|
+
expect(client.private_channels).to be_nil
|
293
|
+
end
|
294
|
+
|
284
295
|
it 'no ims' do
|
285
296
|
expect(client.ims).to be_nil
|
286
297
|
end
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
it 'no groups' do
|
291
|
-
expect(client.groups).to be_nil
|
298
|
+
|
299
|
+
it 'no mpims' do
|
300
|
+
expect(client.mpims).to be_nil
|
292
301
|
end
|
302
|
+
|
293
303
|
it 'includes team name in to_s' do
|
294
304
|
expect(client.to_s).to eq(
|
295
305
|
"id=#{client.team.id}, name=#{client.team.name}, domain=#{client.team.domain}"
|
@@ -300,14 +310,17 @@ RSpec.describe Slack::RealTime::Client do
|
|
300
310
|
it 'uses web client to fetch url' do
|
301
311
|
expect(client.web_client).to be_a Slack::Web::Client
|
302
312
|
end
|
313
|
+
|
303
314
|
it 'remembers socket' do
|
304
315
|
expect(client.instance_variable_get(:@socket)).to eq socket
|
305
316
|
end
|
317
|
+
|
306
318
|
it 'cannot be invoked twice' do
|
307
319
|
expect do
|
308
320
|
client.start!
|
309
321
|
end.to raise_error Slack::RealTime::Client::ClientAlreadyStartedError
|
310
322
|
end
|
323
|
+
|
311
324
|
describe '#stop!' do
|
312
325
|
before do
|
313
326
|
allow(socket).to receive(:disconnect!)
|
@@ -338,6 +351,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
338
351
|
it 'sets store to nil' do
|
339
352
|
expect(client.store).to be_nil
|
340
353
|
end
|
354
|
+
|
341
355
|
it "doesn't handle events" do
|
342
356
|
event = Slack::RealTime::Event.new(
|
343
357
|
'type' => 'team_rename',
|
@@ -346,12 +360,15 @@ RSpec.describe Slack::RealTime::Client do
|
|
346
360
|
expect(client).not_to receive(:run_handlers)
|
347
361
|
client.send(:dispatch, event)
|
348
362
|
end
|
363
|
+
|
349
364
|
it 'self' do
|
350
365
|
expect(client.self).to be_nil
|
351
366
|
end
|
367
|
+
|
352
368
|
it 'team' do
|
353
369
|
expect(client.team).to be_nil
|
354
370
|
end
|
371
|
+
|
355
372
|
describe 'to_s' do
|
356
373
|
it 'defaults to class instance' do
|
357
374
|
expect(client.to_s).to match(/^#<Slack::RealTime::Client:0x\h+>$/)
|
@@ -366,15 +383,19 @@ RSpec.describe Slack::RealTime::Client do
|
|
366
383
|
it 'sets ping' do
|
367
384
|
expect(client.websocket_ping).to eq 30
|
368
385
|
end
|
386
|
+
|
369
387
|
it "doesn't set proxy" do
|
370
388
|
expect(client.websocket_proxy).to be_nil
|
371
389
|
end
|
390
|
+
|
372
391
|
it 'defaults logger' do
|
373
392
|
expect(client.send(:logger)).to be_a ::Logger
|
374
393
|
end
|
394
|
+
|
375
395
|
it 'sets default store_class' do
|
376
|
-
expect(client.send(:store_class)).to eq Slack::RealTime::
|
396
|
+
expect(client.send(:store_class)).to eq Slack::RealTime::Stores::Starter
|
377
397
|
end
|
398
|
+
|
378
399
|
(Slack::RealTime::Config::ATTRIBUTES - %i[logger store_class token]).each do |key|
|
379
400
|
it "sets #{key}" do
|
380
401
|
expect(client.send(key)).to eq Slack::RealTime::Config.send(key)
|
@@ -387,6 +408,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
387
408
|
client.websocket_ping = 30
|
388
409
|
expect(client.run_ping?).to be true
|
389
410
|
end
|
411
|
+
|
390
412
|
it 'returns false when websocket_ping is less than 1' do
|
391
413
|
client.websocket_ping = 0
|
392
414
|
expect(client.run_ping?).to be false
|
@@ -416,6 +438,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
416
438
|
it 'exposes public logger' do
|
417
439
|
expect(client.logger).to be_a(::Logger)
|
418
440
|
end
|
441
|
+
|
419
442
|
it 'exposes public logger=' do
|
420
443
|
expect { client.logger = nil }.not_to raise_error(NoMethodError)
|
421
444
|
end
|
@@ -441,12 +464,14 @@ RSpec.describe Slack::RealTime::Client do
|
|
441
464
|
it 'sets ping' do
|
442
465
|
expect(client.websocket_ping).to eq 15
|
443
466
|
end
|
444
|
-
|
467
|
+
|
468
|
+
it 'creates a connection with custom ping', vcr: { cassette_name: 'web/rtm_connect' } do
|
445
469
|
expect(Slack::RealTime::Concurrency::Mock::WebSocket).to(
|
446
470
|
receive(:new).with(url, nil, { ping: 15 }).and_return(ws)
|
447
471
|
)
|
448
472
|
client.start!
|
449
473
|
end
|
474
|
+
|
450
475
|
it 'sets start_options' do
|
451
476
|
expect(client.start_options).to eq(request: { timeout: 180 })
|
452
477
|
end
|
@@ -470,7 +495,8 @@ RSpec.describe Slack::RealTime::Client do
|
|
470
495
|
headers: { 'User-Agent' => 'ruby' }
|
471
496
|
)
|
472
497
|
end
|
473
|
-
|
498
|
+
|
499
|
+
it 'creates a connection with custom proxy', vcr: { cassette_name: 'web/rtm_connect' } do
|
474
500
|
expect(Slack::RealTime::Concurrency::Mock::WebSocket).to receive(:new).with(
|
475
501
|
url,
|
476
502
|
nil,
|
@@ -490,14 +516,15 @@ RSpec.describe Slack::RealTime::Client do
|
|
490
516
|
context 'start_options' do
|
491
517
|
before do
|
492
518
|
described_class.configure do |config|
|
493
|
-
config.start_options = {
|
519
|
+
config.start_options = { presence_sub: true }
|
494
520
|
end
|
495
521
|
end
|
496
522
|
|
497
523
|
describe '#initialize' do
|
498
524
|
it 'sets start_options' do
|
499
|
-
expect(client.start_options).to eq(
|
525
|
+
expect(client.start_options).to eq(presence_sub: true)
|
500
526
|
end
|
527
|
+
|
501
528
|
context 'start!' do
|
502
529
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
503
530
|
|
@@ -507,9 +534,9 @@ RSpec.describe Slack::RealTime::Client do
|
|
507
534
|
allow(socket).to receive(:start_sync)
|
508
535
|
end
|
509
536
|
|
510
|
-
it 'calls
|
537
|
+
it 'calls rtm.connect with start options', vcr: { cassette_name: 'web/rtm_connect' } do
|
511
538
|
expect(client.web_client).to(
|
512
|
-
receive(:
|
539
|
+
receive(:rtm_connect).with({ presence_sub: true }).and_call_original
|
513
540
|
)
|
514
541
|
client.start!
|
515
542
|
end
|
@@ -518,7 +545,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
518
545
|
end
|
519
546
|
|
520
547
|
context 'store_class' do
|
521
|
-
context '
|
548
|
+
context 'when configured with Starter class' do
|
522
549
|
before do
|
523
550
|
described_class.configure do |config|
|
524
551
|
config.store_class = Slack::RealTime::Stores::Starter
|
@@ -526,13 +553,15 @@ RSpec.describe Slack::RealTime::Client do
|
|
526
553
|
end
|
527
554
|
|
528
555
|
describe '#initialize' do
|
529
|
-
it 'can
|
530
|
-
client = described_class.new(store_class: Slack::RealTime::Store)
|
531
|
-
expect(client.send(:store_class)).to eq Slack::RealTime::Store
|
556
|
+
it 'can override the configured store class' do
|
557
|
+
client = described_class.new(store_class: Slack::RealTime::Stores::Store)
|
558
|
+
expect(client.send(:store_class)).to eq Slack::RealTime::Stores::Store
|
532
559
|
end
|
560
|
+
|
533
561
|
it 'sets store_class' do
|
534
562
|
expect(client.send(:store_class)).to eq(Slack::RealTime::Stores::Starter)
|
535
563
|
end
|
564
|
+
|
536
565
|
context 'start!' do
|
537
566
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
538
567
|
|
@@ -549,73 +578,6 @@ RSpec.describe Slack::RealTime::Client do
|
|
549
578
|
end
|
550
579
|
end
|
551
580
|
end
|
552
|
-
|
553
|
-
context 'store' do
|
554
|
-
before do
|
555
|
-
described_class.configure do |config|
|
556
|
-
config.store_class = Slack::RealTime::Stores::Store
|
557
|
-
end
|
558
|
-
end
|
559
|
-
|
560
|
-
describe '#initialize' do
|
561
|
-
context 'start!' do
|
562
|
-
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
563
|
-
|
564
|
-
before do
|
565
|
-
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
566
|
-
allow(socket).to receive(:connect!)
|
567
|
-
allow(socket).to receive(:start_sync)
|
568
|
-
end
|
569
|
-
|
570
|
-
it 'calls rtm_start and not rtm_connect', vcr: { cassette_name: 'web/rtm_start' } do
|
571
|
-
expect(client.web_client).to receive(:rtm_start).and_call_original
|
572
|
-
client.start!
|
573
|
-
end
|
574
|
-
end
|
575
|
-
end
|
576
|
-
end
|
577
|
-
end
|
578
|
-
|
579
|
-
context 'start_method' do
|
580
|
-
describe '#initialize' do
|
581
|
-
it 'can be overriden explicitly' do
|
582
|
-
client = described_class.new(start_method: :overriden)
|
583
|
-
expect(client.send(:start_method)).to eq :overriden
|
584
|
-
end
|
585
|
-
context 'with start_method' do
|
586
|
-
before do
|
587
|
-
described_class.configure do |config|
|
588
|
-
config.start_method = :overriden
|
589
|
-
end
|
590
|
-
end
|
591
|
-
|
592
|
-
it 'sets start_method' do
|
593
|
-
expect(client.send(:start_method)).to eq :overriden
|
594
|
-
end
|
595
|
-
it 'calls the overriden method' do
|
596
|
-
expect(client.web_client).to receive(:overriden).and_raise('overriden')
|
597
|
-
expect do
|
598
|
-
client.start!
|
599
|
-
end.to raise_error RuntimeError, 'overriden'
|
600
|
-
end
|
601
|
-
end
|
602
|
-
|
603
|
-
context 'start!' do
|
604
|
-
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
605
|
-
|
606
|
-
before do
|
607
|
-
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
608
|
-
allow(socket).to receive(:connect!)
|
609
|
-
allow(socket).to receive(:start_sync)
|
610
|
-
end
|
611
|
-
|
612
|
-
it 'defaults to :rtm_start when using full store',
|
613
|
-
vcr: { cassette_name: 'web/rtm_start' } do
|
614
|
-
expect(client.web_client).to receive(:rtm_start).and_call_original
|
615
|
-
client.start!
|
616
|
-
end
|
617
|
-
end
|
618
|
-
end
|
619
581
|
end
|
620
582
|
end
|
621
583
|
end
|
@@ -1,13 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/
|
4
|
+
RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_connect' } do
|
5
5
|
include_context 'connected client'
|
6
6
|
|
7
7
|
context 'bot' do
|
8
|
-
it 'sets bot data on rtm.start' do
|
9
|
-
expect(client.bots.count).to eq 83
|
10
|
-
end
|
11
8
|
it 'bot_added' do
|
12
9
|
expect do
|
13
10
|
event = Slack::RealTime::Event.new(
|
@@ -27,19 +24,24 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
27
24
|
expect(bot['name']).to eq 'hugbot'
|
28
25
|
expect(bot['icons']['image_48']).to eq 'https:\/\/slack.com\/path\/to\/hugbot_48.png'
|
29
26
|
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
27
|
+
|
28
|
+
context 'with bot loaded in the store' do
|
29
|
+
include_context 'loaded client'
|
30
|
+
|
31
|
+
it 'bot_changed' do
|
32
|
+
expect do
|
33
|
+
event = Slack::RealTime::Event.new(
|
34
|
+
'type' => 'bot_changed',
|
35
|
+
'bot' => {
|
36
|
+
'id' => 'B0751JU2H',
|
37
|
+
'name' => 'hugbot'
|
38
|
+
}
|
39
|
+
)
|
40
|
+
client.send(:dispatch, event)
|
41
|
+
end.not_to change(client.bots, :count)
|
42
|
+
bot = client.bots['B0751JU2H']
|
43
|
+
expect(bot['name']).to eq 'hugbot'
|
44
|
+
end
|
43
45
|
end
|
44
46
|
end
|
45
47
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/
|
4
|
+
RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_connect' } do
|
5
5
|
include_context 'connected client'
|
6
6
|
|
7
7
|
it 'is not fatal' do
|
@@ -1,13 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/
|
4
|
+
RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_connect' } do
|
5
5
|
include_context 'connected client'
|
6
6
|
|
7
7
|
context 'im' do
|
8
|
-
it 'sets im data' do
|
9
|
-
expect(client.ims.count).to eq 10
|
10
|
-
end
|
11
8
|
it 'im_created' do
|
12
9
|
expect(client.ims['CDEADBEEF']).to be_nil
|
13
10
|
event = Slack::RealTime::Event.new(
|
@@ -22,27 +19,33 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
22
19
|
expect(im).not_to be_nil
|
23
20
|
expect(im.name).to eq 'beef'
|
24
21
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
22
|
+
|
23
|
+
context 'with im loaded in the store' do
|
24
|
+
include_context 'loaded client'
|
25
|
+
|
26
|
+
it 'im_open' do
|
27
|
+
im = client.ims['D0J1H6QTV']
|
28
|
+
expect(im).not_to be_nil
|
29
|
+
im.is_open = false
|
30
|
+
event = Slack::RealTime::Event.new(
|
31
|
+
'type' => 'im_open',
|
32
|
+
'channel' => 'D0J1H6QTV'
|
33
|
+
)
|
34
|
+
client.send(:dispatch, event)
|
35
|
+
expect(im.is_open).to be true
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'im_close' do
|
39
|
+
im = client.ims['D0J1H6QTV']
|
40
|
+
expect(im).not_to be_nil
|
41
|
+
expect(im.is_open).to be true
|
42
|
+
event = Slack::RealTime::Event.new(
|
43
|
+
'type' => 'im_close',
|
44
|
+
'channel' => 'D0J1H6QTV'
|
45
|
+
)
|
46
|
+
client.send(:dispatch, event)
|
47
|
+
expect(im.is_open).to be false
|
48
|
+
end
|
46
49
|
end
|
47
50
|
end
|
48
51
|
end
|
@@ -1,15 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/
|
4
|
+
RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_connect' } do
|
5
5
|
include_context 'connected client'
|
6
|
+
include_context 'loaded client'
|
6
7
|
|
7
|
-
context '
|
8
|
-
it 'sets
|
9
|
-
expect(client.
|
8
|
+
context 'private channel' do
|
9
|
+
it 'sets private channel data' do
|
10
|
+
expect(client.private_channels.count).to eq 1
|
10
11
|
end
|
12
|
+
|
11
13
|
it 'group_joined' do
|
12
|
-
expect(client.
|
14
|
+
expect(client.private_channels['CDEADBEEF']).to be_nil
|
13
15
|
event = Slack::RealTime::Event.new(
|
14
16
|
'type' => 'group_joined',
|
15
17
|
'channel' => {
|
@@ -18,43 +20,47 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
18
20
|
}
|
19
21
|
)
|
20
22
|
client.send(:dispatch, event)
|
21
|
-
|
22
|
-
expect(
|
23
|
-
expect(
|
23
|
+
channel = client.private_channels['CDEADBEEF']
|
24
|
+
expect(channel).not_to be_nil
|
25
|
+
expect(channel.name).to eq 'beef'
|
24
26
|
end
|
27
|
+
|
25
28
|
it 'group_left' do
|
26
|
-
|
27
|
-
expect(
|
29
|
+
channel = client.private_channels['G0K7EV5A7']
|
30
|
+
expect(channel.members).to include client.self.id
|
28
31
|
event = Slack::RealTime::Event.new(
|
29
32
|
'type' => 'group_left',
|
30
33
|
'channel' => 'G0K7EV5A7'
|
31
34
|
)
|
32
35
|
client.send(:dispatch, event)
|
33
|
-
expect(
|
36
|
+
expect(client.private_channels['G0K7EV5A7']).to be_nil
|
34
37
|
end
|
38
|
+
|
35
39
|
it 'group_archive' do
|
36
|
-
|
37
|
-
expect(
|
40
|
+
channel = client.private_channels['G0K7EV5A7']
|
41
|
+
expect(channel.is_archived).to be false
|
38
42
|
event = Slack::RealTime::Event.new(
|
39
43
|
'type' => 'group_archive',
|
40
44
|
'channel' => 'G0K7EV5A7'
|
41
45
|
)
|
42
46
|
client.send(:dispatch, event)
|
43
|
-
expect(
|
47
|
+
expect(channel.is_archived).to be true
|
44
48
|
end
|
49
|
+
|
45
50
|
it 'group_unarchive' do
|
46
|
-
|
47
|
-
|
51
|
+
channel = client.private_channels['G0K7EV5A7']
|
52
|
+
channel.is_archived = true
|
48
53
|
event = Slack::RealTime::Event.new(
|
49
54
|
'type' => 'group_unarchive',
|
50
55
|
'channel' => 'G0K7EV5A7'
|
51
56
|
)
|
52
57
|
client.send(:dispatch, event)
|
53
|
-
expect(
|
58
|
+
expect(channel.is_archived).to be false
|
54
59
|
end
|
60
|
+
|
55
61
|
it 'group_rename' do
|
56
|
-
|
57
|
-
expect(
|
62
|
+
channel = client.private_channels['G0K7EV5A7']
|
63
|
+
expect(channel.name).to eq 'mpdm-dblock--rubybot--player1-1'
|
58
64
|
event = Slack::RealTime::Event.new(
|
59
65
|
'type' => 'group_rename',
|
60
66
|
'channel' => {
|
@@ -64,28 +70,30 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
64
70
|
}
|
65
71
|
)
|
66
72
|
client.send(:dispatch, event)
|
67
|
-
expect(
|
73
|
+
expect(channel.name).to eq 'updated'
|
68
74
|
end
|
75
|
+
|
69
76
|
it 'group_open' do
|
70
|
-
|
71
|
-
expect(
|
77
|
+
channel = client.private_channels['G0K7EV5A7']
|
78
|
+
expect(channel).not_to be_nil
|
72
79
|
event = Slack::RealTime::Event.new(
|
73
80
|
'type' => 'group_open',
|
74
81
|
'channel' => 'G0K7EV5A7'
|
75
82
|
)
|
76
83
|
client.send(:dispatch, event)
|
77
|
-
expect(
|
84
|
+
expect(channel.is_open).to be true
|
78
85
|
end
|
86
|
+
|
79
87
|
it 'group_close' do
|
80
|
-
|
81
|
-
expect(
|
82
|
-
|
88
|
+
channel = client.private_channels['G0K7EV5A7']
|
89
|
+
expect(channel).not_to be_nil
|
90
|
+
channel.is_open = true
|
83
91
|
event = Slack::RealTime::Event.new(
|
84
92
|
'type' => 'group_close',
|
85
93
|
'channel' => 'G0K7EV5A7'
|
86
94
|
)
|
87
95
|
client.send(:dispatch, event)
|
88
|
-
expect(
|
96
|
+
expect(channel.is_open).to be false
|
89
97
|
end
|
90
98
|
end
|
91
99
|
end
|