slack-ruby-client 1.0.0 → 2.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/FUNDING.yml +1 -0
- data/.github/workflows/integration_test.yml +45 -0
- data/.github/workflows/lint.yml +14 -0
- data/.github/workflows/pr_lint.yml +21 -0
- data/.github/workflows/test.yml +37 -0
- data/.gitignore +4 -3
- data/.rubocop.yml +6 -1
- data/.rubocop_todo.yml +88 -34
- data/.ruby-version +1 -0
- data/CHANGELOG.md +36 -0
- data/CONTRIBUTING.md +6 -5
- data/Gemfile +13 -1
- data/Gemfile.danger +6 -0
- data/README.md +78 -76
- data/RELEASING.md +2 -2
- data/SECURITY.md +9 -0
- data/UPGRADING.md +28 -0
- data/bin/commands/admin_analytics.rb +16 -10
- data/bin/commands/admin_apps.rb +48 -42
- data/bin/commands/admin_apps_approved.rb +17 -11
- data/bin/commands/admin_apps_requests.rb +28 -11
- data/bin/commands/admin_apps_restricted.rb +17 -11
- data/bin/commands/admin_audit_anomaly_allow.rb +29 -0
- data/bin/commands/admin_auth_policy.rb +37 -31
- data/bin/commands/admin_barriers.rb +44 -38
- data/bin/commands/admin_conversations.rb +221 -163
- data/bin/commands/admin_conversations_ekm.rb +17 -11
- data/bin/commands/admin_conversations_restrictAccess.rb +35 -29
- data/bin/commands/admin_emoji.rb +50 -44
- data/bin/commands/admin_inviteRequests.rb +34 -28
- data/bin/commands/admin_inviteRequests_approved.rb +16 -10
- data/bin/commands/admin_inviteRequests_denied.rb +16 -10
- data/bin/commands/admin_roles.rb +46 -0
- data/bin/commands/admin_teams.rb +26 -20
- data/bin/commands/admin_teams_admins.rb +16 -10
- data/bin/commands/admin_teams_owners.rb +16 -10
- data/bin/commands/admin_teams_settings.rb +59 -53
- data/bin/commands/admin_usergroups.rb +45 -39
- data/bin/commands/admin_users.rb +91 -85
- data/bin/commands/admin_users_session.rb +72 -66
- data/bin/commands/admin_users_unsupportedVersions.rb +21 -0
- data/bin/commands/api.rb +14 -8
- data/bin/commands/apps.rb +15 -9
- data/bin/commands/apps_connections.rb +13 -7
- data/bin/commands/apps_event_authorizations.rb +16 -10
- data/bin/commands/apps_manifest.rb +48 -41
- data/bin/commands/auth.rb +21 -15
- data/bin/commands/auth_teams.rb +16 -10
- data/bin/commands/bookmarks.rb +59 -0
- data/bin/commands/bots.rb +15 -9
- data/bin/commands/calls.rb +49 -43
- data/bin/commands/calls_participants.rb +24 -18
- data/bin/commands/chat.rb +150 -141
- data/bin/commands/chat_scheduledMessages.rb +19 -13
- data/bin/commands/conversations.rb +233 -225
- data/bin/commands/dialog.rb +15 -9
- data/bin/commands/dnd.rb +46 -40
- data/bin/commands/emoji.rb +14 -7
- data/bin/commands/files.rb +112 -83
- data/bin/commands/files_comments.rb +15 -9
- data/bin/commands/files_remote.rb +73 -67
- data/bin/commands/functions_workflows_steps.rb +22 -0
- data/bin/commands/functions_workflows_steps_responses.rb +22 -0
- data/bin/commands/migration.rb +16 -10
- data/bin/commands/oauth.rb +18 -12
- data/bin/commands/oauth_v2.rb +28 -22
- data/bin/commands/openid_connect.rb +26 -20
- data/bin/commands/pins.rb +33 -26
- data/bin/commands/reactions.rb +52 -46
- data/bin/commands/reminders.rb +53 -47
- data/bin/commands/rtm.rb +15 -24
- data/bin/commands/search.rb +43 -37
- data/bin/commands/stars.rb +38 -32
- data/bin/commands/team.rb +47 -38
- data/bin/commands/team_billing.rb +13 -7
- data/bin/commands/team_preferences.rb +13 -7
- data/bin/commands/team_profile.rb +14 -8
- data/bin/commands/tooling_tokens.rb +14 -8
- data/bin/commands/usergroups.rb +64 -58
- data/bin/commands/usergroups_users.rb +27 -21
- data/bin/commands/users.rb +111 -105
- data/bin/commands/users_admin.rb +28 -22
- data/bin/commands/users_prefs.rb +13 -7
- data/bin/commands/users_profile.rb +26 -20
- data/bin/commands/views.rb +47 -39
- data/bin/commands/workflows.rb +36 -30
- data/bin/slack +48 -43
- 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 +10 -28
- 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 +2 -2
- data/lib/slack/web/api/endpoints/admin_apps.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_apps_requests.rb +16 -0
- 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 +110 -28
- data/lib/slack/web/api/endpoints/admin_conversations_restrictAccess.rb +6 -6
- data/lib/slack/web/api/endpoints/admin_emoji.rb +9 -9
- data/lib/slack/web/api/endpoints/admin_inviteRequests.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_roles.rb +73 -0
- 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/admin_users_unsupportedVersions.rb +25 -0
- 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 +8 -6
- data/lib/slack/web/api/endpoints/bookmarks.rb +88 -0
- 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 +37 -31
- data/lib/slack/web/api/endpoints/conversations.rb +38 -34
- 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/emoji.rb +2 -0
- data/lib/slack/web/api/endpoints/files.rb +45 -10
- 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/functions_workflows_steps.rb +28 -0
- data/lib/slack/web/api/endpoints/functions_workflows_steps_responses.rb +28 -0
- 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 +5 -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/team.rb +13 -1
- data/lib/slack/web/api/endpoints/tooling_tokens.rb +1 -1
- data/lib/slack/web/api/endpoints/usergroups.rb +5 -5
- 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/users_profile.rb +1 -1
- 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 +12 -0
- data/lib/slack/web/api/errors.rb +146 -8
- 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/command.erb +18 -12
- data/lib/slack/web/api/templates/method.erb +1 -1
- data/lib/slack/web/config.rb +2 -2
- 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 +44 -24
- data/lib/tasks/web.rake +9 -8
- data/slack-ruby-client.gemspec +5 -14
- data/spec/fixtures/slack/web/rtm_connect.yml +85 -1
- data/spec/integration/integration_spec.rb +1 -1
- data/spec/slack/events/config_spec.rb +2 -0
- data/spec/slack/events/request_spec.rb +5 -1
- 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 +91 -127
- 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 +30 -27
- 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} +27 -23
- 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 +5 -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_audit_anomaly_allow_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_conversations_spec.rb +31 -0
- data/spec/slack/web/api/endpoints/admin_roles_spec.rb +30 -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 +45 -17
- data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +6 -2
- data/spec/slack/web/api/endpoints/custom_specs/views_spec.rb +33 -16
- data/spec/slack/web/api/endpoints/files_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/functions_workflows_steps_responses_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/functions_workflows_steps_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 +11 -7
- data/spec/slack/web/client_spec.rb +39 -11
- data/spec/slack/web/faraday/response/raise_error_spec.rb +1 -1
- data/spec/support/real_time/connected_client.rb +1 -1
- data/spec/support/real_time/loaded_client.rb +120 -0
- metadata +45 -197
- data/.travis.yml +0 -29
- 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/bin/commands.rb +0 -66
- 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/lib/slack/web/api/templates/commands.erb +0 -6
- 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
|
@@ -10,30 +10,37 @@ describe Slack::Messages::Formatting do
|
|
|
10
10
|
it 'plain text' do
|
|
11
11
|
expect(formatting.unescape('plain text')).to eq 'plain text'
|
|
12
12
|
end
|
|
13
|
+
|
|
13
14
|
it 'decodes an HTML-encoded message' do
|
|
14
15
|
expect(formatting.unescape('Hello & <world>')).to eq 'Hello & <world>'
|
|
15
16
|
end
|
|
17
|
+
|
|
16
18
|
it 'unescapes a user reference' do
|
|
17
19
|
expect(formatting.unescape('Hey <@U024BE7LH|bob>, did you see my file?')).to(
|
|
18
20
|
eq('Hey @bob, did you see my file?')
|
|
19
21
|
)
|
|
20
22
|
end
|
|
23
|
+
|
|
21
24
|
it 'unescapes a user reference without a name' do
|
|
22
25
|
expect(formatting.unescape('<@U02BEFY4U> ^^^')).to eq '@U02BEFY4U ^^^'
|
|
23
26
|
end
|
|
27
|
+
|
|
24
28
|
it 'unescapes a URL without text' do
|
|
25
29
|
expect(formatting.unescape('This message contains a URL <http://foo.com/>')).to(
|
|
26
30
|
eq('This message contains a URL http://foo.com/')
|
|
27
31
|
)
|
|
28
32
|
end
|
|
33
|
+
|
|
29
34
|
it 'unescapes a URL with text' do
|
|
30
35
|
expect(formatting.unescape('So does this one: <http://www.foo.com|www.foo.com>')).to(
|
|
31
36
|
eq('So does this one: www.foo.com')
|
|
32
37
|
)
|
|
33
38
|
end
|
|
39
|
+
|
|
34
40
|
it 'removes mailto' do
|
|
35
41
|
expect(formatting.unescape('<mailto:bob@example.com|Bob>')).to eq 'Bob'
|
|
36
42
|
end
|
|
43
|
+
|
|
37
44
|
it 'unlinkifies references' do
|
|
38
45
|
expect(
|
|
39
46
|
formatting.unescape('Hello <@U123|bob>, say hi to <!everyone> in <#C1234|general>')
|
|
@@ -41,12 +48,15 @@ describe Slack::Messages::Formatting do
|
|
|
41
48
|
eq('Hello @bob, say hi to @everyone in #general')
|
|
42
49
|
)
|
|
43
50
|
end
|
|
51
|
+
|
|
44
52
|
it 'can handle a lone >' do
|
|
45
53
|
expect(formatting.unescape('Hello <@U123|bob> > file.txt')).to eq 'Hello @bob > file.txt'
|
|
46
54
|
end
|
|
55
|
+
|
|
47
56
|
it 'unescapes a double smart quote' do
|
|
48
57
|
expect(formatting.unescape('“hello”')).to eq '"hello"'
|
|
49
58
|
end
|
|
59
|
+
|
|
50
60
|
it 'unescapes a single smart quote' do
|
|
51
61
|
expect(formatting.unescape('‘hello’')).to eq "'hello'"
|
|
52
62
|
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
|
describe '#message' do
|
|
@@ -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
|
describe '#ping' do
|
|
@@ -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
|
describe '#typing' do
|
|
@@ -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
|
|
|
@@ -73,7 +75,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
73
75
|
|
|
74
76
|
before do
|
|
75
77
|
allow(Slack::RealTime::Socket).to(
|
|
76
|
-
receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
|
|
78
|
+
receive(:new).with(url, { ping: 30, logger: Slack::Logger.default }).and_return(socket)
|
|
77
79
|
)
|
|
78
80
|
allow(socket).to receive(:connect!)
|
|
79
81
|
allow(socket).to receive(:start_sync)
|
|
@@ -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
|
-
expect(client.instance_variable_get(
|
|
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!)
|
|
@@ -138,7 +133,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
138
133
|
end
|
|
139
134
|
|
|
140
135
|
it 'cannot be invoked twice' do
|
|
141
|
-
client.instance_variable_set(
|
|
136
|
+
client.instance_variable_set(:@socket, nil) # caused by a :close callback
|
|
142
137
|
expect do
|
|
143
138
|
client.stop!
|
|
144
139
|
end.to raise_error Slack::RealTime::Client::ClientNotStartedError
|
|
@@ -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
|
|
@@ -186,7 +181,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
186
181
|
|
|
187
182
|
before do
|
|
188
183
|
allow(Slack::RealTime::Socket).to(
|
|
189
|
-
receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
|
|
184
|
+
receive(:new).with(url, { ping: 30, logger: Slack::Logger.default }).and_return(socket)
|
|
190
185
|
)
|
|
191
186
|
allow(socket).to receive(:connect!)
|
|
192
187
|
allow(socket).to receive(:start_async)
|
|
@@ -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,
|
|
@@ -255,7 +252,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
255
252
|
|
|
256
253
|
before do
|
|
257
254
|
allow(Slack::RealTime::Socket).to(
|
|
258
|
-
receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
|
|
255
|
+
receive(:new).with(url, { ping: 30, logger: Slack::Logger.default }).and_return(socket)
|
|
259
256
|
)
|
|
260
257
|
allow(socket).to receive(:connect!)
|
|
261
258
|
allow(socket).to receive(:start_sync)
|
|
@@ -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
|
-
expect(client.instance_variable_get(
|
|
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!)
|
|
@@ -315,7 +328,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
315
328
|
end
|
|
316
329
|
|
|
317
330
|
it 'cannot be invoked twice' do
|
|
318
|
-
client.instance_variable_set(
|
|
331
|
+
client.instance_variable_set(:@socket, nil) # caused by a :close callback
|
|
319
332
|
expect do
|
|
320
333
|
client.stop!
|
|
321
334
|
end.to raise_error Slack::RealTime::Client::ClientNotStartedError
|
|
@@ -336,8 +349,9 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
336
349
|
let(:url) { 'wss://mpmulti-w5tz.slack-msgs.com/websocket/uid' }
|
|
337
350
|
|
|
338
351
|
it 'sets store to nil' do
|
|
339
|
-
expect(client.store).to
|
|
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
|
-
expect(client.self).to
|
|
365
|
+
expect(client.self).to be_nil
|
|
351
366
|
end
|
|
367
|
+
|
|
352
368
|
it 'team' do
|
|
353
|
-
expect(client.team).to
|
|
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
|
-
expect(client.websocket_proxy).to
|
|
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
|
-
receive(:new).with(url, nil, ping: 15).and_return(ws)
|
|
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,14 +495,17 @@ 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,
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
503
|
+
{
|
|
504
|
+
ping: 30,
|
|
505
|
+
proxy: {
|
|
506
|
+
origin: 'http://username:password@proxy.example.com',
|
|
507
|
+
headers: { 'User-Agent' => 'ruby' }
|
|
508
|
+
}
|
|
481
509
|
}
|
|
482
510
|
).and_return(ws)
|
|
483
511
|
client.start!
|
|
@@ -488,14 +516,15 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
488
516
|
context 'start_options' do
|
|
489
517
|
before do
|
|
490
518
|
described_class.configure do |config|
|
|
491
|
-
config.start_options = {
|
|
519
|
+
config.start_options = { presence_sub: true }
|
|
492
520
|
end
|
|
493
521
|
end
|
|
494
522
|
|
|
495
523
|
describe '#initialize' do
|
|
496
524
|
it 'sets start_options' do
|
|
497
|
-
expect(client.start_options).to eq(
|
|
525
|
+
expect(client.start_options).to eq(presence_sub: true)
|
|
498
526
|
end
|
|
527
|
+
|
|
499
528
|
context 'start!' do
|
|
500
529
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
501
530
|
|
|
@@ -505,9 +534,9 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
505
534
|
allow(socket).to receive(:start_sync)
|
|
506
535
|
end
|
|
507
536
|
|
|
508
|
-
it 'calls
|
|
537
|
+
it 'calls rtm.connect with start options', vcr: { cassette_name: 'web/rtm_connect' } do
|
|
509
538
|
expect(client.web_client).to(
|
|
510
|
-
receive(:
|
|
539
|
+
receive(:rtm_connect).with({ presence_sub: true }).and_call_original
|
|
511
540
|
)
|
|
512
541
|
client.start!
|
|
513
542
|
end
|
|
@@ -516,7 +545,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
516
545
|
end
|
|
517
546
|
|
|
518
547
|
context 'store_class' do
|
|
519
|
-
context '
|
|
548
|
+
context 'when configured with Starter class' do
|
|
520
549
|
before do
|
|
521
550
|
described_class.configure do |config|
|
|
522
551
|
config.store_class = Slack::RealTime::Stores::Starter
|
|
@@ -524,13 +553,15 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
524
553
|
end
|
|
525
554
|
|
|
526
555
|
describe '#initialize' do
|
|
527
|
-
it 'can
|
|
528
|
-
client = described_class.new(store_class: Slack::RealTime::Store)
|
|
529
|
-
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
|
|
530
559
|
end
|
|
560
|
+
|
|
531
561
|
it 'sets store_class' do
|
|
532
562
|
expect(client.send(:store_class)).to eq(Slack::RealTime::Stores::Starter)
|
|
533
563
|
end
|
|
564
|
+
|
|
534
565
|
context 'start!' do
|
|
535
566
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
536
567
|
|
|
@@ -547,73 +578,6 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
547
578
|
end
|
|
548
579
|
end
|
|
549
580
|
end
|
|
550
|
-
|
|
551
|
-
context 'store' do
|
|
552
|
-
before do
|
|
553
|
-
described_class.configure do |config|
|
|
554
|
-
config.store_class = Slack::RealTime::Stores::Store
|
|
555
|
-
end
|
|
556
|
-
end
|
|
557
|
-
|
|
558
|
-
describe '#initialize' do
|
|
559
|
-
context 'start!' do
|
|
560
|
-
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
561
|
-
|
|
562
|
-
before do
|
|
563
|
-
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
|
564
|
-
allow(socket).to receive(:connect!)
|
|
565
|
-
allow(socket).to receive(:start_sync)
|
|
566
|
-
end
|
|
567
|
-
|
|
568
|
-
it 'calls rtm_start and not rtm_connect', vcr: { cassette_name: 'web/rtm_start' } do
|
|
569
|
-
expect(client.web_client).to receive(:rtm_start).and_call_original
|
|
570
|
-
client.start!
|
|
571
|
-
end
|
|
572
|
-
end
|
|
573
|
-
end
|
|
574
|
-
end
|
|
575
|
-
end
|
|
576
|
-
|
|
577
|
-
context 'start_method' do
|
|
578
|
-
describe '#initialize' do
|
|
579
|
-
it 'can be overriden explicitly' do
|
|
580
|
-
client = described_class.new(start_method: :overriden)
|
|
581
|
-
expect(client.send(:start_method)).to eq :overriden
|
|
582
|
-
end
|
|
583
|
-
context 'with start_method' do
|
|
584
|
-
before do
|
|
585
|
-
described_class.configure do |config|
|
|
586
|
-
config.start_method = :overriden
|
|
587
|
-
end
|
|
588
|
-
end
|
|
589
|
-
|
|
590
|
-
it 'sets start_method' do
|
|
591
|
-
expect(client.send(:start_method)).to eq :overriden
|
|
592
|
-
end
|
|
593
|
-
it 'calls the overriden method' do
|
|
594
|
-
expect(client.web_client).to receive(:overriden).and_raise('overriden')
|
|
595
|
-
expect do
|
|
596
|
-
client.start!
|
|
597
|
-
end.to raise_error RuntimeError, 'overriden'
|
|
598
|
-
end
|
|
599
|
-
end
|
|
600
|
-
|
|
601
|
-
context 'start!' do
|
|
602
|
-
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
603
|
-
|
|
604
|
-
before do
|
|
605
|
-
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
|
606
|
-
allow(socket).to receive(:connect!)
|
|
607
|
-
allow(socket).to receive(:start_sync)
|
|
608
|
-
end
|
|
609
|
-
|
|
610
|
-
it 'defaults to :rtm_start when using full store',
|
|
611
|
-
vcr: { cassette_name: 'web/rtm_start' } do
|
|
612
|
-
expect(client.web_client).to receive(:rtm_start).and_call_original
|
|
613
|
-
client.start!
|
|
614
|
-
end
|
|
615
|
-
end
|
|
616
|
-
end
|
|
617
581
|
end
|
|
618
582
|
end
|
|
619
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
|