slack-ruby-client 0.14.4 → 0.16.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 +104 -47
- data/.travis.yml +1 -5
- data/CHANGELOG.md +41 -2
- data/CONTRIBUTING.md +17 -6
- data/Dangerfile +2 -1
- data/Gemfile +2 -2
- data/README.md +94 -53
- data/Rakefile +1 -0
- data/UPGRADING.md +20 -2
- data/bin/commands.rb +30 -0
- data/bin/commands/admin_analytics.rb +15 -0
- data/bin/commands/admin_apps.rb +40 -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_barriers.rb +47 -0
- data/bin/commands/admin_conversations.rb +169 -0
- data/bin/commands/admin_conversations_ekm.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 +25 -2
- data/bin/commands/api.rb +3 -3
- data/bin/commands/apps.rb +3 -2
- data/bin/commands/apps_connections.rb +13 -0
- data/bin/commands/apps_event_authorizations.rb +16 -0
- 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/auth_teams.rb +16 -0
- data/bin/commands/bots.rb +4 -2
- data/bin/commands/calls.rb +52 -0
- data/bin/commands/calls_participants.rb +25 -0
- data/bin/commands/channels.rb +37 -33
- data/bin/commands/chat.rb +34 -33
- data/bin/commands/chat_scheduledMessages.rb +4 -2
- data/bin/commands/conversations.rb +50 -38
- data/bin/commands/dialog.rb +3 -2
- data/bin/commands/dnd.rb +10 -9
- data/bin/commands/emoji.rb +3 -2
- data/bin/commands/files.rb +16 -13
- data/bin/commands/files_comments.rb +3 -2
- data/bin/commands/files_remote.rb +78 -0
- data/bin/commands/groups.rb +38 -35
- data/bin/commands/im.rb +14 -13
- data/bin/commands/migration.rb +4 -2
- data/bin/commands/mpim.rb +14 -13
- data/bin/commands/oauth.rb +6 -5
- data/bin/commands/oauth_v2.rb +17 -0
- data/bin/commands/pins.rb +7 -10
- data/bin/commands/reactions.rb +11 -11
- data/bin/commands/reminders.rb +11 -10
- data/bin/commands/rtm.rb +5 -4
- data/bin/commands/search.rb +11 -7
- data/bin/commands/stars.rb +7 -6
- data/bin/commands/team.rb +12 -8
- data/bin/commands/team_profile.rb +3 -2
- data/bin/commands/usergroups.rb +17 -11
- data/bin/commands/usergroups_users.rb +7 -4
- data/bin/commands/users.rb +26 -23
- data/bin/commands/users_admin.rb +1 -0
- data/bin/commands/users_prefs.rb +1 -0
- data/bin/commands/users_profile.rb +6 -5
- data/bin/commands/views.rb +48 -0
- data/bin/commands/workflows.rb +38 -0
- data/bin/slack +1 -2
- 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_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 +6 -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 +8 -2
- 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 +21 -13
- data/lib/slack/real_time/concurrency.rb +1 -2
- data/lib/slack/real_time/concurrency/async.rb +12 -6
- data/lib/slack/real_time/config.rb +9 -3
- 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 +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 +60 -0
- data/lib/slack/web/api/endpoints/admin_analytics.rb +26 -0
- data/lib/slack/web/api/endpoints/admin_apps.rb +62 -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_barriers.rb +82 -0
- data/lib/slack/web/api/endpoints/admin_conversations.rb +260 -0
- data/lib/slack/web/api/endpoints/admin_conversations_ekm.rb +35 -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 +161 -0
- data/lib/slack/web/api/endpoints/admin_users_session.rb +40 -1
- data/lib/slack/web/api/endpoints/api.rb +2 -3
- data/lib/slack/web/api/endpoints/apps.rb +2 -1
- data/lib/slack/web/api/endpoints/apps_connections.rb +21 -0
- data/lib/slack/web/api/endpoints/apps_event_authorizations.rb +34 -0
- 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/auth_teams.rb +33 -0
- data/lib/slack/web/api/endpoints/bots.rb +4 -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 +52 -31
- data/lib/slack/web/api/endpoints/chat.rb +31 -30
- data/lib/slack/web/api/endpoints/chat_scheduledMessages.rb +5 -2
- data/lib/slack/web/api/endpoints/conversations.rb +55 -36
- 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 +13 -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 +39 -24
- data/lib/slack/web/api/endpoints/im.rb +17 -12
- data/lib/slack/web/api/endpoints/migration.rb +4 -1
- data/lib/slack/web/api/endpoints/mpim.rb +18 -13
- 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 +7 -16
- data/lib/slack/web/api/endpoints/reactions.rb +14 -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 +10 -3
- data/lib/slack/web/api/endpoints/stars.rb +6 -7
- data/lib/slack/web/api/endpoints/team.rb +11 -5
- data/lib/slack/web/api/endpoints/team_profile.rb +2 -1
- data/lib/slack/web/api/endpoints/usergroups.rb +16 -5
- data/lib/slack/web/api/endpoints/usergroups_users.rb +7 -2
- data/lib/slack/web/api/endpoints/users.rb +18 -21
- 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 +4 -3
- data/lib/slack/web/api/endpoints/views.rb +97 -0
- data/lib/slack/web/api/endpoints/workflows.rb +61 -0
- data/lib/slack/web/api/error.rb +1 -0
- data/lib/slack/web/api/errors.rb +850 -0
- data/lib/slack/web/api/errors/internal_error.rb +14 -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 +2 -3
- data/lib/slack/web/api/mixins/conversations.id.rb +25 -0
- data/lib/slack/web/api/mixins/groups.id.rb +2 -3
- data/lib/slack/web/api/mixins/ids.id.rb +3 -2
- data/lib/slack/web/api/mixins/users.id.rb +2 -3
- 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 +2 -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 +2 -1
- data/lib/slack/web/client.rb +2 -1
- data/lib/slack/web/config.rb +3 -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 +25 -6
- data/lib/slack/web/faraday/response/wrap_error.rb +18 -0
- 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 +34 -10
- 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/conversations_setTopic.yml +69 -0
- data/spec/fixtures/slack/web/conversations_setTopic_one_page.yml +142 -0
- data/spec/fixtures/slack/web/conversations_setTopic_paginated.yml +208 -0
- data/spec/fixtures/slack/web/views_open_error.yml +76 -0
- 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 +74 -40
- 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 +153 -38
- 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_analytics_spec.rb +13 -0
- 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 +13 -0
- data/spec/slack/web/api/endpoints/admin_barriers_spec.rb +38 -0
- data/spec/slack/web/api/endpoints/admin_conversations_ekm_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 +98 -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 +9 -0
- data/spec/slack/web/api/endpoints/admin_users_spec.rb +67 -0
- data/spec/slack/web/api/endpoints/api_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/apps_connections_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/apps_event_authorizations_spec.rb +13 -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 +3 -2
- data/spec/slack/web/api/endpoints/auth_teams_spec.rb +8 -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 +21 -12
- 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 +1 -0
- data/spec/slack/web/api/endpoints/emoji_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/files_comments_spec.rb +3 -2
- data/spec/slack/web/api/endpoints/files_remote_spec.rb +24 -0
- data/spec/slack/web/api/endpoints/files_spec.rb +5 -4
- data/spec/slack/web/api/endpoints/im_spec.rb +5 -4
- data/spec/slack/web/api/endpoints/migration_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/mpim_spec.rb +5 -4
- data/spec/slack/web/api/endpoints/oauth_spec.rb +4 -14
- data/spec/slack/web/api/endpoints/oauth_v2_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/pins_spec.rb +1 -0
- data/spec/slack/web/api/endpoints/reactions_spec.rb +8 -1
- data/spec/slack/web/api/endpoints/reminders_spec.rb +3 -2
- 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 +3 -2
- 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/endpoints/workflows_spec.rb +26 -0
- data/spec/slack/web/api/error_spec.rb +4 -2
- 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_list_spec.rb +21 -0
- data/spec/slack/web/api/mixins/conversations_spec.rb +43 -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 +171 -18
- data/spec/slack/web/faraday/response/raise_error_spec.rb +47 -12
- 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 +5 -0
- metadata +190 -46
- data/examples/hi_real_time/Gemfile +0 -5
- data/examples/hi_real_time/hi.gif +0 -0
- data/examples/hi_real_time/hi.rb +0 -37
- data/examples/hi_real_time_async_celluloid/Gemfile +0 -6
- data/examples/hi_real_time_async_celluloid/Procfile +0 -2
- data/examples/hi_real_time_async_celluloid/hi.rb +0 -35
- data/examples/hi_real_time_async_eventmachine/Gemfile +0 -6
- data/examples/hi_real_time_async_eventmachine/Procfile +0 -2
- data/examples/hi_real_time_async_eventmachine/hi.rb +0 -35
- data/lib/slack/real_time/concurrency/celluloid.rb +0 -136
- data/lib/slack/real_time/concurrency/eventmachine.rb +0 -82
- 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 -15
- data/screenshots/register-bot.png +0 -0
- data/spec/slack/real_time/concurrency/celluloid_spec.rb +0 -111
- data/spec/slack/real_time/concurrency/eventmachine_spec.rb +0 -49
- data/spec/slack/web/api/errors/service_unavailable_spec.rb +0 -14
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,60 +1,82 @@
|
|
|
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: {
|
|
17
26
|
'X-Slack-Request-Timestamp' => timestamp,
|
|
18
27
|
'X-Slack-Signature' => signature
|
|
19
28
|
},
|
|
20
|
-
body:
|
|
21
|
-
read: body
|
|
22
|
-
)
|
|
29
|
+
body: StringIO.new(body)
|
|
23
30
|
)
|
|
24
31
|
end
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
|
|
33
|
+
after do
|
|
34
|
+
Slack::Events.config.reset
|
|
27
35
|
end
|
|
36
|
+
|
|
28
37
|
it 'reads http request' do
|
|
29
|
-
expect(
|
|
30
|
-
expect(
|
|
31
|
-
expect(
|
|
32
|
-
expect(
|
|
38
|
+
expect(request.signature).to eq signature
|
|
39
|
+
expect(request.body).to eq body
|
|
40
|
+
expect(request.timestamp).to eq timestamp
|
|
41
|
+
expect(request.version).to eq 'v0'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'rewinds the request body after reading it' do
|
|
45
|
+
expect(request.body).to eq body
|
|
46
|
+
expect(http_request.body.read).to eq body
|
|
33
47
|
end
|
|
48
|
+
|
|
34
49
|
context 'time' do
|
|
35
50
|
after do
|
|
36
51
|
Timecop.return
|
|
37
52
|
end
|
|
53
|
+
|
|
38
54
|
context 'with an invalid signature' do
|
|
39
55
|
let(:signature) { 'v0=invalid' }
|
|
56
|
+
|
|
40
57
|
before do
|
|
41
58
|
Timecop.freeze(Time.at(timestamp.to_i))
|
|
42
59
|
end
|
|
60
|
+
|
|
43
61
|
it 'is invalid but not expired' do
|
|
44
|
-
expect(
|
|
45
|
-
expect(
|
|
62
|
+
expect(request).not_to be_valid
|
|
63
|
+
expect(request).not_to be_expired
|
|
46
64
|
end
|
|
47
65
|
end
|
|
66
|
+
|
|
48
67
|
context 'with an invalid body' do
|
|
49
68
|
let(:body) { 'invalid' }
|
|
69
|
+
|
|
50
70
|
before do
|
|
51
71
|
Timecop.freeze(Time.at(timestamp.to_i))
|
|
52
72
|
end
|
|
73
|
+
|
|
53
74
|
it 'is invalid but not expired' do
|
|
54
|
-
expect(
|
|
55
|
-
expect(
|
|
75
|
+
expect(request).not_to be_valid
|
|
76
|
+
expect(request).not_to be_expired
|
|
56
77
|
end
|
|
57
78
|
end
|
|
79
|
+
|
|
58
80
|
context 'with an invalid signing secret' do
|
|
59
81
|
before do
|
|
60
82
|
Slack::Events.configure do |config|
|
|
@@ -62,88 +84,100 @@ RSpec.describe Slack::Events::Request do
|
|
|
62
84
|
end
|
|
63
85
|
Timecop.freeze(Time.at(timestamp.to_i))
|
|
64
86
|
end
|
|
87
|
+
|
|
65
88
|
it 'is invalid but not expired' do
|
|
66
|
-
expect(
|
|
67
|
-
expect(
|
|
89
|
+
expect(request).not_to be_valid
|
|
90
|
+
expect(request).not_to be_expired
|
|
68
91
|
end
|
|
69
92
|
end
|
|
93
|
+
|
|
70
94
|
context 'within time window' do
|
|
71
95
|
before do
|
|
72
96
|
Timecop.freeze(Time.at(timestamp.to_i) + Slack::Events.config.signature_expires_in - 1)
|
|
73
97
|
end
|
|
98
|
+
|
|
74
99
|
it 'is valid' do
|
|
75
|
-
expect(
|
|
76
|
-
expect(
|
|
100
|
+
expect(request).to be_valid
|
|
101
|
+
expect(request).not_to be_expired
|
|
77
102
|
end
|
|
78
103
|
it 'does not raise an error and returns true' do
|
|
79
|
-
expect(
|
|
104
|
+
expect(request.verify!).to be true
|
|
80
105
|
end
|
|
81
106
|
end
|
|
107
|
+
|
|
82
108
|
context 'after time window' do
|
|
83
109
|
before do
|
|
84
110
|
Timecop.freeze(Time.at(timestamp.to_i) + Slack::Events.config.signature_expires_in + 1)
|
|
85
111
|
end
|
|
112
|
+
|
|
86
113
|
it 'is valid but expired' do
|
|
87
|
-
expect(
|
|
88
|
-
expect(
|
|
114
|
+
expect(request).to be_valid
|
|
115
|
+
expect(request).to be_expired
|
|
89
116
|
end
|
|
90
117
|
it 'raises an error on verify!' do
|
|
91
|
-
expect {
|
|
118
|
+
expect { request.verify! }.to raise_error Slack::Events::Request::TimestampExpired
|
|
92
119
|
end
|
|
93
120
|
end
|
|
121
|
+
|
|
94
122
|
context 'before time but within window' do
|
|
95
123
|
before do
|
|
96
124
|
Timecop.freeze(Time.at(timestamp.to_i) - Slack::Events.config.signature_expires_in + 1)
|
|
97
125
|
end
|
|
126
|
+
|
|
98
127
|
it 'is valid and not expired' do
|
|
99
|
-
expect(
|
|
100
|
-
expect(
|
|
128
|
+
expect(request).to be_valid
|
|
129
|
+
expect(request).not_to be_expired
|
|
101
130
|
end
|
|
102
131
|
it 'does not raise an error on verify!' do
|
|
103
|
-
expect(
|
|
132
|
+
expect(request.verify!).to be true
|
|
104
133
|
end
|
|
105
134
|
end
|
|
135
|
+
|
|
106
136
|
context 'before time window' do
|
|
107
137
|
before do
|
|
108
138
|
Timecop.freeze(Time.at(timestamp.to_i) - Slack::Events.config.signature_expires_in - 1)
|
|
109
139
|
end
|
|
140
|
+
|
|
110
141
|
it 'is valid but expired' do
|
|
111
|
-
expect(
|
|
112
|
-
expect(
|
|
142
|
+
expect(request).to be_valid
|
|
143
|
+
expect(request).to be_expired
|
|
113
144
|
end
|
|
114
145
|
it 'raises an error on verify!' do
|
|
115
|
-
expect {
|
|
146
|
+
expect { request.verify! }.to raise_error Slack::Events::Request::TimestampExpired
|
|
116
147
|
end
|
|
117
148
|
end
|
|
118
149
|
end
|
|
150
|
+
|
|
119
151
|
context 'without global config' do
|
|
120
152
|
before do
|
|
121
153
|
Slack::Events.config.reset
|
|
122
154
|
end
|
|
155
|
+
|
|
123
156
|
context 'without a signing secret parameter' do
|
|
124
|
-
subject do
|
|
125
|
-
|
|
157
|
+
subject(:request) do
|
|
158
|
+
described_class.new(http_request)
|
|
126
159
|
end
|
|
160
|
+
|
|
127
161
|
it 'raises MissingSigningSecret' do
|
|
128
|
-
expect {
|
|
162
|
+
expect { request.valid? }.to raise_error Slack::Events::Request::MissingSigningSecret
|
|
129
163
|
end
|
|
130
164
|
end
|
|
165
|
+
|
|
131
166
|
context 'with a signing secret parameter' do
|
|
132
|
-
subject do
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
167
|
+
subject(:request) do
|
|
168
|
+
described_class.new(http_request,
|
|
169
|
+
signing_secret: signing_secret,
|
|
170
|
+
signature_expires_in: 30)
|
|
136
171
|
end
|
|
172
|
+
|
|
137
173
|
before do
|
|
138
174
|
Timecop.freeze(Time.at(timestamp.to_i))
|
|
139
175
|
end
|
|
176
|
+
|
|
140
177
|
it 'is valid and not expired' do
|
|
141
|
-
expect(
|
|
142
|
-
expect(
|
|
178
|
+
expect(request).to be_valid
|
|
179
|
+
expect(request).not_to be_expired
|
|
143
180
|
end
|
|
144
181
|
end
|
|
145
182
|
end
|
|
146
|
-
after do
|
|
147
|
-
Slack::Events.config.reset
|
|
148
|
-
end
|
|
149
183
|
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
4
|
RSpec.describe Slack::RealTime::Client do
|
|
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(
|
|
@@ -143,15 +166,37 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
143
166
|
expect(client.store.team.name).to eq 'New Team Name Inc.'
|
|
144
167
|
end
|
|
145
168
|
end
|
|
169
|
+
|
|
170
|
+
describe '#run_handlers' do
|
|
171
|
+
describe 'empty events' do
|
|
172
|
+
before do
|
|
173
|
+
@e = client.store.class.events
|
|
174
|
+
client.store.class.events = nil
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
after do
|
|
178
|
+
client.store.class.events = @e
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it 'returns false when event is nil' do
|
|
182
|
+
expect(client.send(:run_handlers, 'example', {})).to be nil
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
end
|
|
146
186
|
end
|
|
187
|
+
|
|
147
188
|
describe '#start_async' do
|
|
148
189
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
190
|
+
|
|
149
191
|
before do
|
|
150
|
-
allow(Slack::RealTime::Socket).to
|
|
192
|
+
allow(Slack::RealTime::Socket).to(
|
|
193
|
+
receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
|
|
194
|
+
)
|
|
151
195
|
allow(socket).to receive(:connect!)
|
|
152
196
|
allow(socket).to receive(:start_async)
|
|
153
197
|
client.start_async
|
|
154
198
|
end
|
|
199
|
+
|
|
155
200
|
describe '#run_ping!' do
|
|
156
201
|
it 'sends ping messages when the websocket connection is idle' do
|
|
157
202
|
allow(socket).to receive(:time_since_last_message).and_return(30)
|
|
@@ -165,34 +210,62 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
165
210
|
expect(socket).to receive(:restart_async)
|
|
166
211
|
client.run_ping!
|
|
167
212
|
end
|
|
168
|
-
[
|
|
213
|
+
[
|
|
214
|
+
EOFError,
|
|
215
|
+
Errno::ECONNRESET,
|
|
216
|
+
Errno::EPIPE,
|
|
217
|
+
Faraday::ClientError,
|
|
218
|
+
Slack::Web::Api::Errors::SlackError
|
|
219
|
+
].each do |err|
|
|
169
220
|
context "raising #{err}" do
|
|
170
221
|
it 'does not terminate the ping worker' do
|
|
171
222
|
allow(socket).to receive(:time_since_last_message) { raise err }
|
|
172
|
-
expect(socket).
|
|
223
|
+
expect(socket).not_to receive(:send_data)
|
|
173
224
|
client.run_ping!
|
|
174
225
|
end
|
|
175
226
|
end
|
|
176
227
|
end
|
|
228
|
+
context 'raising Slack::Web::Api::Errors::SlackError' do
|
|
229
|
+
%w[invalid_auth account_inactive].each do |code|
|
|
230
|
+
context code do
|
|
231
|
+
it 'does not terminate the ping worker' do
|
|
232
|
+
allow(socket).to receive(:time_since_last_message) {
|
|
233
|
+
raise Slack::Web::Api::Errors::SlackError, code
|
|
234
|
+
}
|
|
235
|
+
expect(socket).not_to receive(:send_data)
|
|
236
|
+
expect do
|
|
237
|
+
client.run_ping!
|
|
238
|
+
end.to raise_error Slack::Web::Api::Errors::SlackError, code
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
end
|
|
177
243
|
end
|
|
178
244
|
end
|
|
245
|
+
|
|
179
246
|
describe 'to_s' do
|
|
180
247
|
it 'defaults to class instance' do
|
|
181
248
|
expect(client.to_s).to match(/^#<Slack::RealTime::Client:0x\h+>$/)
|
|
182
249
|
end
|
|
183
250
|
end
|
|
184
251
|
end
|
|
252
|
+
|
|
185
253
|
context 'client with starter store', vcr: { cassette_name: 'web/rtm_connect' } do
|
|
186
|
-
let(:client) {
|
|
254
|
+
let(:client) { described_class.new(store_class: Slack::RealTime::Stores::Starter) }
|
|
187
255
|
let(:url) { 'wss://mpmulti-w5tz.slack-msgs.com/websocket/uid' }
|
|
256
|
+
|
|
188
257
|
describe '#start!' do
|
|
189
258
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
259
|
+
|
|
190
260
|
before do
|
|
191
|
-
allow(Slack::RealTime::Socket).to
|
|
261
|
+
allow(Slack::RealTime::Socket).to(
|
|
262
|
+
receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
|
|
263
|
+
)
|
|
192
264
|
allow(socket).to receive(:connect!)
|
|
193
265
|
allow(socket).to receive(:start_sync)
|
|
194
266
|
client.start!
|
|
195
267
|
end
|
|
268
|
+
|
|
196
269
|
describe 'properties provided upon connection' do
|
|
197
270
|
it 'sets url' do
|
|
198
271
|
expect(client.url).to eq url
|
|
@@ -222,9 +295,12 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
222
295
|
expect(client.groups).to be_nil
|
|
223
296
|
end
|
|
224
297
|
it 'includes team name in to_s' do
|
|
225
|
-
expect(client.to_s).to eq
|
|
298
|
+
expect(client.to_s).to eq(
|
|
299
|
+
"id=#{client.team.id}, name=#{client.team.name}, domain=#{client.team.domain}"
|
|
300
|
+
)
|
|
226
301
|
end
|
|
227
302
|
end
|
|
303
|
+
|
|
228
304
|
it 'uses web client to fetch url' do
|
|
229
305
|
expect(client.web_client).to be_a Slack::Web::Client
|
|
230
306
|
end
|
|
@@ -238,9 +314,10 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
238
314
|
end
|
|
239
315
|
describe '#stop!' do
|
|
240
316
|
before do
|
|
241
|
-
|
|
317
|
+
allow(socket).to receive(:disconnect!)
|
|
242
318
|
client.stop!
|
|
243
319
|
end
|
|
320
|
+
|
|
244
321
|
it 'cannot be invoked twice' do
|
|
245
322
|
client.instance_variable_set('@socket', nil) # caused by a :close callback
|
|
246
323
|
expect do
|
|
@@ -248,6 +325,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
248
325
|
end.to raise_error Slack::RealTime::Client::ClientNotStartedError
|
|
249
326
|
end
|
|
250
327
|
end
|
|
328
|
+
|
|
251
329
|
describe '#next_id' do
|
|
252
330
|
it 'increments' do
|
|
253
331
|
previous_id = client.send(:next_id)
|
|
@@ -256,9 +334,11 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
256
334
|
end
|
|
257
335
|
end
|
|
258
336
|
end
|
|
337
|
+
|
|
259
338
|
context 'client with nil store', vcr: { cassette_name: 'web/rtm_connect' } do
|
|
260
|
-
let(:client) {
|
|
339
|
+
let(:client) { described_class.new(store_class: nil) }
|
|
261
340
|
let(:url) { 'wss://mpmulti-w5tz.slack-msgs.com/websocket/uid' }
|
|
341
|
+
|
|
262
342
|
it 'sets store to nil' do
|
|
263
343
|
expect(client.store).to be nil
|
|
264
344
|
end
|
|
@@ -267,7 +347,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
267
347
|
'type' => 'team_rename',
|
|
268
348
|
'name' => 'New Team Name Inc.'
|
|
269
349
|
)
|
|
270
|
-
expect(client).
|
|
350
|
+
expect(client).not_to receive(:run_handlers)
|
|
271
351
|
client.send(:dispatch, event)
|
|
272
352
|
end
|
|
273
353
|
it 'self' do
|
|
@@ -282,8 +362,10 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
282
362
|
end
|
|
283
363
|
end
|
|
284
364
|
end
|
|
365
|
+
|
|
285
366
|
context 'client with defaults' do
|
|
286
|
-
let(:client) {
|
|
367
|
+
let(:client) { described_class.new }
|
|
368
|
+
|
|
287
369
|
describe '#initialize' do
|
|
288
370
|
it 'sets ping' do
|
|
289
371
|
expect(client.websocket_ping).to eq 30
|
|
@@ -303,6 +385,7 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
303
385
|
end
|
|
304
386
|
end
|
|
305
387
|
end
|
|
388
|
+
|
|
306
389
|
describe '#run_ping?' do
|
|
307
390
|
it 'returns true when websocket_ping is greater than 0' do
|
|
308
391
|
client.websocket_ping = 30
|
|
@@ -316,20 +399,24 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
316
399
|
end
|
|
317
400
|
end
|
|
318
401
|
end
|
|
402
|
+
|
|
319
403
|
context 'with custom settings' do
|
|
320
404
|
describe '#initialize' do
|
|
321
405
|
Slack::RealTime::Config::ATTRIBUTES.each do |key|
|
|
322
|
-
context key do
|
|
323
|
-
let(:client) {
|
|
406
|
+
context key.to_s do
|
|
407
|
+
let(:client) { described_class.new(key => 'custom') }
|
|
408
|
+
|
|
324
409
|
it "sets #{key}" do
|
|
325
|
-
expect(client.send(key)).
|
|
410
|
+
expect(client.send(key)).not_to eq Slack::RealTime::Config.send(key)
|
|
326
411
|
expect(client.send(key)).to eq 'custom'
|
|
327
412
|
end
|
|
328
413
|
end
|
|
329
414
|
end
|
|
330
415
|
end
|
|
416
|
+
|
|
331
417
|
describe 'logger accessor' do
|
|
332
|
-
let(:client) {
|
|
418
|
+
let(:client) { described_class.new }
|
|
419
|
+
|
|
333
420
|
it 'exposes public logger' do
|
|
334
421
|
expect(client.logger).to be_a(::Logger)
|
|
335
422
|
end
|
|
@@ -338,24 +425,30 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
338
425
|
end
|
|
339
426
|
end
|
|
340
427
|
end
|
|
428
|
+
|
|
341
429
|
context 'global config' do
|
|
342
430
|
after do
|
|
343
|
-
|
|
431
|
+
described_class.config.reset
|
|
344
432
|
end
|
|
433
|
+
|
|
345
434
|
let(:url) { 'wss://ms173.slack-msgs.com/websocket/lqcUiAvrKTP-uuid=' }
|
|
346
|
-
let(:client) {
|
|
435
|
+
let(:client) { described_class.new }
|
|
436
|
+
|
|
347
437
|
context 'ping' do
|
|
348
438
|
before do
|
|
349
|
-
|
|
439
|
+
described_class.configure do |config|
|
|
350
440
|
config.websocket_ping = 15
|
|
351
441
|
end
|
|
352
442
|
end
|
|
443
|
+
|
|
353
444
|
describe '#initialize' do
|
|
354
445
|
it 'sets ping' do
|
|
355
446
|
expect(client.websocket_ping).to eq 15
|
|
356
447
|
end
|
|
357
448
|
it 'creates a connection with custom ping', vcr: { cassette_name: 'web/rtm_start' } do
|
|
358
|
-
expect(Slack::RealTime::Concurrency::Mock::WebSocket).to
|
|
449
|
+
expect(Slack::RealTime::Concurrency::Mock::WebSocket).to(
|
|
450
|
+
receive(:new).with(url, nil, ping: 15).and_return(ws)
|
|
451
|
+
)
|
|
359
452
|
client.start!
|
|
360
453
|
end
|
|
361
454
|
it 'sets start_options' do
|
|
@@ -363,15 +456,17 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
363
456
|
end
|
|
364
457
|
end
|
|
365
458
|
end
|
|
459
|
+
|
|
366
460
|
context 'proxy' do
|
|
367
461
|
before do
|
|
368
|
-
|
|
462
|
+
described_class.configure do |config|
|
|
369
463
|
config.websocket_proxy = {
|
|
370
464
|
origin: 'http://username:password@proxy.example.com',
|
|
371
465
|
headers: { 'User-Agent' => 'ruby' }
|
|
372
466
|
}
|
|
373
467
|
end
|
|
374
468
|
end
|
|
469
|
+
|
|
375
470
|
describe '#initialize' do
|
|
376
471
|
it 'sets proxy' do
|
|
377
472
|
expect(client.websocket_proxy).to eq(
|
|
@@ -393,40 +488,48 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
393
488
|
end
|
|
394
489
|
end
|
|
395
490
|
end
|
|
491
|
+
|
|
396
492
|
context 'start_options' do
|
|
397
493
|
before do
|
|
398
|
-
|
|
494
|
+
described_class.configure do |config|
|
|
399
495
|
config.start_options = { simple_latest: true }
|
|
400
496
|
end
|
|
401
497
|
end
|
|
498
|
+
|
|
402
499
|
describe '#initialize' do
|
|
403
500
|
it 'sets start_options' do
|
|
404
501
|
expect(client.start_options).to eq(simple_latest: true)
|
|
405
502
|
end
|
|
406
503
|
context 'start!' do
|
|
407
504
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
505
|
+
|
|
408
506
|
before do
|
|
409
507
|
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
|
410
508
|
allow(socket).to receive(:connect!)
|
|
411
509
|
allow(socket).to receive(:start_sync)
|
|
412
510
|
end
|
|
511
|
+
|
|
413
512
|
it 'calls rtm_start with start options', vcr: { cassette_name: 'web/rtm_start' } do
|
|
414
|
-
expect(client.web_client).to
|
|
513
|
+
expect(client.web_client).to(
|
|
514
|
+
receive(:rtm_start).with(simple_latest: true).and_call_original
|
|
515
|
+
)
|
|
415
516
|
client.start!
|
|
416
517
|
end
|
|
417
518
|
end
|
|
418
519
|
end
|
|
419
520
|
end
|
|
521
|
+
|
|
420
522
|
context 'store_class' do
|
|
421
523
|
context 'starter' do
|
|
422
524
|
before do
|
|
423
|
-
|
|
525
|
+
described_class.configure do |config|
|
|
424
526
|
config.store_class = Slack::RealTime::Stores::Starter
|
|
425
527
|
end
|
|
426
528
|
end
|
|
529
|
+
|
|
427
530
|
describe '#initialize' do
|
|
428
531
|
it 'can be overriden explicitly' do
|
|
429
|
-
client =
|
|
532
|
+
client = described_class.new(store_class: Slack::RealTime::Store)
|
|
430
533
|
expect(client.send(:store_class)).to eq Slack::RealTime::Store
|
|
431
534
|
end
|
|
432
535
|
it 'sets store_class' do
|
|
@@ -434,11 +537,13 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
434
537
|
end
|
|
435
538
|
context 'start!' do
|
|
436
539
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
540
|
+
|
|
437
541
|
before do
|
|
438
542
|
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
|
439
543
|
allow(socket).to receive(:connect!)
|
|
440
544
|
allow(socket).to receive(:start_sync)
|
|
441
545
|
end
|
|
546
|
+
|
|
442
547
|
it 'instantiates the correct store class', vcr: { cassette_name: 'web/rtm_connect' } do
|
|
443
548
|
client.start!
|
|
444
549
|
expect(client.store).to be_a Slack::RealTime::Stores::Starter
|
|
@@ -446,20 +551,24 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
446
551
|
end
|
|
447
552
|
end
|
|
448
553
|
end
|
|
554
|
+
|
|
449
555
|
context 'store' do
|
|
450
556
|
before do
|
|
451
|
-
|
|
557
|
+
described_class.configure do |config|
|
|
452
558
|
config.store_class = Slack::RealTime::Stores::Store
|
|
453
559
|
end
|
|
454
560
|
end
|
|
561
|
+
|
|
455
562
|
describe '#initialize' do
|
|
456
563
|
context 'start!' do
|
|
457
564
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
565
|
+
|
|
458
566
|
before do
|
|
459
567
|
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
|
460
568
|
allow(socket).to receive(:connect!)
|
|
461
569
|
allow(socket).to receive(:start_sync)
|
|
462
570
|
end
|
|
571
|
+
|
|
463
572
|
it 'calls rtm_start and not rtm_connect', vcr: { cassette_name: 'web/rtm_start' } do
|
|
464
573
|
expect(client.web_client).to receive(:rtm_start).and_call_original
|
|
465
574
|
client.start!
|
|
@@ -468,18 +577,20 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
468
577
|
end
|
|
469
578
|
end
|
|
470
579
|
end
|
|
580
|
+
|
|
471
581
|
context 'start_method' do
|
|
472
582
|
describe '#initialize' do
|
|
473
583
|
it 'can be overriden explicitly' do
|
|
474
|
-
client =
|
|
584
|
+
client = described_class.new(start_method: :overriden)
|
|
475
585
|
expect(client.send(:start_method)).to eq :overriden
|
|
476
586
|
end
|
|
477
587
|
context 'with start_method' do
|
|
478
588
|
before do
|
|
479
|
-
|
|
589
|
+
described_class.configure do |config|
|
|
480
590
|
config.start_method = :overriden
|
|
481
591
|
end
|
|
482
592
|
end
|
|
593
|
+
|
|
483
594
|
it 'sets start_method' do
|
|
484
595
|
expect(client.send(:start_method)).to eq :overriden
|
|
485
596
|
end
|
|
@@ -490,14 +601,18 @@ RSpec.describe Slack::RealTime::Client do
|
|
|
490
601
|
end.to raise_error RuntimeError, 'overriden'
|
|
491
602
|
end
|
|
492
603
|
end
|
|
604
|
+
|
|
493
605
|
context 'start!' do
|
|
494
606
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
|
607
|
+
|
|
495
608
|
before do
|
|
496
609
|
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
|
497
610
|
allow(socket).to receive(:connect!)
|
|
498
611
|
allow(socket).to receive(:start_sync)
|
|
499
612
|
end
|
|
500
|
-
|
|
613
|
+
|
|
614
|
+
it 'defaults to :rtm_start when using full store',
|
|
615
|
+
vcr: { cassette_name: 'web/rtm_start' } do
|
|
501
616
|
expect(client.web_client).to receive(:rtm_start).and_call_original
|
|
502
617
|
client.start!
|
|
503
618
|
end
|