slack-ruby-client 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/danger.yml +19 -0
- data/.github/workflows/integtest.yml +25 -0
- data/.github/workflows/rubocop.yml +13 -0
- data/.github/workflows/test.yml +34 -0
- data/.gitignore +5 -3
- data/.rubocop.yml +2 -1
- data/.rubocop_todo.yml +86 -26
- data/CHANGELOG.md +13 -0
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +18 -1
- data/Gemfile.danger +6 -0
- data/README.md +3 -2
- data/RELEASING.md +1 -1
- data/bin/commands/admin_apps_requests.rb +11 -0
- data/bin/commands/admin_conversations.rb +1 -0
- data/bin/commands/admin_emoji.rb +2 -2
- data/bin/commands/admin_users_unsupportedVersions.rb +15 -0
- data/bin/commands/apps_manifest.rb +1 -0
- data/bin/commands/bookmarks.rb +52 -0
- data/bin/commands/team.rb +1 -0
- data/bin/commands.rb +2 -0
- data/lib/slack/real_time/client.rb +2 -2
- data/lib/slack/version.rb +1 -1
- data/lib/slack/web/api/endpoints/admin_apps_requests.rb +16 -0
- data/lib/slack/web/api/endpoints/admin_conversations.rb +2 -0
- data/lib/slack/web/api/endpoints/admin_emoji.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_users_unsupportedVersions.rb +25 -0
- data/lib/slack/web/api/endpoints/apps_manifest.rb +2 -0
- data/lib/slack/web/api/endpoints/bookmarks.rb +86 -0
- data/lib/slack/web/api/endpoints/chat.rb +1 -1
- data/lib/slack/web/api/endpoints/team.rb +2 -0
- data/lib/slack/web/api/endpoints.rb +4 -0
- data/lib/slack/web/api/errors.rb +28 -2
- data/lib/slack/web/api/patches/chat.1.patch +1 -1
- data/lib/slack/web/faraday/connection.rb +4 -4
- data/lib/slack/web/faraday/request.rb +2 -0
- data/lib/slack/web/faraday/response/raise_error.rb +2 -10
- data/lib/slack/web/faraday/response/wrap_error.rb +1 -1
- data/lib/slack-ruby-client.rb +2 -1
- data/lib/tasks/real_time.rake +1 -3
- data/slack-ruby-client.gemspec +5 -13
- data/spec/integration/integration_spec.rb +1 -1
- data/spec/slack/events/request_spec.rb +1 -1
- data/spec/slack/real_time/client_spec.rb +20 -18
- data/spec/slack/real_time/event_handlers/channel_spec.rb +8 -8
- data/spec/slack/real_time/event_handlers/group_spec.rb +2 -2
- data/spec/slack/real_time/event_handlers/im_spec.rb +2 -2
- data/spec/slack/real_time/store_spec.rb +2 -2
- data/spec/slack/slack_spec.rb +4 -4
- data/spec/slack/version_spec.rb +1 -1
- data/spec/slack/web/api/endpoints/admin_apps_requests_spec.rb +5 -0
- data/spec/slack/web/api/endpoints/admin_users_unsupportedVersions_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/bookmarks_spec.rb +40 -0
- data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +28 -16
- data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +4 -2
- data/spec/slack/web/api/endpoints/custom_specs/views_spec.rb +22 -14
- data/spec/slack/web/api/pagination/cursor_spec.rb +7 -7
- data/spec/slack/web/client_spec.rb +25 -7
- data/spec/slack/web/faraday/response/raise_error_spec.rb +1 -1
- data/spec/support/real_time/connected_client.rb +1 -1
- metadata +25 -154
- data/.travis.yml +0 -29
@@ -73,7 +73,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
73
73
|
|
74
74
|
before do
|
75
75
|
allow(Slack::RealTime::Socket).to(
|
76
|
-
receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
|
76
|
+
receive(:new).with(url, { ping: 30, logger: Slack::Logger.default }).and_return(socket)
|
77
77
|
)
|
78
78
|
allow(socket).to receive(:connect!)
|
79
79
|
allow(socket).to receive(:start_sync)
|
@@ -124,7 +124,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
124
124
|
expect(client.web_client).to be_a Slack::Web::Client
|
125
125
|
end
|
126
126
|
it 'remembers socket' do
|
127
|
-
expect(client.instance_variable_get(
|
127
|
+
expect(client.instance_variable_get(:@socket)).to eq socket
|
128
128
|
end
|
129
129
|
it 'cannot be invoked twice' do
|
130
130
|
expect do
|
@@ -138,7 +138,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
138
138
|
end
|
139
139
|
|
140
140
|
it 'cannot be invoked twice' do
|
141
|
-
client.instance_variable_set(
|
141
|
+
client.instance_variable_set(:@socket, nil) # caused by a :close callback
|
142
142
|
expect do
|
143
143
|
client.stop!
|
144
144
|
end.to raise_error Slack::RealTime::Client::ClientNotStartedError
|
@@ -175,7 +175,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
175
175
|
end
|
176
176
|
|
177
177
|
it 'returns false when event is nil' do
|
178
|
-
expect(client.send(:run_handlers, 'example', {})).to
|
178
|
+
expect(client.send(:run_handlers, 'example', {})).to be_nil
|
179
179
|
end
|
180
180
|
end
|
181
181
|
end
|
@@ -186,7 +186,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
186
186
|
|
187
187
|
before do
|
188
188
|
allow(Slack::RealTime::Socket).to(
|
189
|
-
receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
|
189
|
+
receive(:new).with(url, { ping: 30, logger: Slack::Logger.default }).and_return(socket)
|
190
190
|
)
|
191
191
|
allow(socket).to receive(:connect!)
|
192
192
|
allow(socket).to receive(:start_async)
|
@@ -255,7 +255,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
255
255
|
|
256
256
|
before do
|
257
257
|
allow(Slack::RealTime::Socket).to(
|
258
|
-
receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
|
258
|
+
receive(:new).with(url, { ping: 30, logger: Slack::Logger.default }).and_return(socket)
|
259
259
|
)
|
260
260
|
allow(socket).to receive(:connect!)
|
261
261
|
allow(socket).to receive(:start_sync)
|
@@ -301,7 +301,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
301
301
|
expect(client.web_client).to be_a Slack::Web::Client
|
302
302
|
end
|
303
303
|
it 'remembers socket' do
|
304
|
-
expect(client.instance_variable_get(
|
304
|
+
expect(client.instance_variable_get(:@socket)).to eq socket
|
305
305
|
end
|
306
306
|
it 'cannot be invoked twice' do
|
307
307
|
expect do
|
@@ -315,7 +315,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
315
315
|
end
|
316
316
|
|
317
317
|
it 'cannot be invoked twice' do
|
318
|
-
client.instance_variable_set(
|
318
|
+
client.instance_variable_set(:@socket, nil) # caused by a :close callback
|
319
319
|
expect do
|
320
320
|
client.stop!
|
321
321
|
end.to raise_error Slack::RealTime::Client::ClientNotStartedError
|
@@ -336,7 +336,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
336
336
|
let(:url) { 'wss://mpmulti-w5tz.slack-msgs.com/websocket/uid' }
|
337
337
|
|
338
338
|
it 'sets store to nil' do
|
339
|
-
expect(client.store).to
|
339
|
+
expect(client.store).to be_nil
|
340
340
|
end
|
341
341
|
it "doesn't handle events" do
|
342
342
|
event = Slack::RealTime::Event.new(
|
@@ -347,10 +347,10 @@ RSpec.describe Slack::RealTime::Client do
|
|
347
347
|
client.send(:dispatch, event)
|
348
348
|
end
|
349
349
|
it 'self' do
|
350
|
-
expect(client.self).to
|
350
|
+
expect(client.self).to be_nil
|
351
351
|
end
|
352
352
|
it 'team' do
|
353
|
-
expect(client.team).to
|
353
|
+
expect(client.team).to be_nil
|
354
354
|
end
|
355
355
|
describe 'to_s' do
|
356
356
|
it 'defaults to class instance' do
|
@@ -367,7 +367,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
367
367
|
expect(client.websocket_ping).to eq 30
|
368
368
|
end
|
369
369
|
it "doesn't set proxy" do
|
370
|
-
expect(client.websocket_proxy).to
|
370
|
+
expect(client.websocket_proxy).to be_nil
|
371
371
|
end
|
372
372
|
it 'defaults logger' do
|
373
373
|
expect(client.send(:logger)).to be_a ::Logger
|
@@ -443,7 +443,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
443
443
|
end
|
444
444
|
it 'creates a connection with custom ping', vcr: { cassette_name: 'web/rtm_start' } do
|
445
445
|
expect(Slack::RealTime::Concurrency::Mock::WebSocket).to(
|
446
|
-
receive(:new).with(url, nil, ping: 15).and_return(ws)
|
446
|
+
receive(:new).with(url, nil, { ping: 15 }).and_return(ws)
|
447
447
|
)
|
448
448
|
client.start!
|
449
449
|
end
|
@@ -474,10 +474,12 @@ RSpec.describe Slack::RealTime::Client do
|
|
474
474
|
expect(Slack::RealTime::Concurrency::Mock::WebSocket).to receive(:new).with(
|
475
475
|
url,
|
476
476
|
nil,
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
477
|
+
{
|
478
|
+
ping: 30,
|
479
|
+
proxy: {
|
480
|
+
origin: 'http://username:password@proxy.example.com',
|
481
|
+
headers: { 'User-Agent' => 'ruby' }
|
482
|
+
}
|
481
483
|
}
|
482
484
|
).and_return(ws)
|
483
485
|
client.start!
|
@@ -507,7 +509,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
507
509
|
|
508
510
|
it 'calls rtm_start with start options', vcr: { cassette_name: 'web/rtm_start' } do
|
509
511
|
expect(client.web_client).to(
|
510
|
-
receive(:rtm_start).with(simple_latest: true).and_call_original
|
512
|
+
receive(:rtm_start).with({ simple_latest: true }).and_call_original
|
511
513
|
)
|
512
514
|
client.start!
|
513
515
|
end
|
@@ -20,7 +20,7 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
20
20
|
expect(channel.is_archived).to be true
|
21
21
|
end
|
22
22
|
it 'channel_created' do
|
23
|
-
expect(client.channels['C024BE91L']).to
|
23
|
+
expect(client.channels['C024BE91L']).to be_nil
|
24
24
|
event = Slack::RealTime::Event.new(
|
25
25
|
'type' => 'channel_created',
|
26
26
|
'channel' => {
|
@@ -32,23 +32,23 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
32
32
|
)
|
33
33
|
client.send(:dispatch, event)
|
34
34
|
channel = client.channels['C024BE91L']
|
35
|
-
expect(channel).not_to
|
35
|
+
expect(channel).not_to be_nil
|
36
36
|
expect(channel.name).to eq 'fun'
|
37
37
|
expect(channel.creator).to eq 'U04KB5WQR'
|
38
38
|
expect(channel.created).to eq 1_360_782_804
|
39
39
|
end
|
40
40
|
it 'channel_deleted' do
|
41
|
-
expect(client.channels['C0HLE0BBL']).not_to
|
41
|
+
expect(client.channels['C0HLE0BBL']).not_to be_nil
|
42
42
|
event = Slack::RealTime::Event.new(
|
43
43
|
'type' => 'channel_deleted',
|
44
44
|
'channel' => 'C0HLE0BBL'
|
45
45
|
)
|
46
46
|
client.send(:dispatch, event)
|
47
|
-
expect(client.channels['C0HLE0BBL']).to
|
47
|
+
expect(client.channels['C0HLE0BBL']).to be_nil
|
48
48
|
end
|
49
49
|
context 'channel_joined' do
|
50
50
|
it 'creates channel' do
|
51
|
-
expect(client.channels['CDEADBEEF']).to
|
51
|
+
expect(client.channels['CDEADBEEF']).to be_nil
|
52
52
|
event = Slack::RealTime::Event.new(
|
53
53
|
'type' => 'channel_joined',
|
54
54
|
'channel' => {
|
@@ -58,11 +58,11 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
58
58
|
)
|
59
59
|
client.send(:dispatch, event)
|
60
60
|
channel = client.channels['CDEADBEEF']
|
61
|
-
expect(channel).not_to
|
61
|
+
expect(channel).not_to be_nil
|
62
62
|
expect(channel.name).to eq 'beef'
|
63
63
|
end
|
64
64
|
it 'updates channel' do
|
65
|
-
expect(client.channels['CDEADBEEF']).to
|
65
|
+
expect(client.channels['CDEADBEEF']).to be_nil
|
66
66
|
client.channels['CDEADBEEF'] =
|
67
67
|
Slack::RealTime::Models::Channel.new('id' => 'CDEADBEEF', name: 'beef')
|
68
68
|
event = Slack::RealTime::Event.new(
|
@@ -75,7 +75,7 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
75
75
|
)
|
76
76
|
client.send(:dispatch, event)
|
77
77
|
channel = client.channels['CDEADBEEF']
|
78
|
-
expect(channel).not_to
|
78
|
+
expect(channel).not_to be_nil
|
79
79
|
expect(channel.updated).to be true
|
80
80
|
end
|
81
81
|
end
|
@@ -9,7 +9,7 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
9
9
|
expect(client.groups.count).to eq 1
|
10
10
|
end
|
11
11
|
it 'group_joined' do
|
12
|
-
expect(client.groups['CDEADBEEF']).to
|
12
|
+
expect(client.groups['CDEADBEEF']).to be_nil
|
13
13
|
event = Slack::RealTime::Event.new(
|
14
14
|
'type' => 'group_joined',
|
15
15
|
'channel' => {
|
@@ -19,7 +19,7 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
19
19
|
)
|
20
20
|
client.send(:dispatch, event)
|
21
21
|
group = client.groups['CDEADBEEF']
|
22
|
-
expect(group).not_to
|
22
|
+
expect(group).not_to be_nil
|
23
23
|
expect(group.name).to eq 'beef'
|
24
24
|
end
|
25
25
|
it 'group_left' do
|
@@ -9,7 +9,7 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
9
9
|
expect(client.ims.count).to eq 10
|
10
10
|
end
|
11
11
|
it 'im_created' do
|
12
|
-
expect(client.ims['CDEADBEEF']).to
|
12
|
+
expect(client.ims['CDEADBEEF']).to be_nil
|
13
13
|
event = Slack::RealTime::Event.new(
|
14
14
|
'type' => 'im_created',
|
15
15
|
'channel' => {
|
@@ -19,7 +19,7 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
19
19
|
)
|
20
20
|
client.send(:dispatch, event)
|
21
21
|
im = client.ims['CDEADBEEF']
|
22
|
-
expect(im).not_to
|
22
|
+
expect(im).not_to be_nil
|
23
23
|
expect(im.name).to eq 'beef'
|
24
24
|
end
|
25
25
|
it 'im_open' do
|
@@ -4,9 +4,9 @@ require 'spec_helper'
|
|
4
4
|
RSpec.describe Slack::RealTime::Store do
|
5
5
|
it 'can be initialized with an empty hash' do
|
6
6
|
store = described_class.new(Hashie::Mash.new)
|
7
|
-
expect(store.self).to
|
7
|
+
expect(store.self).to be_nil
|
8
8
|
expect(store.groups.count).to eq 0
|
9
|
-
expect(store.team).to
|
9
|
+
expect(store.team).to be_nil
|
10
10
|
expect(store.teams.count).to eq 0
|
11
11
|
end
|
12
12
|
end
|
data/spec/slack/slack_spec.rb
CHANGED
@@ -22,7 +22,7 @@ describe Slack do
|
|
22
22
|
context 'globals' do
|
23
23
|
let(:command) do
|
24
24
|
"\"#{slack}\" --vcr-cassette-name=web/auth_test_success " \
|
25
|
-
|
25
|
+
'--slack-api-token=token -d auth test 2>&1'
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'enables request and response logging with -d' do
|
@@ -44,7 +44,7 @@ describe Slack do
|
|
44
44
|
context 'bad auth' do
|
45
45
|
let(:command) do
|
46
46
|
"\"#{slack}\" --vcr-cassette-name=web/auth_test_error " \
|
47
|
-
|
47
|
+
'--slack-api-token=token auth test 2>&1'
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'fails with an exception' do
|
@@ -56,7 +56,7 @@ describe Slack do
|
|
56
56
|
context 'good auth' do
|
57
57
|
let(:command) do
|
58
58
|
"\"#{slack}\" --vcr-cassette-name=web/auth_test_success " \
|
59
|
-
|
59
|
+
'--slack-api-token=token auth test 2>&1'
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'succeeds' do
|
@@ -79,7 +79,7 @@ describe Slack do
|
|
79
79
|
describe '#users' do
|
80
80
|
let(:command) do
|
81
81
|
"\"#{slack}\" --vcr-cassette-name=web/users_list " \
|
82
|
-
|
82
|
+
'--slack-api-token=token users list --presence=true 2>&1'
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'list' do
|
data/spec/slack/version_spec.rb
CHANGED
@@ -5,4 +5,9 @@ require 'spec_helper'
|
|
5
5
|
|
6
6
|
RSpec.describe Slack::Web::Api::Endpoints::AdminAppsRequests do
|
7
7
|
let(:client) { Slack::Web::Client.new }
|
8
|
+
context 'admin.apps.requests_cancel' do
|
9
|
+
it 'requires request_id' do
|
10
|
+
expect { client.admin_apps_requests_cancel }.to raise_error ArgumentError, /Required arguments :request_id missing/
|
11
|
+
end
|
12
|
+
end
|
8
13
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# This file was auto-generated by lib/tasks/web.rake
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
RSpec.describe Slack::Web::Api::Endpoints::Bookmarks do
|
7
|
+
let(:client) { Slack::Web::Client.new }
|
8
|
+
context 'bookmarks_add' do
|
9
|
+
it 'requires channel_id' do
|
10
|
+
expect { client.bookmarks_add(title: %q[], type: %q[]) }.to raise_error ArgumentError, /Required arguments :channel_id missing/
|
11
|
+
end
|
12
|
+
it 'requires title' do
|
13
|
+
expect { client.bookmarks_add(channel_id: %q[], type: %q[]) }.to raise_error ArgumentError, /Required arguments :title missing/
|
14
|
+
end
|
15
|
+
it 'requires type' do
|
16
|
+
expect { client.bookmarks_add(channel_id: %q[], title: %q[]) }.to raise_error ArgumentError, /Required arguments :type missing/
|
17
|
+
end
|
18
|
+
end
|
19
|
+
context 'bookmarks_edit' do
|
20
|
+
it 'requires bookmark_id' do
|
21
|
+
expect { client.bookmarks_edit(channel_id: %q[]) }.to raise_error ArgumentError, /Required arguments :bookmark_id missing/
|
22
|
+
end
|
23
|
+
it 'requires channel_id' do
|
24
|
+
expect { client.bookmarks_edit(bookmark_id: %q[]) }.to raise_error ArgumentError, /Required arguments :channel_id missing/
|
25
|
+
end
|
26
|
+
end
|
27
|
+
context 'bookmarks_list' do
|
28
|
+
it 'requires channel_id' do
|
29
|
+
expect { client.bookmarks_list }.to raise_error ArgumentError, /Required arguments :channel_id missing/
|
30
|
+
end
|
31
|
+
end
|
32
|
+
context 'bookmarks_remove' do
|
33
|
+
it 'requires bookmark_id' do
|
34
|
+
expect { client.bookmarks_remove(channel_id: %q[]) }.to raise_error ArgumentError, /Required arguments :bookmark_id missing/
|
35
|
+
end
|
36
|
+
it 'requires channel_id' do
|
37
|
+
expect { client.bookmarks_remove(bookmark_id: %q[]) }.to raise_error ArgumentError, /Required arguments :channel_id missing/
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -14,11 +14,13 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
|
|
14
14
|
it 'automatically converts attachments and blocks into JSON' do
|
15
15
|
expect(client).to receive(:post).with(
|
16
16
|
'chat.postEphemeral',
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
{
|
18
|
+
channel: 'channel',
|
19
|
+
text: 'text',
|
20
|
+
user: '123',
|
21
|
+
attachments: '[]',
|
22
|
+
blocks: '[]'
|
23
|
+
}
|
22
24
|
)
|
23
25
|
client.chat_postEphemeral(
|
24
26
|
channel: 'channel',
|
@@ -88,10 +90,12 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
|
|
88
90
|
it 'automatically converts attachments and blocks into JSON' do
|
89
91
|
expect(client).to receive(:post).with(
|
90
92
|
'chat.postMessage',
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
93
|
+
{
|
94
|
+
channel: 'channel',
|
95
|
+
text: 'text',
|
96
|
+
attachments: '[]',
|
97
|
+
blocks: '[]'
|
98
|
+
}
|
95
99
|
)
|
96
100
|
client.chat_postMessage(channel: 'channel', text: 'text', attachments: [], blocks: [])
|
97
101
|
end
|
@@ -131,11 +135,13 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
|
|
131
135
|
it 'automatically converts attachments and blocks into JSON' do
|
132
136
|
expect(client).to receive(:post).with(
|
133
137
|
'chat.update',
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
138
|
+
{
|
139
|
+
channel: 'channel',
|
140
|
+
text: 'text',
|
141
|
+
ts: ts,
|
142
|
+
attachments: '[]',
|
143
|
+
blocks: '[]'
|
144
|
+
}
|
139
145
|
)
|
140
146
|
client.chat_update(channel: 'channel', text: 'text', ts: ts, attachments: [], blocks: [])
|
141
147
|
end
|
@@ -148,9 +154,9 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
|
|
148
154
|
end
|
149
155
|
|
150
156
|
context 'text, attachment and blocks arguments' do
|
151
|
-
it 'requires text, attachments or
|
157
|
+
it 'requires text, attachments, blocks or reply_broadcast' do
|
152
158
|
expect { client.chat_update(channel: 'channel', ts: ts) }.to(
|
153
|
-
raise_error(ArgumentError, /Required arguments :text, :attachments or :
|
159
|
+
raise_error(ArgumentError, /Required arguments :text, :attachments, :blocks or :reply_broadcast missing/)
|
154
160
|
)
|
155
161
|
end
|
156
162
|
it 'only text' do
|
@@ -171,6 +177,12 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
|
|
171
177
|
client.chat_update(channel: 'channel', ts: ts, blocks: [])
|
172
178
|
end.not_to raise_error
|
173
179
|
end
|
180
|
+
it 'only reply_broadcast' do
|
181
|
+
expect(client).to receive(:post).with('chat.update', hash_including(reply_broadcast: true))
|
182
|
+
expect do
|
183
|
+
client.chat_update(channel: 'channel', ts: ts, reply_broadcast: true)
|
184
|
+
end.not_to raise_error
|
185
|
+
end
|
174
186
|
it 'all text, attachments and blocks' do
|
175
187
|
expect(client).to(
|
176
188
|
receive(:post)
|
@@ -8,8 +8,10 @@ RSpec.describe Slack::Web::Api::Endpoints::Dialog do
|
|
8
8
|
it 'automatically converts dialog into JSON' do
|
9
9
|
expect(client).to receive(:post).with(
|
10
10
|
'dialog.open',
|
11
|
-
|
12
|
-
|
11
|
+
{
|
12
|
+
trigger_id: '12345.98765.abcd2358fdea',
|
13
|
+
dialog: '[]'
|
14
|
+
}
|
13
15
|
)
|
14
16
|
client.dialog_open(trigger_id: '12345.98765.abcd2358fdea', dialog: [])
|
15
17
|
end
|
@@ -10,7 +10,7 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
|
|
10
10
|
let(:view_str) { '{"celery":"man"}' }
|
11
11
|
|
12
12
|
it 'automatically converts view into JSON' do
|
13
|
-
expect(client).to receive(:post).with('views.open', trigger_id: trigger_id, view: view_str)
|
13
|
+
expect(client).to receive(:post).with('views.open', { trigger_id: trigger_id, view: view_str })
|
14
14
|
client.views_open(trigger_id: trigger_id, view: { celery: 'man' })
|
15
15
|
end
|
16
16
|
end
|
@@ -19,7 +19,7 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
|
|
19
19
|
let(:view_str) { 'celery man' }
|
20
20
|
|
21
21
|
it 'leaves view as is' do
|
22
|
-
expect(client).to receive(:post).with('views.open', trigger_id: trigger_id, view: view_str)
|
22
|
+
expect(client).to receive(:post).with('views.open', { trigger_id: trigger_id, view: view_str })
|
23
23
|
client.views_open(trigger_id: trigger_id, view: 'celery man')
|
24
24
|
end
|
25
25
|
end
|
@@ -32,10 +32,14 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
|
|
32
32
|
let(:view_str) { '{"celery":"man"}' }
|
33
33
|
|
34
34
|
it 'automatically converts view into JSON' do
|
35
|
-
expect(client).to receive(:post).with(
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
expect(client).to receive(:post).with(
|
36
|
+
'views.publish',
|
37
|
+
{
|
38
|
+
trigger_id: trigger_id,
|
39
|
+
user_id: user_id,
|
40
|
+
view: view_str
|
41
|
+
}
|
42
|
+
)
|
39
43
|
client.views_publish(user_id: user_id, trigger_id: trigger_id, view: { celery: 'man' })
|
40
44
|
end
|
41
45
|
end
|
@@ -44,10 +48,14 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
|
|
44
48
|
let(:view_str) { 'celery man' }
|
45
49
|
|
46
50
|
it 'leaves view as is' do
|
47
|
-
expect(client).to receive(:post).with(
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
+
expect(client).to receive(:post).with(
|
52
|
+
'views.publish',
|
53
|
+
{
|
54
|
+
user_id: user_id,
|
55
|
+
trigger_id: trigger_id,
|
56
|
+
view: view_str
|
57
|
+
}
|
58
|
+
)
|
51
59
|
client.views_publish(user_id: user_id, trigger_id: trigger_id, view: 'celery man')
|
52
60
|
end
|
53
61
|
end
|
@@ -58,7 +66,7 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
|
|
58
66
|
let(:view_str) { '{"celery":"man"}' }
|
59
67
|
|
60
68
|
it 'automatically converts view into JSON' do
|
61
|
-
expect(client).to receive(:post).with('views.push', trigger_id: trigger_id, view: view_str)
|
69
|
+
expect(client).to receive(:post).with('views.push', { trigger_id: trigger_id, view: view_str })
|
62
70
|
client.views_push(trigger_id: trigger_id, view: { celery: 'man' })
|
63
71
|
end
|
64
72
|
end
|
@@ -67,7 +75,7 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
|
|
67
75
|
let(:view_str) { 'celery man' }
|
68
76
|
|
69
77
|
it 'leaves view as is' do
|
70
|
-
expect(client).to receive(:post).with('views.push', trigger_id: trigger_id, view: view_str)
|
78
|
+
expect(client).to receive(:post).with('views.push', { trigger_id: trigger_id, view: view_str })
|
71
79
|
client.views_push(trigger_id: trigger_id, view: 'celery man')
|
72
80
|
end
|
73
81
|
end
|
@@ -78,7 +86,7 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
|
|
78
86
|
let(:view_str) { '{"celery":"man"}' }
|
79
87
|
|
80
88
|
it 'automatically converts view into JSON' do
|
81
|
-
expect(client).to receive(:post).with('views.update', view: view_str)
|
89
|
+
expect(client).to receive(:post).with('views.update', { view: view_str })
|
82
90
|
client.views_update(view: { celery: 'man' })
|
83
91
|
end
|
84
92
|
end
|
@@ -87,7 +95,7 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
|
|
87
95
|
let(:view_str) { 'celery man' }
|
88
96
|
|
89
97
|
it 'leaves view as is' do
|
90
|
-
expect(client).to receive(:post).with('views.update', view: view_str)
|
98
|
+
expect(client).to receive(:post).with('views.update', { view: view_str })
|
91
99
|
client.views_update(view: 'celery man')
|
92
100
|
end
|
93
101
|
end
|
@@ -8,7 +8,7 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
|
|
8
8
|
let(:cursor) { described_class.new(client, 'users_list', {}) }
|
9
9
|
|
10
10
|
it 'provides a default limit' do
|
11
|
-
expect(client).to receive(:users_list).with(limit: 100, cursor: nil)
|
11
|
+
expect(client).to receive(:users_list).with({ limit: 100, cursor: nil })
|
12
12
|
cursor.first
|
13
13
|
end
|
14
14
|
it 'handles blank response metadata' do
|
@@ -36,17 +36,17 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
|
|
36
36
|
it 'sleeps after a TooManyRequestsError' do
|
37
37
|
expect(client).to(
|
38
38
|
receive(:users_list)
|
39
|
-
.with(limit: 100, cursor: nil)
|
39
|
+
.with({ limit: 100, cursor: nil })
|
40
40
|
.ordered
|
41
41
|
.and_return(Slack::Messages::Message.new(response_metadata: { next_cursor: 'next' }))
|
42
42
|
)
|
43
43
|
expect(client).to(
|
44
|
-
receive(:users_list).with(limit: 100, cursor: 'next').ordered.and_raise(error)
|
44
|
+
receive(:users_list).with({ limit: 100, cursor: 'next' }).ordered.and_raise(error)
|
45
45
|
)
|
46
46
|
expect(cursor).to receive(:sleep).once.ordered.with(9)
|
47
47
|
expect(client).to(
|
48
48
|
receive(:users_list)
|
49
|
-
.with(limit: 100, cursor: 'next')
|
49
|
+
.with({ limit: 100, cursor: 'next' })
|
50
50
|
.ordered
|
51
51
|
.and_return(Slack::Messages::Message.new)
|
52
52
|
)
|
@@ -60,11 +60,11 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
|
|
60
60
|
it 'raises the error after hitting the max retries' do
|
61
61
|
expect(client).to(
|
62
62
|
receive(:users_list)
|
63
|
-
.with(limit: 100, cursor: nil)
|
63
|
+
.with({ limit: 100, cursor: nil })
|
64
64
|
.and_return(Slack::Messages::Message.new(response_metadata: { next_cursor: 'next' }))
|
65
65
|
)
|
66
66
|
expect(client).to(
|
67
|
-
receive(:users_list).with(limit: 100, cursor: 'next').exactly(5).times.and_raise(error)
|
67
|
+
receive(:users_list).with({ limit: 100, cursor: 'next' }).exactly(5).times.and_raise(error)
|
68
68
|
)
|
69
69
|
expect(cursor).to receive(:sleep).exactly(4).times.with(9)
|
70
70
|
expect { cursor.to_a }.to raise_error(error)
|
@@ -77,7 +77,7 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
|
|
77
77
|
let(:cursor) { described_class.new(client, 'users_list', limit: 42) }
|
78
78
|
|
79
79
|
it 'overrides default limit' do
|
80
|
-
expect(client).to receive(:users_list).with(limit: 42, cursor: nil)
|
80
|
+
expect(client).to receive(:users_list).with({ limit: 42, cursor: nil })
|
81
81
|
cursor.first
|
82
82
|
end
|
83
83
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'spec_helper'
|
3
|
+
require 'faraday/typhoeus'
|
3
4
|
|
4
5
|
RSpec.describe Slack::Web::Client do
|
5
6
|
before do
|
@@ -275,13 +276,28 @@ RSpec.describe Slack::Web::Client do
|
|
275
276
|
end
|
276
277
|
|
277
278
|
context 'parsing error' do
|
278
|
-
|
279
|
+
context 'when the response is not JSON' do
|
280
|
+
before do
|
281
|
+
stub_slack_request.to_return(body: '<html></html>', headers: { 'Content-Type' => 'text/html' })
|
282
|
+
end
|
279
283
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
284
|
+
it 'raises ParsingError' do
|
285
|
+
expect { request }.to raise_error(Slack::Web::Api::Errors::ParsingError).with_message('parsing_error')
|
286
|
+
expect(exception.response.body).to eq('<html></html>')
|
287
|
+
expect(exception.cause).to be_a(Faraday::ParsingError)
|
288
|
+
expect(exception.cause.cause).to be_a(JSON::ParserError)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
context 'when the response is malformed JSON' do
|
293
|
+
before { stub_slack_request.to_return(body: '{') }
|
294
|
+
|
295
|
+
it 'raises ParsingError' do
|
296
|
+
expect { request }.to raise_error(Slack::Web::Api::Errors::ParsingError).with_message('parsing_error')
|
297
|
+
expect(exception.response.body).to eq('{')
|
298
|
+
expect(exception.cause).to be_a(Faraday::ParsingError)
|
299
|
+
expect(exception.cause.cause).to be_a(JSON::ParserError)
|
300
|
+
end
|
285
301
|
end
|
286
302
|
end
|
287
303
|
|
@@ -318,7 +334,9 @@ RSpec.describe Slack::Web::Client do
|
|
318
334
|
end
|
319
335
|
|
320
336
|
context 'with a HTML response' do
|
321
|
-
before
|
337
|
+
before do
|
338
|
+
stub_slack_request.to_return(status: 500, body: '<html></html>', headers: { 'Content-Type' => 'text/html' })
|
339
|
+
end
|
322
340
|
|
323
341
|
it 'raises UnavailableError' do
|
324
342
|
expect { request }.to raise_error(Slack::Web::Api::Errors::UnavailableError).with_message('unavailable_error')
|
@@ -11,7 +11,7 @@ RSpec.shared_context 'connected client' do |opts|
|
|
11
11
|
config.store_class = (opts || {})[:store_class] || Slack::RealTime::Stores::Store
|
12
12
|
end
|
13
13
|
allow(Slack::RealTime::Socket).to(
|
14
|
-
receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
|
14
|
+
receive(:new).with(url, { ping: 30, logger: Slack::Logger.default }).and_return(socket)
|
15
15
|
)
|
16
16
|
allow(socket).to receive(:start_sync)
|
17
17
|
allow(socket).to receive(:connect!)
|