slack-ruby-client 0.14.4 → 0.14.5
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/.rubocop.yml +19 -11
- data/.rubocop_todo.yml +66 -47
- data/CHANGELOG.md +8 -0
- data/Dangerfile +1 -0
- data/Gemfile +1 -0
- data/README.md +16 -9
- data/Rakefile +1 -0
- data/bin/commands.rb +6 -0
- data/bin/commands/admin_apps.rb +27 -0
- data/bin/commands/admin_apps_requests.rb +16 -0
- data/bin/commands/admin_users_session.rb +3 -2
- data/bin/commands/api.rb +3 -2
- data/bin/commands/apps.rb +3 -2
- data/bin/commands/apps_permissions.rb +5 -4
- data/bin/commands/apps_permissions_resources.rb +3 -2
- data/bin/commands/apps_permissions_scopes.rb +3 -2
- data/bin/commands/apps_permissions_users.rb +5 -4
- data/bin/commands/auth.rb +5 -4
- data/bin/commands/bots.rb +3 -2
- data/bin/commands/channels.rb +31 -30
- data/bin/commands/chat.rb +19 -18
- data/bin/commands/chat_scheduledMessages.rb +3 -2
- data/bin/commands/conversations.rb +35 -34
- data/bin/commands/dialog.rb +3 -2
- data/bin/commands/dnd.rb +9 -8
- data/bin/commands/emoji.rb +3 -2
- data/bin/commands/files.rb +13 -12
- data/bin/commands/files_comments.rb +3 -2
- data/bin/commands/files_remote.rb +78 -0
- data/bin/commands/groups.rb +33 -32
- data/bin/commands/im.rb +13 -12
- data/bin/commands/migration.rb +3 -2
- data/bin/commands/mpim.rb +11 -10
- data/bin/commands/oauth.rb +5 -4
- data/bin/commands/oauth_v2.rb +17 -0
- data/bin/commands/pins.rb +7 -8
- data/bin/commands/reactions.rb +10 -11
- data/bin/commands/reminders.rb +11 -10
- data/bin/commands/rtm.rb +5 -4
- data/bin/commands/search.rb +7 -6
- data/bin/commands/stars.rb +7 -6
- data/bin/commands/team.rb +9 -8
- data/bin/commands/team_profile.rb +3 -2
- data/bin/commands/usergroups.rb +11 -10
- data/bin/commands/usergroups_users.rb +5 -4
- data/bin/commands/users.rb +21 -20
- data/bin/commands/users_admin.rb +1 -0
- data/bin/commands/users_prefs.rb +1 -0
- data/bin/commands/users_profile.rb +5 -4
- data/bin/commands/views.rb +48 -0
- data/bin/slack +1 -2
- data/examples/hi_real_time/Gemfile +1 -0
- data/examples/hi_real_time/hi.rb +7 -3
- data/examples/hi_real_time_and_web/Gemfile +1 -0
- data/examples/hi_real_time_and_web/hi.rb +7 -3
- data/examples/hi_real_time_async_async/Gemfile +1 -0
- data/examples/hi_real_time_async_async/hi.rb +6 -2
- data/examples/hi_real_time_async_celluloid/Gemfile +1 -0
- data/examples/hi_real_time_async_celluloid/hi.rb +7 -3
- data/examples/hi_real_time_async_eventmachine/Gemfile +1 -0
- data/examples/hi_real_time_async_eventmachine/hi.rb +7 -3
- data/examples/hi_web/Gemfile +1 -0
- data/examples/hi_web/hi.rb +1 -0
- data/examples/new_ticket/Gemfile +1 -0
- data/examples/new_ticket/new_ticket.rb +1 -0
- data/lib/slack-ruby-client.rb +3 -2
- data/lib/slack.rb +1 -0
- data/lib/slack/config.rb +1 -0
- data/lib/slack/events/config.rb +1 -0
- data/lib/slack/events/request.rb +3 -1
- data/lib/slack/logger.rb +6 -5
- data/lib/slack/messages/formatting.rb +1 -0
- data/lib/slack/messages/message.rb +1 -0
- data/lib/slack/real_time/api/message.rb +3 -1
- data/lib/slack/real_time/api/message_id.rb +1 -0
- data/lib/slack/real_time/api/ping.rb +5 -2
- data/lib/slack/real_time/api/typing.rb +3 -1
- data/lib/slack/real_time/client.rb +19 -12
- data/lib/slack/real_time/concurrency.rb +1 -0
- data/lib/slack/real_time/concurrency/async.rb +15 -7
- data/lib/slack/real_time/concurrency/celluloid.rb +9 -3
- data/lib/slack/real_time/concurrency/eventmachine.rb +7 -4
- data/lib/slack/real_time/config.rb +6 -1
- data/lib/slack/real_time/models.rb +1 -0
- data/lib/slack/real_time/models/base.rb +1 -0
- data/lib/slack/real_time/models/bot.rb +1 -0
- data/lib/slack/real_time/models/channel.rb +1 -0
- data/lib/slack/real_time/models/group.rb +1 -0
- data/lib/slack/real_time/models/im.rb +1 -0
- data/lib/slack/real_time/models/team.rb +1 -0
- data/lib/slack/real_time/models/user.rb +1 -0
- data/lib/slack/real_time/socket.rb +14 -11
- data/lib/slack/real_time/stores.rb +1 -0
- data/lib/slack/real_time/stores/base.rb +1 -0
- data/lib/slack/real_time/stores/starter.rb +1 -0
- data/lib/slack/real_time/stores/store.rb +16 -25
- data/lib/slack/version.rb +2 -1
- data/lib/slack/web/api/endpoints.rb +11 -0
- data/lib/slack/web/api/endpoints/admin_apps.rb +42 -0
- data/lib/slack/web/api/endpoints/admin_apps_requests.rb +33 -0
- data/lib/slack/web/api/endpoints/admin_users_session.rb +2 -1
- data/lib/slack/web/api/endpoints/api.rb +2 -1
- data/lib/slack/web/api/endpoints/apps.rb +2 -1
- data/lib/slack/web/api/endpoints/apps_permissions.rb +3 -2
- data/lib/slack/web/api/endpoints/apps_permissions_resources.rb +2 -1
- data/lib/slack/web/api/endpoints/apps_permissions_scopes.rb +2 -1
- data/lib/slack/web/api/endpoints/apps_permissions_users.rb +3 -2
- data/lib/slack/web/api/endpoints/auth.rb +3 -2
- data/lib/slack/web/api/endpoints/bots.rb +2 -1
- data/lib/slack/web/api/endpoints/channels.rb +16 -16
- data/lib/slack/web/api/endpoints/chat.rb +10 -9
- data/lib/slack/web/api/endpoints/chat_scheduledMessages.rb +2 -1
- data/lib/slack/web/api/endpoints/conversations.rb +18 -17
- data/lib/slack/web/api/endpoints/dialog.rb +2 -1
- data/lib/slack/web/api/endpoints/dnd.rb +5 -4
- data/lib/slack/web/api/endpoints/emoji.rb +2 -1
- data/lib/slack/web/api/endpoints/files.rb +7 -6
- data/lib/slack/web/api/endpoints/files_comments.rb +2 -1
- data/lib/slack/web/api/endpoints/files_remote.rb +127 -0
- data/lib/slack/web/api/endpoints/groups.rb +17 -22
- data/lib/slack/web/api/endpoints/im.rb +7 -8
- data/lib/slack/web/api/endpoints/migration.rb +2 -1
- data/lib/slack/web/api/endpoints/mpim.rb +6 -7
- data/lib/slack/web/api/endpoints/oauth.rb +3 -2
- data/lib/slack/web/api/endpoints/oauth_v2.rb +30 -0
- data/lib/slack/web/api/endpoints/pins.rb +5 -9
- data/lib/slack/web/api/endpoints/reactions.rb +9 -12
- data/lib/slack/web/api/endpoints/reminders.rb +6 -5
- data/lib/slack/web/api/endpoints/rtm.rb +3 -2
- data/lib/slack/web/api/endpoints/search.rb +4 -3
- data/lib/slack/web/api/endpoints/stars.rb +4 -5
- data/lib/slack/web/api/endpoints/team.rb +5 -5
- data/lib/slack/web/api/endpoints/team_profile.rb +2 -1
- data/lib/slack/web/api/endpoints/usergroups.rb +6 -5
- data/lib/slack/web/api/endpoints/usergroups_users.rb +3 -2
- data/lib/slack/web/api/endpoints/users.rb +11 -16
- data/lib/slack/web/api/endpoints/users_admin.rb +1 -0
- data/lib/slack/web/api/endpoints/users_prefs.rb +1 -0
- data/lib/slack/web/api/endpoints/users_profile.rb +3 -2
- data/lib/slack/web/api/endpoints/views.rb +97 -0
- data/lib/slack/web/api/error.rb +1 -0
- data/lib/slack/web/api/errors/slack_error.rb +2 -1
- data/lib/slack/web/api/errors/too_many_requests_error.rb +1 -0
- data/lib/slack/web/api/mixins.rb +1 -0
- data/lib/slack/web/api/mixins/channels.id.rb +1 -0
- data/lib/slack/web/api/mixins/groups.id.rb +1 -0
- data/lib/slack/web/api/mixins/ids.id.rb +4 -1
- data/lib/slack/web/api/mixins/users.id.rb +1 -0
- data/lib/slack/web/api/mixins/users.search.rb +1 -0
- data/lib/slack/web/api/patches/views.1.view-json.patch +40 -0
- data/lib/slack/web/api/patches/views.1.views-published.patch +16 -0
- data/lib/slack/web/api/templates/command.erb +1 -0
- data/lib/slack/web/api/templates/commands.erb +1 -0
- data/lib/slack/web/api/templates/endpoints.erb +1 -0
- data/lib/slack/web/api/templates/method.erb +1 -0
- data/lib/slack/web/api/templates/method_spec.erb +1 -0
- data/lib/slack/web/client.rb +1 -0
- data/lib/slack/web/config.rb +1 -0
- data/lib/slack/web/faraday/connection.rb +1 -0
- data/lib/slack/web/faraday/request.rb +1 -0
- data/lib/slack/web/faraday/response/raise_error.rb +7 -6
- data/lib/slack/web/pagination/cursor.rb +1 -0
- data/lib/slack_ruby_client.rb +1 -0
- data/lib/tasks/git.rake +1 -0
- data/lib/tasks/real_time.rake +12 -4
- data/lib/tasks/update.rake +1 -0
- data/lib/tasks/web.rake +17 -6
- data/screenshots/create-app.png +0 -0
- data/slack-ruby-client.gemspec +4 -1
- data/spec/integration/integration_spec.rb +16 -17
- data/spec/slack/config_spec.rb +2 -0
- data/spec/slack/events/config_spec.rb +8 -4
- data/spec/slack/events/request_spec.rb +67 -37
- data/spec/slack/messages/formatting_spec.rb +25 -13
- data/spec/slack/real_time/api/message_spec.rb +6 -1
- data/spec/slack/real_time/api/ping_spec.rb +2 -0
- data/spec/slack/real_time/api/typing_spec.rb +5 -1
- data/spec/slack/real_time/client_spec.rb +137 -39
- data/spec/slack/real_time/concurrency/celluloid_spec.rb +11 -6
- data/spec/slack/real_time/concurrency/eventmachine_spec.rb +9 -1
- data/spec/slack/real_time/concurrency/it_behaves_like_a_realtime_socket.rb +2 -0
- data/spec/slack/real_time/event_handlers/bot_spec.rb +2 -1
- data/spec/slack/real_time/event_handlers/channel_spec.rb +9 -6
- data/spec/slack/real_time/event_handlers/event_handlers_spec.rb +2 -1
- data/spec/slack/real_time/event_handlers/group_spec.rb +5 -4
- data/spec/slack/real_time/event_handlers/im_spec.rb +4 -3
- data/spec/slack/real_time/event_handlers/team_spec.rb +3 -1
- data/spec/slack/real_time/event_handlers/user_spec.rb +1 -0
- data/spec/slack/real_time/rtm_connect_spec.rb +1 -0
- data/spec/slack/real_time/rtm_start_spec.rb +1 -0
- data/spec/slack/real_time/store_spec.rb +2 -1
- data/spec/slack/slack_spec.rb +37 -5
- data/spec/slack/version_spec.rb +2 -1
- data/spec/slack/web/api/endpoints/admin_apps_requests_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_apps_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_users_session_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/api_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/apps_permissions_resources_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/apps_permissions_scopes_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/apps_permissions_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/apps_permissions_users_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/apps_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/bots_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/chat_scheduledMessages_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/conversations_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/custom_specs/auth_spec.rb +5 -1
- data/spec/slack/web/api/endpoints/custom_specs/channels_spec.rb +2 -0
- data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +80 -25
- data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +12 -4
- data/spec/slack/web/api/endpoints/custom_specs/groups_spec.rb +2 -0
- data/spec/slack/web/api/endpoints/custom_specs/users_spec.rb +6 -1
- data/spec/slack/web/api/endpoints/custom_specs/views_spec.rb +95 -0
- data/spec/slack/web/api/endpoints/dnd_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/emoji_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/files_comments_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/files_remote_spec.rb +24 -0
- data/spec/slack/web/api/endpoints/files_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/im_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/migration_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/mpim_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/oauth_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/oauth_v2_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/pins_spec.rb +5 -1
- data/spec/slack/web/api/endpoints/reactions_spec.rb +8 -1
- data/spec/slack/web/api/endpoints/reminders_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/rtm_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/search_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/stars_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/team_profile_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/team_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/usergroups_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/usergroups_users_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/users_admin_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/users_prefs_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/users_profile_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/views_spec.rb +29 -0
- data/spec/slack/web/api/error_spec.rb +4 -2
- data/spec/slack/web/api/errors/service_unavailable_spec.rb +6 -3
- data/spec/slack/web/api/errors/slack_error_spec.rb +4 -2
- data/spec/slack/web/api/mixins/channels_spec.rb +17 -7
- data/spec/slack/web/api/mixins/groups_spec.rb +17 -7
- data/spec/slack/web/api/mixins/users_spec.rb +17 -8
- data/spec/slack/web/api/pagination/cursor_spec.rb +40 -10
- data/spec/slack/web/client_spec.rb +45 -18
- data/spec/slack/web/faraday/response/raise_error_spec.rb +16 -5
- data/spec/spec_helper.rb +2 -1
- data/spec/support/queue_with_timeout.rb +1 -0
- data/spec/support/real_time/concurrency/mock.rb +1 -0
- data/spec/support/real_time/connected_client.rb +9 -3
- data/spec/support/real_time/event.rb +1 -0
- data/spec/support/token.rb +1 -0
- data/spec/support/vcr.rb +1 -0
- metadata +59 -7
- data/screenshots/register-bot.png +0 -0
|
@@ -1,16 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'spec_helper'
|
|
2
3
|
|
|
3
4
|
RSpec.describe Slack::Events::Request do
|
|
5
|
+
subject(:request) do
|
|
6
|
+
described_class.new(http_request)
|
|
7
|
+
end
|
|
8
|
+
|
|
4
9
|
before do
|
|
5
10
|
Slack::Events.configure do |config|
|
|
6
11
|
config.signing_secret = signing_secret
|
|
7
12
|
config.signature_expires_in = 30
|
|
8
13
|
end
|
|
9
14
|
end
|
|
15
|
+
|
|
10
16
|
let(:signing_secret) { 'ade6ca762ade4db0e7d31484cd616b9c' }
|
|
11
17
|
let(:signature) { 'v0=91177eea054d65de0fc0f9b4ec57714307bc0ce2c5f3bf0d28b1b720c8f92ba2' }
|
|
12
18
|
let(:timestamp) { '1547933148' }
|
|
13
|
-
let(:body)
|
|
19
|
+
let(:body) do
|
|
20
|
+
'{"token":"X34FAqCu8tmGEkEEpoDncnja","challenge":' \
|
|
21
|
+
'"P7sFXA4o3HV2hTx4zb4zcQ9yrvuQs8pDh6EacOxmMRj0tJaXfQFF","type":"url_verification"}'
|
|
22
|
+
end
|
|
14
23
|
let(:http_request) do
|
|
15
24
|
double(
|
|
16
25
|
headers: {
|
|
@@ -22,39 +31,48 @@ RSpec.describe Slack::Events::Request do
|
|
|
22
31
|
)
|
|
23
32
|
)
|
|
24
33
|
end
|
|
25
|
-
|
|
26
|
-
|
|
34
|
+
|
|
35
|
+
after do
|
|
36
|
+
Slack::Events.config.reset
|
|
27
37
|
end
|
|
38
|
+
|
|
28
39
|
it 'reads http request' do
|
|
29
|
-
expect(
|
|
30
|
-
expect(
|
|
31
|
-
expect(
|
|
32
|
-
expect(
|
|
40
|
+
expect(request.signature).to eq signature
|
|
41
|
+
expect(request.body).to eq body
|
|
42
|
+
expect(request.timestamp).to eq timestamp
|
|
43
|
+
expect(request.version).to eq 'v0'
|
|
33
44
|
end
|
|
34
45
|
context 'time' do
|
|
35
46
|
after do
|
|
36
47
|
Timecop.return
|
|
37
48
|
end
|
|
49
|
+
|
|
38
50
|
context 'with an invalid signature' do
|
|
39
51
|
let(:signature) { 'v0=invalid' }
|
|
52
|
+
|
|
40
53
|
before do
|
|
41
54
|
Timecop.freeze(Time.at(timestamp.to_i))
|
|
42
55
|
end
|
|
56
|
+
|
|
43
57
|
it 'is invalid but not expired' do
|
|
44
|
-
expect(
|
|
45
|
-
expect(
|
|
58
|
+
expect(request).not_to be_valid
|
|
59
|
+
expect(request).not_to be_expired
|
|
46
60
|
end
|
|
47
61
|
end
|
|
62
|
+
|
|
48
63
|
context 'with an invalid body' do
|
|
49
64
|
let(:body) { 'invalid' }
|
|
65
|
+
|
|
50
66
|
before do
|
|
51
67
|
Timecop.freeze(Time.at(timestamp.to_i))
|
|
52
68
|
end
|
|
69
|
+
|
|
53
70
|
it 'is invalid but not expired' do
|
|
54
|
-
expect(
|
|
55
|
-
expect(
|
|
71
|
+
expect(request).not_to be_valid
|
|
72
|
+
expect(request).not_to be_expired
|
|
56
73
|
end
|
|
57
74
|
end
|
|
75
|
+
|
|
58
76
|
context 'with an invalid signing secret' do
|
|
59
77
|
before do
|
|
60
78
|
Slack::Events.configure do |config|
|
|
@@ -62,88 +80,100 @@ RSpec.describe Slack::Events::Request do
|
|
|
62
80
|
end
|
|
63
81
|
Timecop.freeze(Time.at(timestamp.to_i))
|
|
64
82
|
end
|
|
83
|
+
|
|
65
84
|
it 'is invalid but not expired' do
|
|
66
|
-
expect(
|
|
67
|
-
expect(
|
|
85
|
+
expect(request).not_to be_valid
|
|
86
|
+
expect(request).not_to be_expired
|
|
68
87
|
end
|
|
69
88
|
end
|
|
89
|
+
|
|
70
90
|
context 'within time window' do
|
|
71
91
|
before do
|
|
72
92
|
Timecop.freeze(Time.at(timestamp.to_i) + Slack::Events.config.signature_expires_in - 1)
|
|
73
93
|
end
|
|
94
|
+
|
|
74
95
|
it 'is valid' do
|
|
75
|
-
expect(
|
|
76
|
-
expect(
|
|
96
|
+
expect(request).to be_valid
|
|
97
|
+
expect(request).not_to be_expired
|
|
77
98
|
end
|
|
78
99
|
it 'does not raise an error and returns true' do
|
|
79
|
-
expect(
|
|
100
|
+
expect(request.verify!).to be true
|
|
80
101
|
end
|
|
81
102
|
end
|
|
103
|
+
|
|
82
104
|
context 'after time window' do
|
|
83
105
|
before do
|
|
84
106
|
Timecop.freeze(Time.at(timestamp.to_i) + Slack::Events.config.signature_expires_in + 1)
|
|
85
107
|
end
|
|
108
|
+
|
|
86
109
|
it 'is valid but expired' do
|
|
87
|
-
expect(
|
|
88
|
-
expect(
|
|
110
|
+
expect(request).to be_valid
|
|
111
|
+
expect(request).to be_expired
|
|
89
112
|
end
|
|
90
113
|
it 'raises an error on verify!' do
|
|
91
|
-
expect {
|
|
114
|
+
expect { request.verify! }.to raise_error Slack::Events::Request::TimestampExpired
|
|
92
115
|
end
|
|
93
116
|
end
|
|
117
|
+
|
|
94
118
|
context 'before time but within window' do
|
|
95
119
|
before do
|
|
96
120
|
Timecop.freeze(Time.at(timestamp.to_i) - Slack::Events.config.signature_expires_in + 1)
|
|
97
121
|
end
|
|
122
|
+
|
|
98
123
|
it 'is valid and not expired' do
|
|
99
|
-
expect(
|
|
100
|
-
expect(
|
|
124
|
+
expect(request).to be_valid
|
|
125
|
+
expect(request).not_to be_expired
|
|
101
126
|
end
|
|
102
127
|
it 'does not raise an error on verify!' do
|
|
103
|
-
expect(
|
|
128
|
+
expect(request.verify!).to be true
|
|
104
129
|
end
|
|
105
130
|
end
|
|
131
|
+
|
|
106
132
|
context 'before time window' do
|
|
107
133
|
before do
|
|
108
134
|
Timecop.freeze(Time.at(timestamp.to_i) - Slack::Events.config.signature_expires_in - 1)
|
|
109
135
|
end
|
|
136
|
+
|
|
110
137
|
it 'is valid but expired' do
|
|
111
|
-
expect(
|
|
112
|
-
expect(
|
|
138
|
+
expect(request).to be_valid
|
|
139
|
+
expect(request).to be_expired
|
|
113
140
|
end
|
|
114
141
|
it 'raises an error on verify!' do
|
|
115
|
-
expect {
|
|
142
|
+
expect { request.verify! }.to raise_error Slack::Events::Request::TimestampExpired
|
|
116
143
|
end
|
|
117
144
|
end
|
|
118
145
|
end
|
|
146
|
+
|
|
119
147
|
context 'without global config' do
|
|
120
148
|
before do
|
|
121
149
|
Slack::Events.config.reset
|
|
122
150
|
end
|
|
151
|
+
|
|
123
152
|
context 'without a signing secret parameter' do
|
|
124
|
-
subject do
|
|
125
|
-
|
|
153
|
+
subject(:request) do
|
|
154
|
+
described_class.new(http_request)
|
|
126
155
|
end
|
|
156
|
+
|
|
127
157
|
it 'raises MissingSigningSecret' do
|
|
128
|
-
expect {
|
|
158
|
+
expect { request.valid? }.to raise_error Slack::Events::Request::MissingSigningSecret
|
|
129
159
|
end
|
|
130
160
|
end
|
|
161
|
+
|
|
131
162
|
context 'with a signing secret parameter' do
|
|
132
|
-
subject do
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
163
|
+
subject(:request) do
|
|
164
|
+
described_class.new(http_request,
|
|
165
|
+
signing_secret: signing_secret,
|
|
166
|
+
signature_expires_in: 30)
|
|
136
167
|
end
|
|
168
|
+
|
|
137
169
|
before do
|
|
138
170
|
Timecop.freeze(Time.at(timestamp.to_i))
|
|
139
171
|
end
|
|
172
|
+
|
|
140
173
|
it 'is valid and not expired' do
|
|
141
|
-
expect(
|
|
142
|
-
expect(
|
|
174
|
+
expect(request).to be_valid
|
|
175
|
+
expect(request).not_to be_expired
|
|
143
176
|
end
|
|
144
177
|
end
|
|
145
178
|
end
|
|
146
|
-
after do
|
|
147
|
-
Slack::Events.config.reset
|
|
148
|
-
end
|
|
149
179
|
end
|
|
@@ -1,42 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'spec_helper'
|
|
2
3
|
|
|
3
4
|
describe Slack::Messages::Formatting do
|
|
4
|
-
subject do
|
|
5
|
-
|
|
5
|
+
subject(:formatting) do
|
|
6
|
+
described_class
|
|
6
7
|
end
|
|
8
|
+
|
|
7
9
|
context '#unescape' do
|
|
8
10
|
it 'plain text' do
|
|
9
|
-
expect(
|
|
11
|
+
expect(formatting.unescape('plain text')).to eq 'plain text'
|
|
10
12
|
end
|
|
11
13
|
it 'decodes an HTML-encoded message' do
|
|
12
|
-
expect(
|
|
14
|
+
expect(formatting.unescape('Hello & <world>')).to eq 'Hello & <world>'
|
|
13
15
|
end
|
|
14
16
|
it 'unescapes a user reference' do
|
|
15
|
-
expect(
|
|
17
|
+
expect(formatting.unescape('Hey <@U024BE7LH|bob>, did you see my file?')).to(
|
|
18
|
+
eq('Hey @bob, did you see my file?')
|
|
19
|
+
)
|
|
16
20
|
end
|
|
17
21
|
it 'unescapes a user reference without a name' do
|
|
18
|
-
expect(
|
|
22
|
+
expect(formatting.unescape('<@U02BEFY4U> ^^^')).to eq '@U02BEFY4U ^^^'
|
|
19
23
|
end
|
|
20
24
|
it 'unescapes a URL without text' do
|
|
21
|
-
expect(
|
|
25
|
+
expect(formatting.unescape('This message contains a URL <http://foo.com/>')).to(
|
|
26
|
+
eq('This message contains a URL http://foo.com/')
|
|
27
|
+
)
|
|
22
28
|
end
|
|
23
29
|
it 'unescapes a URL with text' do
|
|
24
|
-
expect(
|
|
30
|
+
expect(formatting.unescape('So does this one: <http://www.foo.com|www.foo.com>')).to(
|
|
31
|
+
eq('So does this one: www.foo.com')
|
|
32
|
+
)
|
|
25
33
|
end
|
|
26
34
|
it 'removes mailto' do
|
|
27
|
-
expect(
|
|
35
|
+
expect(formatting.unescape('<mailto:bob@example.com|Bob>')).to eq 'Bob'
|
|
28
36
|
end
|
|
29
37
|
it 'unlinkifies references' do
|
|
30
|
-
expect(
|
|
38
|
+
expect(
|
|
39
|
+
formatting.unescape('Hello <@U123|bob>, say hi to <!everyone> in <#C1234|general>')
|
|
40
|
+
).to(
|
|
41
|
+
eq('Hello @bob, say hi to @everyone in #general')
|
|
42
|
+
)
|
|
31
43
|
end
|
|
32
44
|
it 'can handle a lone >' do
|
|
33
|
-
expect(
|
|
45
|
+
expect(formatting.unescape('Hello <@U123|bob> > file.txt')).to eq 'Hello @bob > file.txt'
|
|
34
46
|
end
|
|
35
47
|
it 'unescapes a double smart quote' do
|
|
36
|
-
expect(
|
|
48
|
+
expect(formatting.unescape('“hello”')).to eq '"hello"'
|
|
37
49
|
end
|
|
38
50
|
it 'unescapes a single smart quote' do
|
|
39
|
-
expect(
|
|
51
|
+
expect(formatting.unescape('‘hello’')).to eq "'hello'"
|
|
40
52
|
end
|
|
41
53
|
end
|
|
42
54
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'spec_helper'
|
|
2
3
|
|
|
3
4
|
RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' } do
|
|
@@ -7,8 +8,12 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
|
7
8
|
before do
|
|
8
9
|
allow(client).to receive(:next_id).and_return(42)
|
|
9
10
|
end
|
|
11
|
+
|
|
10
12
|
it 'sends message' do
|
|
11
|
-
expect(socket).to
|
|
13
|
+
expect(socket).to(
|
|
14
|
+
receive(:send_data)
|
|
15
|
+
.with({ type: 'message', id: 42, text: 'hello world', channel: 'channel' }.to_json)
|
|
16
|
+
)
|
|
12
17
|
client.message(text: 'hello world', channel: 'channel')
|
|
13
18
|
end
|
|
14
19
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'spec_helper'
|
|
2
3
|
|
|
3
4
|
RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' } do
|
|
@@ -7,6 +8,7 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
|
7
8
|
before do
|
|
8
9
|
allow(client).to receive(:next_id).and_return(42)
|
|
9
10
|
end
|
|
11
|
+
|
|
10
12
|
it 'sends message' do
|
|
11
13
|
expect(socket).to receive(:send_data).with({ type: 'ping', id: 42 }.to_json)
|
|
12
14
|
client.ping
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'spec_helper'
|
|
2
3
|
|
|
3
4
|
RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' } do
|
|
@@ -7,8 +8,11 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
|
7
8
|
before do
|
|
8
9
|
allow(client).to receive(:next_id).and_return(42)
|
|
9
10
|
end
|
|
11
|
+
|
|
10
12
|
it 'sends a typing indicator' do
|
|
11
|
-
expect(socket).to
|
|
13
|
+
expect(socket).to(
|
|
14
|
+
receive(:send_data).with({ type: 'typing', id: 42, channel: 'channel' }.to_json)
|
|
15
|
+
)
|
|
12
16
|
client.typing(channel: 'channel')
|
|
13
17
|
end
|
|
14
18
|
end
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'spec_helper'
|
|
2
3
|
|
|
3
|
-
RSpec.describe Slack::RealTime::Client do
|
|
4
|
+
RSpec.describe Slack::RealTime::Client do # rubocop:disable Metrics/BlockLength
|
|
4
5
|
let(:ws) { double(Slack::RealTime::Concurrency::Mock::WebSocket, on: true) }
|
|
6
|
+
|
|
5
7
|
before do
|
|
6
8
|
@token = ENV.delete('SLACK_API_TOKEN')
|
|
7
9
|
Slack::Config.reset
|
|
@@ -10,63 +12,78 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
10
12
|
config.concurrency = Slack::RealTime::Concurrency::Mock
|
|
11
13
|
end
|
|
12
14
|
end
|
|
15
|
+
|
|
13
16
|
after do
|
|
14
17
|
ENV['SLACK_API_TOKEN'] = @token if @token
|
|
15
18
|
end
|
|
19
|
+
|
|
16
20
|
context 'token' do
|
|
17
21
|
before do
|
|
18
22
|
Slack.configure do |config|
|
|
19
23
|
config.token = 'global default'
|
|
20
24
|
end
|
|
21
25
|
end
|
|
26
|
+
|
|
22
27
|
it 'defaults token to global default' do
|
|
23
|
-
client =
|
|
28
|
+
client = described_class.new
|
|
24
29
|
expect(client.token).to eq 'global default'
|
|
25
30
|
expect(client.web_client.token).to eq 'global default'
|
|
26
31
|
end
|
|
27
32
|
context 'with real time config' do
|
|
28
33
|
before do
|
|
29
|
-
|
|
34
|
+
described_class.configure do |config|
|
|
30
35
|
config.token = 'custom real time token'
|
|
31
36
|
end
|
|
32
37
|
end
|
|
38
|
+
|
|
33
39
|
it 'overrides token to real time config' do
|
|
34
|
-
client =
|
|
40
|
+
client = described_class.new
|
|
35
41
|
expect(client.token).to eq 'custom real time token'
|
|
36
42
|
expect(client.web_client.token).to eq 'custom real time token'
|
|
37
43
|
end
|
|
38
44
|
it 'overrides token to specific token' do
|
|
39
|
-
client =
|
|
45
|
+
client = described_class.new(token: 'local token')
|
|
40
46
|
expect(client.token).to eq 'local token'
|
|
41
47
|
expect(client.web_client.token).to eq 'local token'
|
|
42
48
|
end
|
|
43
49
|
end
|
|
44
50
|
end
|
|
51
|
+
|
|
45
52
|
context 'websocket_ping_timer' do
|
|
46
53
|
context 'with defaults' do
|
|
47
|
-
let(:client) {
|
|
54
|
+
let(:client) { described_class.new }
|
|
55
|
+
|
|
48
56
|
it 'defaults to websocket_ping / 2' do
|
|
49
57
|
expect(client.websocket_ping_timer).to eq 15
|
|
50
58
|
end
|
|
51
59
|
end
|
|
60
|
+
|
|
52
61
|
context 'with websocket_ping value changed' do
|
|
53
|
-
let(:client) {
|
|
62
|
+
let(:client) { described_class.new(websocket_ping: 22) }
|
|
63
|
+
|
|
54
64
|
it 'defaults to websocket_ping / 2' do
|
|
55
65
|
expect(client.websocket_ping_timer).to eq 11
|
|
56
66
|
end
|
|
57
67
|
end
|
|
58
68
|
end
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
|
|
70
|
+
context 'client with a full store',
|
|
71
|
+
vcr: { cassette_name: 'web/rtm_start', allow_playback_repeats: true } do
|
|
72
|
+
let(:client) { described_class.new(store_class: Slack::RealTime::Stores::Store) }
|
|
61
73
|
let(:url) { 'wss://ms173.slack-msgs.com/websocket/lqcUiAvrKTP-uuid=' }
|
|
74
|
+
|
|
62
75
|
describe '#start!' do
|
|
63
76
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
77
|
+
|
|
64
78
|
before do
|
|
65
|
-
allow(Slack::RealTime::Socket).to
|
|
79
|
+
allow(Slack::RealTime::Socket).to(
|
|
80
|
+
receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
|
|
81
|
+
)
|
|
66
82
|
allow(socket).to receive(:connect!)
|
|
67
83
|
allow(socket).to receive(:start_sync)
|
|
68
84
|
client.start!
|
|
69
85
|
end
|
|
86
|
+
|
|
70
87
|
describe 'properties provided upon connection' do
|
|
71
88
|
it 'sets url' do
|
|
72
89
|
expect(client.url).to eq url
|
|
@@ -101,9 +118,12 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
101
118
|
expect(client.groups.count).to eq 1
|
|
102
119
|
end
|
|
103
120
|
it 'includes team name in to_s' do
|
|
104
|
-
expect(client.to_s).to eq
|
|
121
|
+
expect(client.to_s).to eq(
|
|
122
|
+
"id=#{client.team.id}, name=#{client.team.name}, domain=#{client.team.domain}"
|
|
123
|
+
)
|
|
105
124
|
end
|
|
106
125
|
end
|
|
126
|
+
|
|
107
127
|
it 'uses web client to fetch url' do
|
|
108
128
|
expect(client.web_client).to be_a Slack::Web::Client
|
|
109
129
|
end
|
|
@@ -117,9 +137,10 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
117
137
|
end
|
|
118
138
|
describe '#stop!' do
|
|
119
139
|
before do
|
|
120
|
-
|
|
140
|
+
allow(socket).to receive(:disconnect!)
|
|
121
141
|
client.stop!
|
|
122
142
|
end
|
|
143
|
+
|
|
123
144
|
it 'cannot be invoked twice' do
|
|
124
145
|
client.instance_variable_set('@socket', nil) # caused by a :close callback
|
|
125
146
|
expect do
|
|
@@ -127,12 +148,14 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
127
148
|
end.to raise_error Slack::RealTime::Client::ClientNotStartedError
|
|
128
149
|
end
|
|
129
150
|
end
|
|
151
|
+
|
|
130
152
|
describe '#next_id' do
|
|
131
153
|
it 'increments' do
|
|
132
154
|
previous_id = client.send(:next_id)
|
|
133
155
|
expect(client.send(:next_id)).to eq previous_id + 1
|
|
134
156
|
end
|
|
135
157
|
end
|
|
158
|
+
|
|
136
159
|
context 'subclassed' do
|
|
137
160
|
it 'runs event handlers' do
|
|
138
161
|
event = Slack::RealTime::Event.new(
|
|
@@ -144,14 +167,19 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
144
167
|
end
|
|
145
168
|
end
|
|
146
169
|
end
|
|
170
|
+
|
|
147
171
|
describe '#start_async' do
|
|
148
172
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
173
|
+
|
|
149
174
|
before do
|
|
150
|
-
allow(Slack::RealTime::Socket).to
|
|
175
|
+
allow(Slack::RealTime::Socket).to(
|
|
176
|
+
receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
|
|
177
|
+
)
|
|
151
178
|
allow(socket).to receive(:connect!)
|
|
152
179
|
allow(socket).to receive(:start_async)
|
|
153
180
|
client.start_async
|
|
154
181
|
end
|
|
182
|
+
|
|
155
183
|
describe '#run_ping!' do
|
|
156
184
|
it 'sends ping messages when the websocket connection is idle' do
|
|
157
185
|
allow(socket).to receive(:time_since_last_message).and_return(30)
|
|
@@ -165,34 +193,62 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
165
193
|
expect(socket).to receive(:restart_async)
|
|
166
194
|
client.run_ping!
|
|
167
195
|
end
|
|
168
|
-
[
|
|
196
|
+
[
|
|
197
|
+
EOFError,
|
|
198
|
+
Errno::ECONNRESET,
|
|
199
|
+
Errno::EPIPE,
|
|
200
|
+
Faraday::ClientError,
|
|
201
|
+
Slack::Web::Api::Errors::SlackError
|
|
202
|
+
].each do |err|
|
|
169
203
|
context "raising #{err}" do
|
|
170
204
|
it 'does not terminate the ping worker' do
|
|
171
205
|
allow(socket).to receive(:time_since_last_message) { raise err }
|
|
172
|
-
expect(socket).
|
|
206
|
+
expect(socket).not_to receive(:send_data)
|
|
173
207
|
client.run_ping!
|
|
174
208
|
end
|
|
175
209
|
end
|
|
176
210
|
end
|
|
211
|
+
context 'raising Slack::Web::Api::Errors::SlackError' do
|
|
212
|
+
%w[invalid_auth account_inactive].each do |code|
|
|
213
|
+
context code do
|
|
214
|
+
it 'does not terminate the ping worker' do
|
|
215
|
+
allow(socket).to receive(:time_since_last_message) {
|
|
216
|
+
raise Slack::Web::Api::Errors::SlackError, code
|
|
217
|
+
}
|
|
218
|
+
expect(socket).not_to receive(:send_data)
|
|
219
|
+
expect do
|
|
220
|
+
client.run_ping!
|
|
221
|
+
end.to raise_error Slack::Web::Api::Errors::SlackError, code
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
end
|
|
177
226
|
end
|
|
178
227
|
end
|
|
228
|
+
|
|
179
229
|
describe 'to_s' do
|
|
180
230
|
it 'defaults to class instance' do
|
|
181
231
|
expect(client.to_s).to match(/^#<Slack::RealTime::Client:0x\h+>$/)
|
|
182
232
|
end
|
|
183
233
|
end
|
|
184
234
|
end
|
|
235
|
+
|
|
185
236
|
context 'client with starter store', vcr: { cassette_name: 'web/rtm_connect' } do
|
|
186
|
-
let(:client) {
|
|
237
|
+
let(:client) { described_class.new(store_class: Slack::RealTime::Stores::Starter) }
|
|
187
238
|
let(:url) { 'wss://mpmulti-w5tz.slack-msgs.com/websocket/uid' }
|
|
239
|
+
|
|
188
240
|
describe '#start!' do
|
|
189
241
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
242
|
+
|
|
190
243
|
before do
|
|
191
|
-
allow(Slack::RealTime::Socket).to
|
|
244
|
+
allow(Slack::RealTime::Socket).to(
|
|
245
|
+
receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
|
|
246
|
+
)
|
|
192
247
|
allow(socket).to receive(:connect!)
|
|
193
248
|
allow(socket).to receive(:start_sync)
|
|
194
249
|
client.start!
|
|
195
250
|
end
|
|
251
|
+
|
|
196
252
|
describe 'properties provided upon connection' do
|
|
197
253
|
it 'sets url' do
|
|
198
254
|
expect(client.url).to eq url
|
|
@@ -222,9 +278,12 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
222
278
|
expect(client.groups).to be_nil
|
|
223
279
|
end
|
|
224
280
|
it 'includes team name in to_s' do
|
|
225
|
-
expect(client.to_s).to eq
|
|
281
|
+
expect(client.to_s).to eq(
|
|
282
|
+
"id=#{client.team.id}, name=#{client.team.name}, domain=#{client.team.domain}"
|
|
283
|
+
)
|
|
226
284
|
end
|
|
227
285
|
end
|
|
286
|
+
|
|
228
287
|
it 'uses web client to fetch url' do
|
|
229
288
|
expect(client.web_client).to be_a Slack::Web::Client
|
|
230
289
|
end
|
|
@@ -238,9 +297,10 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
238
297
|
end
|
|
239
298
|
describe '#stop!' do
|
|
240
299
|
before do
|
|
241
|
-
|
|
300
|
+
allow(socket).to receive(:disconnect!)
|
|
242
301
|
client.stop!
|
|
243
302
|
end
|
|
303
|
+
|
|
244
304
|
it 'cannot be invoked twice' do
|
|
245
305
|
client.instance_variable_set('@socket', nil) # caused by a :close callback
|
|
246
306
|
expect do
|
|
@@ -248,6 +308,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
248
308
|
end.to raise_error Slack::RealTime::Client::ClientNotStartedError
|
|
249
309
|
end
|
|
250
310
|
end
|
|
311
|
+
|
|
251
312
|
describe '#next_id' do
|
|
252
313
|
it 'increments' do
|
|
253
314
|
previous_id = client.send(:next_id)
|
|
@@ -256,9 +317,11 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
256
317
|
end
|
|
257
318
|
end
|
|
258
319
|
end
|
|
320
|
+
|
|
259
321
|
context 'client with nil store', vcr: { cassette_name: 'web/rtm_connect' } do
|
|
260
|
-
let(:client) {
|
|
322
|
+
let(:client) { described_class.new(store_class: nil) }
|
|
261
323
|
let(:url) { 'wss://mpmulti-w5tz.slack-msgs.com/websocket/uid' }
|
|
324
|
+
|
|
262
325
|
it 'sets store to nil' do
|
|
263
326
|
expect(client.store).to be nil
|
|
264
327
|
end
|
|
@@ -267,7 +330,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
267
330
|
'type' => 'team_rename',
|
|
268
331
|
'name' => 'New Team Name Inc.'
|
|
269
332
|
)
|
|
270
|
-
expect(client).
|
|
333
|
+
expect(client).not_to receive(:run_handlers)
|
|
271
334
|
client.send(:dispatch, event)
|
|
272
335
|
end
|
|
273
336
|
it 'self' do
|
|
@@ -282,8 +345,10 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
282
345
|
end
|
|
283
346
|
end
|
|
284
347
|
end
|
|
348
|
+
|
|
285
349
|
context 'client with defaults' do
|
|
286
|
-
let(:client) {
|
|
350
|
+
let(:client) { described_class.new }
|
|
351
|
+
|
|
287
352
|
describe '#initialize' do
|
|
288
353
|
it 'sets ping' do
|
|
289
354
|
expect(client.websocket_ping).to eq 30
|
|
@@ -303,6 +368,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
303
368
|
end
|
|
304
369
|
end
|
|
305
370
|
end
|
|
371
|
+
|
|
306
372
|
describe '#run_ping?' do
|
|
307
373
|
it 'returns true when websocket_ping is greater than 0' do
|
|
308
374
|
client.websocket_ping = 30
|
|
@@ -316,20 +382,24 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
316
382
|
end
|
|
317
383
|
end
|
|
318
384
|
end
|
|
385
|
+
|
|
319
386
|
context 'with custom settings' do
|
|
320
387
|
describe '#initialize' do
|
|
321
388
|
Slack::RealTime::Config::ATTRIBUTES.each do |key|
|
|
322
|
-
context key do
|
|
323
|
-
let(:client) {
|
|
389
|
+
context key.to_s do
|
|
390
|
+
let(:client) { described_class.new(key => 'custom') }
|
|
391
|
+
|
|
324
392
|
it "sets #{key}" do
|
|
325
|
-
expect(client.send(key)).
|
|
393
|
+
expect(client.send(key)).not_to eq Slack::RealTime::Config.send(key)
|
|
326
394
|
expect(client.send(key)).to eq 'custom'
|
|
327
395
|
end
|
|
328
396
|
end
|
|
329
397
|
end
|
|
330
398
|
end
|
|
399
|
+
|
|
331
400
|
describe 'logger accessor' do
|
|
332
|
-
let(:client) {
|
|
401
|
+
let(:client) { described_class.new }
|
|
402
|
+
|
|
333
403
|
it 'exposes public logger' do
|
|
334
404
|
expect(client.logger).to be_a(::Logger)
|
|
335
405
|
end
|
|
@@ -338,24 +408,30 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
338
408
|
end
|
|
339
409
|
end
|
|
340
410
|
end
|
|
411
|
+
|
|
341
412
|
context 'global config' do
|
|
342
413
|
after do
|
|
343
|
-
|
|
414
|
+
described_class.config.reset
|
|
344
415
|
end
|
|
416
|
+
|
|
345
417
|
let(:url) { 'wss://ms173.slack-msgs.com/websocket/lqcUiAvrKTP-uuid=' }
|
|
346
|
-
let(:client) {
|
|
418
|
+
let(:client) { described_class.new }
|
|
419
|
+
|
|
347
420
|
context 'ping' do
|
|
348
421
|
before do
|
|
349
|
-
|
|
422
|
+
described_class.configure do |config|
|
|
350
423
|
config.websocket_ping = 15
|
|
351
424
|
end
|
|
352
425
|
end
|
|
426
|
+
|
|
353
427
|
describe '#initialize' do
|
|
354
428
|
it 'sets ping' do
|
|
355
429
|
expect(client.websocket_ping).to eq 15
|
|
356
430
|
end
|
|
357
431
|
it 'creates a connection with custom ping', vcr: { cassette_name: 'web/rtm_start' } do
|
|
358
|
-
expect(Slack::RealTime::Concurrency::Mock::WebSocket).to
|
|
432
|
+
expect(Slack::RealTime::Concurrency::Mock::WebSocket).to(
|
|
433
|
+
receive(:new).with(url, nil, ping: 15).and_return(ws)
|
|
434
|
+
)
|
|
359
435
|
client.start!
|
|
360
436
|
end
|
|
361
437
|
it 'sets start_options' do
|
|
@@ -363,15 +439,17 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
363
439
|
end
|
|
364
440
|
end
|
|
365
441
|
end
|
|
442
|
+
|
|
366
443
|
context 'proxy' do
|
|
367
444
|
before do
|
|
368
|
-
|
|
445
|
+
described_class.configure do |config|
|
|
369
446
|
config.websocket_proxy = {
|
|
370
447
|
origin: 'http://username:password@proxy.example.com',
|
|
371
448
|
headers: { 'User-Agent' => 'ruby' }
|
|
372
449
|
}
|
|
373
450
|
end
|
|
374
451
|
end
|
|
452
|
+
|
|
375
453
|
describe '#initialize' do
|
|
376
454
|
it 'sets proxy' do
|
|
377
455
|
expect(client.websocket_proxy).to eq(
|
|
@@ -393,40 +471,48 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
393
471
|
end
|
|
394
472
|
end
|
|
395
473
|
end
|
|
474
|
+
|
|
396
475
|
context 'start_options' do
|
|
397
476
|
before do
|
|
398
|
-
|
|
477
|
+
described_class.configure do |config|
|
|
399
478
|
config.start_options = { simple_latest: true }
|
|
400
479
|
end
|
|
401
480
|
end
|
|
481
|
+
|
|
402
482
|
describe '#initialize' do
|
|
403
483
|
it 'sets start_options' do
|
|
404
484
|
expect(client.start_options).to eq(simple_latest: true)
|
|
405
485
|
end
|
|
406
486
|
context 'start!' do
|
|
407
487
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
488
|
+
|
|
408
489
|
before do
|
|
409
490
|
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
|
410
491
|
allow(socket).to receive(:connect!)
|
|
411
492
|
allow(socket).to receive(:start_sync)
|
|
412
493
|
end
|
|
494
|
+
|
|
413
495
|
it 'calls rtm_start with start options', vcr: { cassette_name: 'web/rtm_start' } do
|
|
414
|
-
expect(client.web_client).to
|
|
496
|
+
expect(client.web_client).to(
|
|
497
|
+
receive(:rtm_start).with(simple_latest: true).and_call_original
|
|
498
|
+
)
|
|
415
499
|
client.start!
|
|
416
500
|
end
|
|
417
501
|
end
|
|
418
502
|
end
|
|
419
503
|
end
|
|
504
|
+
|
|
420
505
|
context 'store_class' do
|
|
421
506
|
context 'starter' do
|
|
422
507
|
before do
|
|
423
|
-
|
|
508
|
+
described_class.configure do |config|
|
|
424
509
|
config.store_class = Slack::RealTime::Stores::Starter
|
|
425
510
|
end
|
|
426
511
|
end
|
|
512
|
+
|
|
427
513
|
describe '#initialize' do
|
|
428
514
|
it 'can be overriden explicitly' do
|
|
429
|
-
client =
|
|
515
|
+
client = described_class.new(store_class: Slack::RealTime::Store)
|
|
430
516
|
expect(client.send(:store_class)).to eq Slack::RealTime::Store
|
|
431
517
|
end
|
|
432
518
|
it 'sets store_class' do
|
|
@@ -434,11 +520,13 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
434
520
|
end
|
|
435
521
|
context 'start!' do
|
|
436
522
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
523
|
+
|
|
437
524
|
before do
|
|
438
525
|
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
|
439
526
|
allow(socket).to receive(:connect!)
|
|
440
527
|
allow(socket).to receive(:start_sync)
|
|
441
528
|
end
|
|
529
|
+
|
|
442
530
|
it 'instantiates the correct store class', vcr: { cassette_name: 'web/rtm_connect' } do
|
|
443
531
|
client.start!
|
|
444
532
|
expect(client.store).to be_a Slack::RealTime::Stores::Starter
|
|
@@ -446,20 +534,24 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
446
534
|
end
|
|
447
535
|
end
|
|
448
536
|
end
|
|
537
|
+
|
|
449
538
|
context 'store' do
|
|
450
539
|
before do
|
|
451
|
-
|
|
540
|
+
described_class.configure do |config|
|
|
452
541
|
config.store_class = Slack::RealTime::Stores::Store
|
|
453
542
|
end
|
|
454
543
|
end
|
|
544
|
+
|
|
455
545
|
describe '#initialize' do
|
|
456
546
|
context 'start!' do
|
|
457
547
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
548
|
+
|
|
458
549
|
before do
|
|
459
550
|
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
|
460
551
|
allow(socket).to receive(:connect!)
|
|
461
552
|
allow(socket).to receive(:start_sync)
|
|
462
553
|
end
|
|
554
|
+
|
|
463
555
|
it 'calls rtm_start and not rtm_connect', vcr: { cassette_name: 'web/rtm_start' } do
|
|
464
556
|
expect(client.web_client).to receive(:rtm_start).and_call_original
|
|
465
557
|
client.start!
|
|
@@ -468,18 +560,20 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
468
560
|
end
|
|
469
561
|
end
|
|
470
562
|
end
|
|
563
|
+
|
|
471
564
|
context 'start_method' do
|
|
472
565
|
describe '#initialize' do
|
|
473
566
|
it 'can be overriden explicitly' do
|
|
474
|
-
client =
|
|
567
|
+
client = described_class.new(start_method: :overriden)
|
|
475
568
|
expect(client.send(:start_method)).to eq :overriden
|
|
476
569
|
end
|
|
477
570
|
context 'with start_method' do
|
|
478
571
|
before do
|
|
479
|
-
|
|
572
|
+
described_class.configure do |config|
|
|
480
573
|
config.start_method = :overriden
|
|
481
574
|
end
|
|
482
575
|
end
|
|
576
|
+
|
|
483
577
|
it 'sets start_method' do
|
|
484
578
|
expect(client.send(:start_method)).to eq :overriden
|
|
485
579
|
end
|
|
@@ -490,14 +584,18 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
490
584
|
end.to raise_error RuntimeError, 'overriden'
|
|
491
585
|
end
|
|
492
586
|
end
|
|
587
|
+
|
|
493
588
|
context 'start!' do
|
|
494
589
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
590
|
+
|
|
495
591
|
before do
|
|
496
592
|
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
|
497
593
|
allow(socket).to receive(:connect!)
|
|
498
594
|
allow(socket).to receive(:start_sync)
|
|
499
595
|
end
|
|
500
|
-
|
|
596
|
+
|
|
597
|
+
it 'defaults to :rtm_start when using full store',
|
|
598
|
+
vcr: { cassette_name: 'web/rtm_start' } do
|
|
501
599
|
expect(client.web_client).to receive(:rtm_start).and_call_original
|
|
502
600
|
client.start!
|
|
503
601
|
end
|