slack-ruby-client 0.14.2 → 0.15.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/.rubocop.yml +23 -7
- data/.rubocop_todo.yml +103 -43
- data/.travis.yml +0 -1
- data/CHANGELOG.md +39 -2
- data/CONTRIBUTING.md +24 -6
- data/Dangerfile +2 -1
- data/Gemfile +10 -3
- data/README.md +90 -30
- data/Rakefile +1 -0
- data/UPGRADING.md +16 -0
- data/bin/commands.rb +24 -0
- data/bin/commands/admin_apps.rb +27 -0
- data/bin/commands/admin_apps_approved.rb +17 -0
- data/bin/commands/admin_apps_requests.rb +16 -0
- data/bin/commands/admin_apps_restricted.rb +17 -0
- data/bin/commands/admin_conversations.rb +17 -0
- data/bin/commands/admin_conversations_restrictAccess.rb +37 -0
- data/bin/commands/admin_conversations_whitelist.rb +37 -0
- data/bin/commands/admin_emoji.rb +54 -0
- data/bin/commands/admin_inviteRequests.rb +36 -0
- data/bin/commands/admin_inviteRequests_approved.rb +16 -0
- data/bin/commands/admin_inviteRequests_denied.rb +16 -0
- data/bin/commands/admin_teams.rb +27 -0
- data/bin/commands/admin_teams_admins.rb +16 -0
- data/bin/commands/admin_teams_owners.rb +16 -0
- data/bin/commands/admin_teams_settings.rb +64 -0
- data/bin/commands/admin_usergroups.rb +48 -0
- data/bin/commands/admin_users.rb +97 -0
- data/bin/commands/admin_users_session.rb +16 -0
- 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/calls.rb +52 -0
- data/bin/commands/calls_participants.rb +25 -0
- data/bin/commands/channels.rb +31 -30
- data/bin/commands/chat.rb +36 -32
- data/bin/commands/chat_scheduledMessages.rb +3 -2
- data/bin/commands/conversations.rb +36 -36
- 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 +14 -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 +6 -5
- 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 +10 -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 +4 -4
- 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 -4
- 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 +46 -22
- data/lib/slack/real_time/concurrency.rb +1 -0
- data/lib/slack/real_time/concurrency/async.rb +18 -9
- data/lib/slack/real_time/concurrency/celluloid.rb +10 -4
- data/lib/slack/real_time/concurrency/eventmachine.rb +9 -6
- 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 -4
- 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 +16 -13
- data/lib/slack/real_time/stores.rb +1 -0
- data/lib/slack/real_time/stores/base.rb +4 -1
- data/lib/slack/real_time/stores/starter.rb +11 -0
- data/lib/slack/real_time/stores/store.rb +26 -25
- data/lib/slack/version.rb +2 -1
- data/lib/slack/web/api/endpoints.rb +48 -0
- data/lib/slack/web/api/endpoints/admin_apps.rb +42 -0
- data/lib/slack/web/api/endpoints/admin_apps_approved.rb +35 -0
- data/lib/slack/web/api/endpoints/admin_apps_requests.rb +33 -0
- data/lib/slack/web/api/endpoints/admin_apps_restricted.rb +35 -0
- data/lib/slack/web/api/endpoints/admin_conversations.rb +30 -0
- data/lib/slack/web/api/endpoints/admin_conversations_restrictAccess.rb +61 -0
- data/lib/slack/web/api/endpoints/admin_conversations_whitelist.rb +64 -0
- data/lib/slack/web/api/endpoints/admin_emoji.rb +88 -0
- data/lib/slack/web/api/endpoints/admin_inviteRequests.rb +61 -0
- data/lib/slack/web/api/endpoints/admin_inviteRequests_approved.rb +33 -0
- data/lib/slack/web/api/endpoints/admin_inviteRequests_denied.rb +33 -0
- data/lib/slack/web/api/endpoints/admin_teams.rb +50 -0
- data/lib/slack/web/api/endpoints/admin_teams_admins.rb +34 -0
- data/lib/slack/web/api/endpoints/admin_teams_owners.rb +34 -0
- data/lib/slack/web/api/endpoints/admin_teams_settings.rb +99 -0
- data/lib/slack/web/api/endpoints/admin_usergroups.rb +77 -0
- data/lib/slack/web/api/endpoints/admin_users.rb +163 -0
- data/lib/slack/web/api/endpoints/admin_users_session.rb +28 -0
- 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/calls.rb +83 -0
- data/lib/slack/web/api/endpoints/calls_participants.rb +42 -0
- data/lib/slack/web/api/endpoints/channels.rb +44 -29
- data/lib/slack/web/api/endpoints/chat.rb +38 -31
- data/lib/slack/web/api/endpoints/chat_scheduledMessages.rb +3 -2
- data/lib/slack/web/api/endpoints/conversations.rb +34 -35
- data/lib/slack/web/api/endpoints/dialog.rb +2 -1
- data/lib/slack/web/api/endpoints/dnd.rb +6 -4
- data/lib/slack/web/api/endpoints/emoji.rb +2 -1
- data/lib/slack/web/api/endpoints/files.rb +11 -8
- 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 +33 -18
- data/lib/slack/web/api/endpoints/im.rb +17 -12
- data/lib/slack/web/api/endpoints/migration.rb +2 -1
- data/lib/slack/web/api/endpoints/mpim.rb +16 -11
- data/lib/slack/web/api/endpoints/oauth.rb +4 -6
- data/lib/slack/web/api/endpoints/oauth_v2.rb +30 -0
- data/lib/slack/web/api/endpoints/pins.rb +8 -12
- data/lib/slack/web/api/endpoints/reactions.rb +12 -15
- 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 +6 -7
- data/lib/slack/web/api/endpoints/team.rb +7 -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 -12
- 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.rb +656 -0
- data/lib/slack/web/api/errors/slack_error.rb +14 -1
- data/lib/slack/web/api/errors/too_many_requests_error.rb +1 -0
- data/lib/slack/web/api/mixins.rb +2 -0
- data/lib/slack/web/api/mixins/channels.id.rb +1 -0
- data/lib/slack/web/api/mixins/conversations.id.rb +27 -0
- data/lib/slack/web/api/mixins/groups.id.rb +1 -0
- data/lib/slack/web/api/mixins/ids.id.rb +1 -0
- 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/{chat.6.block-kit-support.patch → chat.1.patch} +29 -26
- 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/errors.erb +20 -0
- data/lib/slack/web/api/templates/method.erb +5 -1
- data/lib/slack/web/api/templates/method_spec.erb +1 -0
- data/lib/slack/web/client.rb +2 -1
- data/lib/slack/web/config.rb +1 -0
- data/lib/slack/web/faraday/connection.rb +24 -20
- data/lib/slack/web/faraday/request.rb +1 -0
- data/lib/slack/web/faraday/response/raise_error.rb +10 -6
- data/lib/slack/web/pagination/cursor.rb +3 -2
- data/lib/slack_ruby_client.rb +1 -0
- data/lib/tasks/git.rake +1 -0
- data/lib/tasks/real_time.rake +13 -5
- data/lib/tasks/update.rake +1 -0
- data/lib/tasks/web.rake +27 -7
- data/screenshots/create-app.png +0 -0
- data/slack-ruby-client.gemspec +6 -3
- data/spec/fixtures/slack/web/channels_info.yml +108 -15
- data/spec/fixtures/slack/web/views_open_error.yml +76 -0
- data/spec/integration/integration_spec.rb +26 -23
- 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 +178 -32
- 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_approved_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_apps_requests_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_apps_restricted_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_apps_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_conversations_restrictAccess_spec.rb +32 -0
- data/spec/slack/web/api/endpoints/admin_conversations_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/admin_conversations_whitelist_spec.rb +32 -0
- data/spec/slack/web/api/endpoints/admin_emoji_spec.rb +37 -0
- data/spec/slack/web/api/endpoints/admin_inviteRequests_approved_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_inviteRequests_denied_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_inviteRequests_spec.rb +18 -0
- data/spec/slack/web/api/endpoints/admin_teams_admins_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/admin_teams_owners_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/admin_teams_settings_spec.rb +53 -0
- data/spec/slack/web/api/endpoints/admin_teams_spec.rb +16 -0
- data/spec/slack/web/api/endpoints/admin_usergroups_spec.rb +37 -0
- data/spec/slack/web/api/endpoints/admin_users_session_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/admin_users_spec.rb +75 -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 +3 -2
- data/spec/slack/web/api/endpoints/apps_permissions_users_spec.rb +4 -3
- 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/calls_participants_spec.rb +24 -0
- data/spec/slack/web/api/endpoints/calls_spec.rb +31 -0
- data/spec/slack/web/api/endpoints/chat_scheduledMessages_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/conversations_spec.rb +2 -1
- data/spec/slack/web/api/endpoints/custom_specs/auth_spec.rb +5 -1
- data/spec/slack/web/api/endpoints/custom_specs/channels_spec.rb +5 -3
- 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 +6 -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 -11
- 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 +8 -5
- data/spec/slack/web/api/errors/slack_error_spec.rb +26 -2
- data/spec/slack/web/api/mixins/channels_spec.rb +17 -7
- data/spec/slack/web/api/mixins/conversations_spec.rb +41 -0
- 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 +71 -18
- data/spec/slack/web/faraday/response/raise_error_spec.rb +41 -7
- 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 +156 -30
- data/lib/slack/web/api/patches/chat.1.text-attachments-required.patch +0 -13
- data/lib/slack/web/api/patches/chat.2.attachments-json.patch +0 -17
- data/lib/slack/web/api/patches/chat.3.update-attachments-support.patch +0 -21
- data/lib/slack/web/api/patches/chat.4.postEphemeral-attachments-support.patch +0 -17
- data/lib/slack/web/api/patches/chat.5.postEphemeral-text-or-attachments.patch +0 -13
- data/screenshots/register-bot.png +0 -0
data/spec/slack/config_spec.rb
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
require 'spec_helper'
|
|
2
3
|
|
|
3
4
|
RSpec.describe Slack::Events::Config do
|
|
4
5
|
before do
|
|
5
6
|
ENV['SLACK_SIGNING_SECRET'] = 'secret'
|
|
6
|
-
|
|
7
|
+
described_class.reset
|
|
7
8
|
end
|
|
9
|
+
|
|
10
|
+
after do
|
|
11
|
+
ENV.delete 'SLACK_SIGNING_SECRET'
|
|
12
|
+
end
|
|
13
|
+
|
|
8
14
|
it 'defaults signing secret to ENV[SLACK_SIGNING_SECRET]' do
|
|
9
15
|
expect(Slack::Events.config.signing_secret).to eq 'secret'
|
|
10
16
|
end
|
|
@@ -18,12 +24,10 @@ RSpec.describe Slack::Events::Config do
|
|
|
18
24
|
config.signature_expires_in = 45
|
|
19
25
|
end
|
|
20
26
|
end
|
|
27
|
+
|
|
21
28
|
it 'uses the configured values' do
|
|
22
29
|
expect(Slack::Events.config.signing_secret).to eq 'custom'
|
|
23
30
|
expect(Slack::Events.config.signature_expires_in).to eq 45
|
|
24
31
|
end
|
|
25
32
|
end
|
|
26
|
-
after do
|
|
27
|
-
ENV.delete 'SLACK_SIGNING_SECRET'
|
|
28
|
-
end
|
|
29
33
|
end
|
|
@@ -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,49 +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
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
|
|
52
|
+
context 'websocket_ping_timer' do
|
|
53
|
+
context 'with defaults' do
|
|
54
|
+
let(:client) { described_class.new }
|
|
55
|
+
|
|
56
|
+
it 'defaults to websocket_ping / 2' do
|
|
57
|
+
expect(client.websocket_ping_timer).to eq 15
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
context 'with websocket_ping value changed' do
|
|
62
|
+
let(:client) { described_class.new(websocket_ping: 22) }
|
|
63
|
+
|
|
64
|
+
it 'defaults to websocket_ping / 2' do
|
|
65
|
+
expect(client.websocket_ping_timer).to eq 11
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
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) }
|
|
47
73
|
let(:url) { 'wss://ms173.slack-msgs.com/websocket/lqcUiAvrKTP-uuid=' }
|
|
74
|
+
|
|
48
75
|
describe '#start!' do
|
|
49
76
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
77
|
+
|
|
50
78
|
before do
|
|
51
|
-
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
|
+
)
|
|
52
82
|
allow(socket).to receive(:connect!)
|
|
53
83
|
allow(socket).to receive(:start_sync)
|
|
54
84
|
client.start!
|
|
55
85
|
end
|
|
86
|
+
|
|
56
87
|
describe 'properties provided upon connection' do
|
|
57
88
|
it 'sets url' do
|
|
58
89
|
expect(client.url).to eq url
|
|
@@ -86,7 +117,13 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
86
117
|
it 'sets groups' do
|
|
87
118
|
expect(client.groups.count).to eq 1
|
|
88
119
|
end
|
|
120
|
+
it 'includes team name in to_s' do
|
|
121
|
+
expect(client.to_s).to eq(
|
|
122
|
+
"id=#{client.team.id}, name=#{client.team.name}, domain=#{client.team.domain}"
|
|
123
|
+
)
|
|
124
|
+
end
|
|
89
125
|
end
|
|
126
|
+
|
|
90
127
|
it 'uses web client to fetch url' do
|
|
91
128
|
expect(client.web_client).to be_a Slack::Web::Client
|
|
92
129
|
end
|
|
@@ -100,9 +137,10 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
100
137
|
end
|
|
101
138
|
describe '#stop!' do
|
|
102
139
|
before do
|
|
103
|
-
|
|
140
|
+
allow(socket).to receive(:disconnect!)
|
|
104
141
|
client.stop!
|
|
105
142
|
end
|
|
143
|
+
|
|
106
144
|
it 'cannot be invoked twice' do
|
|
107
145
|
client.instance_variable_set('@socket', nil) # caused by a :close callback
|
|
108
146
|
expect do
|
|
@@ -110,12 +148,14 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
110
148
|
end.to raise_error Slack::RealTime::Client::ClientNotStartedError
|
|
111
149
|
end
|
|
112
150
|
end
|
|
151
|
+
|
|
113
152
|
describe '#next_id' do
|
|
114
153
|
it 'increments' do
|
|
115
154
|
previous_id = client.send(:next_id)
|
|
116
155
|
expect(client.send(:next_id)).to eq previous_id + 1
|
|
117
156
|
end
|
|
118
157
|
end
|
|
158
|
+
|
|
119
159
|
context 'subclassed' do
|
|
120
160
|
it 'runs event handlers' do
|
|
121
161
|
event = Slack::RealTime::Event.new(
|
|
@@ -127,14 +167,19 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
127
167
|
end
|
|
128
168
|
end
|
|
129
169
|
end
|
|
170
|
+
|
|
130
171
|
describe '#start_async' do
|
|
131
172
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
173
|
+
|
|
132
174
|
before do
|
|
133
|
-
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
|
+
)
|
|
134
178
|
allow(socket).to receive(:connect!)
|
|
135
179
|
allow(socket).to receive(:start_async)
|
|
136
180
|
client.start_async
|
|
137
181
|
end
|
|
182
|
+
|
|
138
183
|
describe '#run_ping!' do
|
|
139
184
|
it 'sends ping messages when the websocket connection is idle' do
|
|
140
185
|
allow(socket).to receive(:time_since_last_message).and_return(30)
|
|
@@ -148,20 +193,62 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
148
193
|
expect(socket).to receive(:restart_async)
|
|
149
194
|
client.run_ping!
|
|
150
195
|
end
|
|
196
|
+
[
|
|
197
|
+
EOFError,
|
|
198
|
+
Errno::ECONNRESET,
|
|
199
|
+
Errno::EPIPE,
|
|
200
|
+
Faraday::ClientError,
|
|
201
|
+
Slack::Web::Api::Errors::SlackError
|
|
202
|
+
].each do |err|
|
|
203
|
+
context "raising #{err}" do
|
|
204
|
+
it 'does not terminate the ping worker' do
|
|
205
|
+
allow(socket).to receive(:time_since_last_message) { raise err }
|
|
206
|
+
expect(socket).not_to receive(:send_data)
|
|
207
|
+
client.run_ping!
|
|
208
|
+
end
|
|
209
|
+
end
|
|
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
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
describe 'to_s' do
|
|
230
|
+
it 'defaults to class instance' do
|
|
231
|
+
expect(client.to_s).to match(/^#<Slack::RealTime::Client:0x\h+>$/)
|
|
151
232
|
end
|
|
152
233
|
end
|
|
153
234
|
end
|
|
235
|
+
|
|
154
236
|
context 'client with starter store', vcr: { cassette_name: 'web/rtm_connect' } do
|
|
155
|
-
let(:client) {
|
|
237
|
+
let(:client) { described_class.new(store_class: Slack::RealTime::Stores::Starter) }
|
|
156
238
|
let(:url) { 'wss://mpmulti-w5tz.slack-msgs.com/websocket/uid' }
|
|
239
|
+
|
|
157
240
|
describe '#start!' do
|
|
158
241
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
242
|
+
|
|
159
243
|
before do
|
|
160
|
-
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
|
+
)
|
|
161
247
|
allow(socket).to receive(:connect!)
|
|
162
248
|
allow(socket).to receive(:start_sync)
|
|
163
249
|
client.start!
|
|
164
250
|
end
|
|
251
|
+
|
|
165
252
|
describe 'properties provided upon connection' do
|
|
166
253
|
it 'sets url' do
|
|
167
254
|
expect(client.url).to eq url
|
|
@@ -190,7 +277,13 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
190
277
|
it 'no groups' do
|
|
191
278
|
expect(client.groups).to be_nil
|
|
192
279
|
end
|
|
280
|
+
it 'includes team name in to_s' do
|
|
281
|
+
expect(client.to_s).to eq(
|
|
282
|
+
"id=#{client.team.id}, name=#{client.team.name}, domain=#{client.team.domain}"
|
|
283
|
+
)
|
|
284
|
+
end
|
|
193
285
|
end
|
|
286
|
+
|
|
194
287
|
it 'uses web client to fetch url' do
|
|
195
288
|
expect(client.web_client).to be_a Slack::Web::Client
|
|
196
289
|
end
|
|
@@ -204,9 +297,10 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
204
297
|
end
|
|
205
298
|
describe '#stop!' do
|
|
206
299
|
before do
|
|
207
|
-
|
|
300
|
+
allow(socket).to receive(:disconnect!)
|
|
208
301
|
client.stop!
|
|
209
302
|
end
|
|
303
|
+
|
|
210
304
|
it 'cannot be invoked twice' do
|
|
211
305
|
client.instance_variable_set('@socket', nil) # caused by a :close callback
|
|
212
306
|
expect do
|
|
@@ -214,6 +308,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
214
308
|
end.to raise_error Slack::RealTime::Client::ClientNotStartedError
|
|
215
309
|
end
|
|
216
310
|
end
|
|
311
|
+
|
|
217
312
|
describe '#next_id' do
|
|
218
313
|
it 'increments' do
|
|
219
314
|
previous_id = client.send(:next_id)
|
|
@@ -222,9 +317,11 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
222
317
|
end
|
|
223
318
|
end
|
|
224
319
|
end
|
|
320
|
+
|
|
225
321
|
context 'client with nil store', vcr: { cassette_name: 'web/rtm_connect' } do
|
|
226
|
-
let(:client) {
|
|
322
|
+
let(:client) { described_class.new(store_class: nil) }
|
|
227
323
|
let(:url) { 'wss://mpmulti-w5tz.slack-msgs.com/websocket/uid' }
|
|
324
|
+
|
|
228
325
|
it 'sets store to nil' do
|
|
229
326
|
expect(client.store).to be nil
|
|
230
327
|
end
|
|
@@ -233,7 +330,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
233
330
|
'type' => 'team_rename',
|
|
234
331
|
'name' => 'New Team Name Inc.'
|
|
235
332
|
)
|
|
236
|
-
expect(client).
|
|
333
|
+
expect(client).not_to receive(:run_handlers)
|
|
237
334
|
client.send(:dispatch, event)
|
|
238
335
|
end
|
|
239
336
|
it 'self' do
|
|
@@ -242,9 +339,16 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
242
339
|
it 'team' do
|
|
243
340
|
expect(client.team).to be nil
|
|
244
341
|
end
|
|
342
|
+
describe 'to_s' do
|
|
343
|
+
it 'defaults to class instance' do
|
|
344
|
+
expect(client.to_s).to match(/^#<Slack::RealTime::Client:0x\h+>$/)
|
|
345
|
+
end
|
|
346
|
+
end
|
|
245
347
|
end
|
|
348
|
+
|
|
246
349
|
context 'client with defaults' do
|
|
247
|
-
let(:client) {
|
|
350
|
+
let(:client) { described_class.new }
|
|
351
|
+
|
|
248
352
|
describe '#initialize' do
|
|
249
353
|
it 'sets ping' do
|
|
250
354
|
expect(client.websocket_ping).to eq 30
|
|
@@ -264,6 +368,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
264
368
|
end
|
|
265
369
|
end
|
|
266
370
|
end
|
|
371
|
+
|
|
267
372
|
describe '#run_ping?' do
|
|
268
373
|
it 'returns true when websocket_ping is greater than 0' do
|
|
269
374
|
client.websocket_ping = 30
|
|
@@ -277,37 +382,56 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
277
382
|
end
|
|
278
383
|
end
|
|
279
384
|
end
|
|
385
|
+
|
|
280
386
|
context 'with custom settings' do
|
|
281
387
|
describe '#initialize' do
|
|
282
388
|
Slack::RealTime::Config::ATTRIBUTES.each do |key|
|
|
283
|
-
context key do
|
|
284
|
-
let(:client) {
|
|
389
|
+
context key.to_s do
|
|
390
|
+
let(:client) { described_class.new(key => 'custom') }
|
|
391
|
+
|
|
285
392
|
it "sets #{key}" do
|
|
286
|
-
expect(client.send(key)).
|
|
393
|
+
expect(client.send(key)).not_to eq Slack::RealTime::Config.send(key)
|
|
287
394
|
expect(client.send(key)).to eq 'custom'
|
|
288
395
|
end
|
|
289
396
|
end
|
|
290
397
|
end
|
|
291
398
|
end
|
|
399
|
+
|
|
400
|
+
describe 'logger accessor' do
|
|
401
|
+
let(:client) { described_class.new }
|
|
402
|
+
|
|
403
|
+
it 'exposes public logger' do
|
|
404
|
+
expect(client.logger).to be_a(::Logger)
|
|
405
|
+
end
|
|
406
|
+
it 'exposes public logger=' do
|
|
407
|
+
expect { client.logger = nil }.not_to raise_error(NoMethodError)
|
|
408
|
+
end
|
|
409
|
+
end
|
|
292
410
|
end
|
|
411
|
+
|
|
293
412
|
context 'global config' do
|
|
294
413
|
after do
|
|
295
|
-
|
|
414
|
+
described_class.config.reset
|
|
296
415
|
end
|
|
416
|
+
|
|
297
417
|
let(:url) { 'wss://ms173.slack-msgs.com/websocket/lqcUiAvrKTP-uuid=' }
|
|
298
|
-
let(:client) {
|
|
418
|
+
let(:client) { described_class.new }
|
|
419
|
+
|
|
299
420
|
context 'ping' do
|
|
300
421
|
before do
|
|
301
|
-
|
|
422
|
+
described_class.configure do |config|
|
|
302
423
|
config.websocket_ping = 15
|
|
303
424
|
end
|
|
304
425
|
end
|
|
426
|
+
|
|
305
427
|
describe '#initialize' do
|
|
306
428
|
it 'sets ping' do
|
|
307
429
|
expect(client.websocket_ping).to eq 15
|
|
308
430
|
end
|
|
309
431
|
it 'creates a connection with custom ping', vcr: { cassette_name: 'web/rtm_start' } do
|
|
310
|
-
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
|
+
)
|
|
311
435
|
client.start!
|
|
312
436
|
end
|
|
313
437
|
it 'sets start_options' do
|
|
@@ -315,15 +439,17 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
315
439
|
end
|
|
316
440
|
end
|
|
317
441
|
end
|
|
442
|
+
|
|
318
443
|
context 'proxy' do
|
|
319
444
|
before do
|
|
320
|
-
|
|
445
|
+
described_class.configure do |config|
|
|
321
446
|
config.websocket_proxy = {
|
|
322
447
|
origin: 'http://username:password@proxy.example.com',
|
|
323
448
|
headers: { 'User-Agent' => 'ruby' }
|
|
324
449
|
}
|
|
325
450
|
end
|
|
326
451
|
end
|
|
452
|
+
|
|
327
453
|
describe '#initialize' do
|
|
328
454
|
it 'sets proxy' do
|
|
329
455
|
expect(client.websocket_proxy).to eq(
|
|
@@ -345,40 +471,48 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
345
471
|
end
|
|
346
472
|
end
|
|
347
473
|
end
|
|
474
|
+
|
|
348
475
|
context 'start_options' do
|
|
349
476
|
before do
|
|
350
|
-
|
|
477
|
+
described_class.configure do |config|
|
|
351
478
|
config.start_options = { simple_latest: true }
|
|
352
479
|
end
|
|
353
480
|
end
|
|
481
|
+
|
|
354
482
|
describe '#initialize' do
|
|
355
483
|
it 'sets start_options' do
|
|
356
484
|
expect(client.start_options).to eq(simple_latest: true)
|
|
357
485
|
end
|
|
358
486
|
context 'start!' do
|
|
359
487
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
488
|
+
|
|
360
489
|
before do
|
|
361
490
|
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
|
362
491
|
allow(socket).to receive(:connect!)
|
|
363
492
|
allow(socket).to receive(:start_sync)
|
|
364
493
|
end
|
|
494
|
+
|
|
365
495
|
it 'calls rtm_start with start options', vcr: { cassette_name: 'web/rtm_start' } do
|
|
366
|
-
expect(client.web_client).to
|
|
496
|
+
expect(client.web_client).to(
|
|
497
|
+
receive(:rtm_start).with(simple_latest: true).and_call_original
|
|
498
|
+
)
|
|
367
499
|
client.start!
|
|
368
500
|
end
|
|
369
501
|
end
|
|
370
502
|
end
|
|
371
503
|
end
|
|
504
|
+
|
|
372
505
|
context 'store_class' do
|
|
373
506
|
context 'starter' do
|
|
374
507
|
before do
|
|
375
|
-
|
|
508
|
+
described_class.configure do |config|
|
|
376
509
|
config.store_class = Slack::RealTime::Stores::Starter
|
|
377
510
|
end
|
|
378
511
|
end
|
|
512
|
+
|
|
379
513
|
describe '#initialize' do
|
|
380
514
|
it 'can be overriden explicitly' do
|
|
381
|
-
client =
|
|
515
|
+
client = described_class.new(store_class: Slack::RealTime::Store)
|
|
382
516
|
expect(client.send(:store_class)).to eq Slack::RealTime::Store
|
|
383
517
|
end
|
|
384
518
|
it 'sets store_class' do
|
|
@@ -386,11 +520,13 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
386
520
|
end
|
|
387
521
|
context 'start!' do
|
|
388
522
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
523
|
+
|
|
389
524
|
before do
|
|
390
525
|
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
|
391
526
|
allow(socket).to receive(:connect!)
|
|
392
527
|
allow(socket).to receive(:start_sync)
|
|
393
528
|
end
|
|
529
|
+
|
|
394
530
|
it 'instantiates the correct store class', vcr: { cassette_name: 'web/rtm_connect' } do
|
|
395
531
|
client.start!
|
|
396
532
|
expect(client.store).to be_a Slack::RealTime::Stores::Starter
|
|
@@ -398,20 +534,24 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
398
534
|
end
|
|
399
535
|
end
|
|
400
536
|
end
|
|
537
|
+
|
|
401
538
|
context 'store' do
|
|
402
539
|
before do
|
|
403
|
-
|
|
540
|
+
described_class.configure do |config|
|
|
404
541
|
config.store_class = Slack::RealTime::Stores::Store
|
|
405
542
|
end
|
|
406
543
|
end
|
|
544
|
+
|
|
407
545
|
describe '#initialize' do
|
|
408
546
|
context 'start!' do
|
|
409
547
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
548
|
+
|
|
410
549
|
before do
|
|
411
550
|
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
|
412
551
|
allow(socket).to receive(:connect!)
|
|
413
552
|
allow(socket).to receive(:start_sync)
|
|
414
553
|
end
|
|
554
|
+
|
|
415
555
|
it 'calls rtm_start and not rtm_connect', vcr: { cassette_name: 'web/rtm_start' } do
|
|
416
556
|
expect(client.web_client).to receive(:rtm_start).and_call_original
|
|
417
557
|
client.start!
|
|
@@ -420,18 +560,20 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
420
560
|
end
|
|
421
561
|
end
|
|
422
562
|
end
|
|
563
|
+
|
|
423
564
|
context 'start_method' do
|
|
424
565
|
describe '#initialize' do
|
|
425
566
|
it 'can be overriden explicitly' do
|
|
426
|
-
client =
|
|
567
|
+
client = described_class.new(start_method: :overriden)
|
|
427
568
|
expect(client.send(:start_method)).to eq :overriden
|
|
428
569
|
end
|
|
429
570
|
context 'with start_method' do
|
|
430
571
|
before do
|
|
431
|
-
|
|
572
|
+
described_class.configure do |config|
|
|
432
573
|
config.start_method = :overriden
|
|
433
574
|
end
|
|
434
575
|
end
|
|
576
|
+
|
|
435
577
|
it 'sets start_method' do
|
|
436
578
|
expect(client.send(:start_method)).to eq :overriden
|
|
437
579
|
end
|
|
@@ -442,14 +584,18 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
442
584
|
end.to raise_error RuntimeError, 'overriden'
|
|
443
585
|
end
|
|
444
586
|
end
|
|
587
|
+
|
|
445
588
|
context 'start!' do
|
|
446
589
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
590
|
+
|
|
447
591
|
before do
|
|
448
592
|
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
|
449
593
|
allow(socket).to receive(:connect!)
|
|
450
594
|
allow(socket).to receive(:start_sync)
|
|
451
595
|
end
|
|
452
|
-
|
|
596
|
+
|
|
597
|
+
it 'defaults to :rtm_start when using full store',
|
|
598
|
+
vcr: { cassette_name: 'web/rtm_start' } do
|
|
453
599
|
expect(client.web_client).to receive(:rtm_start).and_call_original
|
|
454
600
|
client.start!
|
|
455
601
|
end
|