slack-ruby-client 0.16.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/danger.yml +19 -0
- data/.github/workflows/integtest.yml +25 -0
- data/.github/workflows/rubocop.yml +13 -0
- data/.github/workflows/test.yml +34 -0
- data/.gitignore +5 -3
- data/.rubocop.yml +6 -0
- data/.rubocop_todo.yml +137 -43
- data/CHANGELOG.md +34 -3
- data/CONTRIBUTING.md +4 -4
- data/Gemfile +18 -1
- data/Gemfile.danger +6 -0
- data/LICENSE.md +1 -1
- data/README.md +13 -12
- data/RELEASING.md +1 -1
- data/UPGRADING.md +42 -0
- data/bin/commands/admin_analytics.rb +2 -1
- data/bin/commands/admin_apps.rb +11 -0
- data/bin/commands/admin_apps_requests.rb +12 -0
- data/bin/commands/admin_auth_policy.rb +39 -0
- data/bin/commands/admin_conversations.rb +2 -1
- data/bin/commands/admin_conversations_restrictAccess.rb +1 -1
- data/bin/commands/admin_emoji.rb +2 -2
- data/bin/commands/admin_teams.rb +1 -1
- data/bin/commands/admin_users.rb +1 -0
- data/bin/commands/admin_users_session.rb +40 -0
- data/bin/commands/admin_users_unsupportedVersions.rb +15 -0
- data/bin/commands/apps_manifest.rb +52 -0
- data/bin/commands/bookmarks.rb +52 -0
- data/bin/commands/channels.rb +0 -157
- data/bin/commands/chat.rb +14 -9
- data/bin/commands/conversations.rb +61 -4
- data/bin/commands/dnd.rb +3 -1
- data/bin/commands/files.rb +2 -1
- data/bin/commands/groups.rb +0 -163
- data/bin/commands/im.rb +0 -62
- data/bin/commands/mpim.rb +0 -60
- data/bin/commands/oauth.rb +0 -13
- data/bin/commands/oauth_v2.rb +13 -1
- data/bin/commands/openid_connect.rb +27 -0
- data/bin/commands/pins.rb +2 -2
- data/bin/commands/reminders.rb +6 -0
- data/bin/commands/rtm.rb +2 -2
- data/bin/commands/search.rb +2 -1
- data/bin/commands/stars.rb +7 -6
- data/bin/commands/team.rb +1 -0
- data/bin/commands/team_billing.rb +13 -0
- data/bin/commands/team_preferences.rb +13 -0
- data/bin/commands/tooling_tokens.rb +14 -0
- data/bin/commands/usergroups.rb +1 -1
- data/bin/commands/users.rb +1 -1
- data/bin/commands/views.rb +1 -1
- data/bin/commands.rb +8 -9
- data/lib/slack/config.rb +1 -2
- data/lib/slack/events/request.rb +5 -3
- data/lib/slack/real_time/client.rb +6 -7
- data/lib/slack/real_time/concurrency/async.rb +6 -8
- data/lib/slack/real_time/config.rb +3 -13
- data/lib/slack/real_time/socket.rb +1 -2
- data/lib/slack/real_time/stores/base.rb +1 -6
- data/lib/slack/real_time/stores/starter.rb +6 -3
- data/lib/slack/real_time/stores/store.rb +5 -0
- data/lib/slack/version.rb +1 -1
- data/lib/slack/web/api/endpoints/admin_analytics.rb +5 -3
- data/lib/slack/web/api/endpoints/admin_apps.rb +21 -5
- data/lib/slack/web/api/endpoints/admin_apps_approved.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_apps_requests.rb +20 -2
- data/lib/slack/web/api/endpoints/admin_apps_restricted.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_auth_policy.rb +72 -0
- data/lib/slack/web/api/endpoints/admin_barriers.rb +6 -6
- data/lib/slack/web/api/endpoints/admin_conversations.rb +28 -26
- data/lib/slack/web/api/endpoints/admin_conversations_ekm.rb +4 -4
- data/lib/slack/web/api/endpoints/admin_emoji.rb +11 -11
- data/lib/slack/web/api/endpoints/admin_inviteRequests.rb +7 -7
- data/lib/slack/web/api/endpoints/admin_inviteRequests_approved.rb +3 -3
- data/lib/slack/web/api/endpoints/admin_inviteRequests_denied.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_teams.rb +7 -7
- data/lib/slack/web/api/endpoints/admin_teams_admins.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_teams_owners.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_teams_settings.rb +5 -5
- data/lib/slack/web/api/endpoints/admin_usergroups.rb +10 -10
- data/lib/slack/web/api/endpoints/admin_users.rb +20 -18
- data/lib/slack/web/api/endpoints/admin_users_session.rb +65 -9
- data/lib/slack/web/api/endpoints/admin_users_unsupportedVersions.rb +25 -0
- data/lib/slack/web/api/endpoints/api.rb +1 -1
- data/lib/slack/web/api/endpoints/apps.rb +2 -2
- data/lib/slack/web/api/endpoints/apps_event_authorizations.rb +3 -3
- data/lib/slack/web/api/endpoints/apps_manifest.rb +77 -0
- data/lib/slack/web/api/endpoints/auth.rb +1 -1
- data/lib/slack/web/api/endpoints/auth_teams.rb +3 -3
- data/lib/slack/web/api/endpoints/bookmarks.rb +86 -0
- data/lib/slack/web/api/endpoints/bots.rb +2 -2
- data/lib/slack/web/api/endpoints/calls.rb +15 -15
- data/lib/slack/web/api/endpoints/calls_participants.rb +4 -4
- data/lib/slack/web/api/endpoints/channels.rb +0 -265
- data/lib/slack/web/api/endpoints/chat.rb +67 -57
- data/lib/slack/web/api/endpoints/chat_scheduledMessages.rb +3 -3
- data/lib/slack/web/api/endpoints/conversations.rb +117 -27
- data/lib/slack/web/api/endpoints/dialog.rb +2 -2
- data/lib/slack/web/api/endpoints/dnd.rb +6 -3
- data/lib/slack/web/api/endpoints/files.rb +16 -14
- data/lib/slack/web/api/endpoints/files_comments.rb +1 -1
- data/lib/slack/web/api/endpoints/files_remote.rb +20 -20
- data/lib/slack/web/api/endpoints/groups.rb +0 -273
- data/lib/slack/web/api/endpoints/im.rb +0 -107
- data/lib/slack/web/api/endpoints/migration.rb +3 -3
- data/lib/slack/web/api/endpoints/mpim.rb +0 -102
- data/lib/slack/web/api/endpoints/oauth.rb +5 -27
- data/lib/slack/web/api/endpoints/oauth_v2.rb +24 -6
- data/lib/slack/web/api/endpoints/openid_connect.rb +42 -0
- data/lib/slack/web/api/endpoints/pins.rb +4 -4
- data/lib/slack/web/api/endpoints/reactions.rb +12 -12
- data/lib/slack/web/api/endpoints/reminders.rb +17 -5
- data/lib/slack/web/api/endpoints/rtm.rb +10 -10
- data/lib/slack/web/api/endpoints/search.rb +24 -16
- data/lib/slack/web/api/endpoints/stars.rb +11 -9
- data/lib/slack/web/api/endpoints/team.rb +10 -8
- data/lib/slack/web/api/endpoints/team_billing.rb +21 -0
- data/lib/slack/web/api/endpoints/team_preferences.rb +21 -0
- data/lib/slack/web/api/endpoints/team_profile.rb +1 -1
- data/lib/slack/web/api/endpoints/tooling_tokens.rb +24 -0
- data/lib/slack/web/api/endpoints/usergroups.rb +19 -19
- data/lib/slack/web/api/endpoints/usergroups_users.rb +7 -7
- data/lib/slack/web/api/endpoints/users.rb +16 -16
- data/lib/slack/web/api/endpoints/users_profile.rb +4 -4
- data/lib/slack/web/api/endpoints/views.rb +12 -12
- data/lib/slack/web/api/endpoints/workflows.rb +9 -9
- data/lib/slack/web/api/endpoints.rb +16 -20
- data/lib/slack/web/api/errors/server_error.rb +37 -0
- data/lib/slack/web/api/errors/too_many_requests_error.rb +1 -4
- data/lib/slack/web/api/errors.rb +232 -16
- data/lib/slack/web/api/mixins.rb +0 -2
- data/lib/slack/web/api/patches/chat.1.patch +7 -9
- data/lib/slack/web/api/templates/endpoints.erb +0 -2
- data/lib/slack/web/faraday/connection.rb +5 -5
- data/lib/slack/web/faraday/request.rb +4 -1
- data/lib/slack/web/faraday/response/raise_error.rb +2 -14
- data/lib/slack/web/faraday/response/wrap_error.rb +11 -5
- data/lib/slack/web/pagination/cursor.rb +1 -5
- data/lib/slack-ruby-client.rb +3 -2
- data/lib/tasks/real_time.rake +1 -3
- data/lib/tasks/web.rake +4 -0
- data/slack-ruby-client.gemspec +5 -14
- data/spec/fixtures/slack/web/429_error.yml +50 -54
- data/spec/fixtures/slack/web/auth_test_error.yml +51 -18
- data/spec/fixtures/slack/web/auth_test_success.yml +50 -26
- data/spec/fixtures/slack/web/conversations_info.yml +167 -0
- data/spec/fixtures/slack/web/conversations_setTopic.yml +42 -27
- data/spec/fixtures/slack/web/conversations_setTopic_one_page.yml +89 -59
- data/spec/fixtures/slack/web/conversations_setTopic_paginated.yml +131 -86
- data/spec/fixtures/slack/web/paginated_users_list.yml +501 -69
- data/spec/fixtures/slack/web/rtm_connect.yml +267 -30
- data/spec/fixtures/slack/web/rtm_start.yml +771 -60
- data/spec/fixtures/slack/web/users_info.yml +153 -69
- data/spec/fixtures/slack/web/users_list.yml +102 -41
- data/spec/fixtures/slack/web/views_open_error.yml +49 -42
- data/spec/integration/integration_spec.rb +1 -1
- data/spec/slack/events/request_spec.rb +7 -6
- data/spec/slack/real_time/client_spec.rb +37 -39
- data/spec/slack/real_time/concurrency/with_concurrency_spec.rb +10 -0
- data/spec/slack/real_time/concurrency/without_concurrency_spec.rb +10 -0
- data/spec/slack/real_time/event_handlers/bot_spec.rb +1 -1
- data/spec/slack/real_time/event_handlers/channel_spec.rb +9 -9
- data/spec/slack/real_time/event_handlers/group_spec.rb +2 -2
- data/spec/slack/real_time/event_handlers/im_spec.rb +7 -7
- data/spec/slack/real_time/event_handlers/user_spec.rb +2 -2
- data/spec/slack/real_time/rtm_connect_spec.rb +1 -1
- data/spec/slack/real_time/rtm_start_spec.rb +1 -1
- data/spec/slack/real_time/store_spec.rb +2 -2
- data/spec/slack/slack_spec.rb +7 -5
- data/spec/slack/version_spec.rb +1 -1
- data/spec/slack/web/api/endpoints/admin_apps_requests_spec.rb +5 -0
- data/spec/slack/web/api/endpoints/admin_apps_spec.rb +5 -0
- data/spec/slack/web/api/endpoints/admin_auth_policy_spec.rb +35 -0
- data/spec/slack/web/api/endpoints/admin_conversations_spec.rb +9 -9
- data/spec/slack/web/api/endpoints/admin_teams_settings_spec.rb +1 -1
- data/spec/slack/web/api/endpoints/admin_usergroups_spec.rb +6 -6
- data/spec/slack/web/api/endpoints/admin_users_session_spec.rb +22 -2
- data/spec/slack/web/api/endpoints/admin_users_spec.rb +8 -8
- data/spec/slack/web/api/endpoints/admin_users_unsupportedVersions_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/apps_manifest_spec.rb +36 -0
- data/spec/slack/web/api/endpoints/apps_spec.rb +2 -2
- data/spec/slack/web/api/endpoints/bookmarks_spec.rb +40 -0
- data/spec/slack/web/api/endpoints/calls_participants_spec.rb +4 -4
- data/spec/slack/web/api/endpoints/calls_spec.rb +2 -2
- data/spec/slack/web/api/endpoints/custom_specs/auth_spec.rb +4 -6
- data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +28 -16
- data/spec/slack/web/api/endpoints/custom_specs/conversations_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +4 -2
- data/spec/slack/web/api/endpoints/custom_specs/users_spec.rb +2 -2
- data/spec/slack/web/api/endpoints/custom_specs/views_spec.rb +22 -14
- data/spec/slack/web/api/endpoints/dnd_spec.rb +0 -5
- data/spec/slack/web/api/endpoints/files_comments_spec.rb +2 -2
- data/spec/slack/web/api/endpoints/files_remote_spec.rb +3 -3
- data/spec/slack/web/api/endpoints/oauth_spec.rb +0 -11
- data/spec/slack/web/api/endpoints/oauth_v2_spec.rb +6 -3
- data/spec/slack/web/api/endpoints/{apps_permissions_scopes_spec.rb → openid_connect_spec.rb} +1 -1
- data/spec/slack/web/api/endpoints/reactions_spec.rb +3 -3
- data/spec/slack/web/api/endpoints/reminders_spec.rb +2 -2
- data/spec/slack/web/api/endpoints/{apps_permissions_resources_spec.rb → team_billing_spec.rb} +1 -1
- data/spec/slack/web/api/endpoints/team_preferences_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/tooling_tokens_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/usergroups_users_spec.rb +2 -2
- data/spec/slack/web/api/error_spec.rb +5 -7
- data/spec/slack/web/api/errors/slack_error_spec.rb +21 -26
- data/spec/slack/web/api/mixins/conversations_list_spec.rb +1 -1
- data/spec/slack/web/api/pagination/cursor_spec.rb +8 -10
- data/spec/slack/web/client_spec.rb +46 -32
- data/spec/slack/web/faraday/request_spec.rb +80 -0
- data/spec/slack/web/faraday/response/raise_error_spec.rb +2 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/support/real_time/connected_client.rb +2 -8
- data/spec/support/vcr.rb +33 -2
- metadata +50 -297
- data/.travis.yml +0 -28
- data/lib/slack/web/api/errors/internal_error.rb +0 -14
- data/lib/slack/web/api/mixins/channels.id.json +0 -20
- data/lib/slack/web/api/mixins/channels.id.rb +0 -25
- data/lib/slack/web/api/mixins/groups.id.json +0 -20
- data/lib/slack/web/api/mixins/groups.id.rb +0 -25
- data/spec/fixtures/slack/web/503_error.yml +0 -14
- data/spec/fixtures/slack/web/channels_info.yml +0 -139
- data/spec/fixtures/slack/web/groups_info.yml +0 -43
- data/spec/slack/web/api/endpoints/admin_conversations_whitelist_spec.rb +0 -32
- data/spec/slack/web/api/endpoints/apps_permissions_spec.rb +0 -16
- data/spec/slack/web/api/endpoints/apps_permissions_users_spec.rb +0 -19
- data/spec/slack/web/api/endpoints/conversations_spec.rb +0 -109
- data/spec/slack/web/api/endpoints/custom_specs/channels_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/custom_specs/groups_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/im_spec.rb +0 -39
- data/spec/slack/web/api/endpoints/mpim_spec.rb +0 -39
- data/spec/slack/web/api/endpoints/views_spec.rb +0 -29
- data/spec/slack/web/api/mixins/channels_spec.rb +0 -43
- data/spec/slack/web/api/mixins/groups_spec.rb +0 -43
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# This file was auto-generated by lib/tasks/web.rake
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
RSpec.describe Slack::Web::Api::Endpoints::ToolingTokens do
|
7
|
+
let(:client) { Slack::Web::Client.new }
|
8
|
+
context 'tooling.tokens_rotate' do
|
9
|
+
it 'requires refresh_token' do
|
10
|
+
expect { client.tooling_tokens_rotate }.to raise_error ArgumentError, /Required arguments :refresh_token missing/
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -12,10 +12,10 @@ RSpec.describe Slack::Web::Api::Endpoints::UsergroupsUsers do
|
|
12
12
|
end
|
13
13
|
context 'usergroups.users_update' do
|
14
14
|
it 'requires usergroup' do
|
15
|
-
expect { client.usergroups_users_update(users: %q[
|
15
|
+
expect { client.usergroups_users_update(users: %q[]) }.to raise_error ArgumentError, /Required arguments :usergroup missing/
|
16
16
|
end
|
17
17
|
it 'requires users' do
|
18
|
-
expect { client.usergroups_users_update(usergroup: %q[
|
18
|
+
expect { client.usergroups_users_update(usergroup: %q[]) }.to raise_error ArgumentError, /Required arguments :users missing/
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -5,12 +5,10 @@ RSpec.describe Slack::Web::Api::Error do
|
|
5
5
|
let(:client) { Slack::Web::Client.new }
|
6
6
|
|
7
7
|
it 'provides access to the response object', vcr: { cassette_name: 'web/auth_test_error' } do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
expect(e.response.status).to eq 200
|
14
|
-
end
|
8
|
+
client.auth_test
|
9
|
+
raise 'Expected to receive Slack::Web::Api::Error.'
|
10
|
+
rescue described_class => e
|
11
|
+
expect(e.response).not_to be_nil
|
12
|
+
expect(e.response.status).to eq 200
|
15
13
|
end
|
16
14
|
end
|
@@ -5,34 +5,29 @@ RSpec.describe Slack::Web::Api::Errors::SlackError do
|
|
5
5
|
let(:client) { Slack::Web::Client.new }
|
6
6
|
|
7
7
|
it 'provides access to the response object', vcr: { cassette_name: 'web/auth_test_error' } do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
expect(e.response_metadata).to be_nil
|
17
|
-
end
|
8
|
+
client.auth_test
|
9
|
+
raise 'Expected to receive Slack::Web::Api::Errors::SlackError.'
|
10
|
+
rescue described_class => e
|
11
|
+
expect(e.response).not_to be_nil
|
12
|
+
expect(e.response.status).to eq 200
|
13
|
+
expect(e.message).to eql 'not_authed'
|
14
|
+
expect(e.error).to eql 'not_authed'
|
15
|
+
expect(e.response_metadata).to be_nil
|
18
16
|
end
|
19
17
|
|
20
18
|
it 'provides access to any response_metadata', vcr: { cassette_name: 'web/views_open_error' } do
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
'
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
]
|
35
|
-
)
|
36
|
-
end
|
19
|
+
client.views_open(trigger_id: 'trigger_id', view: {})
|
20
|
+
raise 'Expected to receive Slack::Web::Api::Errors::SlackError.'
|
21
|
+
rescue described_class => e
|
22
|
+
expect(e.response).not_to be_nil
|
23
|
+
expect(e.response.status).to eq 200
|
24
|
+
expect(e.message).to eql 'invalid_arguments'
|
25
|
+
expect(e.error).to eql 'invalid_arguments'
|
26
|
+
expect(e.response_metadata).to eq(
|
27
|
+
'messages' => [
|
28
|
+
'[ERROR] failed to match all allowed schemas [json-pointer:/view]',
|
29
|
+
'[ERROR] missing required field: type [json-pointer:/view]'
|
30
|
+
]
|
31
|
+
)
|
37
32
|
end
|
38
33
|
end
|
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
RSpec.describe Slack::Web::Client do
|
5
5
|
context 'conversations_setTopic' do
|
6
6
|
it 'does not invoke conversations_list', vcr: { cassette_name: 'web/conversations_setTopic' } do
|
7
|
-
rc = subject.conversations_setTopic({ channel: '
|
7
|
+
rc = subject.conversations_setTopic({ channel: 'C019CV63UTC', topic: 'new topic' })
|
8
8
|
expect(rc.channel.topic.value).to eq 'new topic'
|
9
9
|
end
|
10
10
|
|
@@ -8,7 +8,7 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
|
|
8
8
|
let(:cursor) { described_class.new(client, 'users_list', {}) }
|
9
9
|
|
10
10
|
it 'provides a default limit' do
|
11
|
-
expect(client).to receive(:users_list).with(limit: 100, cursor: nil)
|
11
|
+
expect(client).to receive(:users_list).with({ limit: 100, cursor: nil })
|
12
12
|
cursor.first
|
13
13
|
end
|
14
14
|
it 'handles blank response metadata' do
|
@@ -30,24 +30,23 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
|
|
30
30
|
cursor.to_a
|
31
31
|
end
|
32
32
|
context 'with rate limiting' do
|
33
|
-
let(:error) { Slack::Web::Api::Errors::TooManyRequestsError.new(
|
33
|
+
let(:error) { Slack::Web::Api::Errors::TooManyRequestsError.new(OpenStruct.new(headers: { 'retry-after' => 9 })) }
|
34
34
|
|
35
35
|
context 'with default max retries' do
|
36
36
|
it 'sleeps after a TooManyRequestsError' do
|
37
37
|
expect(client).to(
|
38
38
|
receive(:users_list)
|
39
|
-
.with(limit: 100, cursor: nil)
|
39
|
+
.with({ limit: 100, cursor: nil })
|
40
40
|
.ordered
|
41
41
|
.and_return(Slack::Messages::Message.new(response_metadata: { next_cursor: 'next' }))
|
42
42
|
)
|
43
43
|
expect(client).to(
|
44
|
-
receive(:users_list).with(limit: 100, cursor: 'next').ordered.and_raise(error)
|
44
|
+
receive(:users_list).with({ limit: 100, cursor: 'next' }).ordered.and_raise(error)
|
45
45
|
)
|
46
|
-
expect(error).to receive(:retry_after).once.ordered.and_return(9)
|
47
46
|
expect(cursor).to receive(:sleep).once.ordered.with(9)
|
48
47
|
expect(client).to(
|
49
48
|
receive(:users_list)
|
50
|
-
.with(limit: 100, cursor: 'next')
|
49
|
+
.with({ limit: 100, cursor: 'next' })
|
51
50
|
.ordered
|
52
51
|
.and_return(Slack::Messages::Message.new)
|
53
52
|
)
|
@@ -61,13 +60,12 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
|
|
61
60
|
it 'raises the error after hitting the max retries' do
|
62
61
|
expect(client).to(
|
63
62
|
receive(:users_list)
|
64
|
-
.with(limit: 100, cursor: nil)
|
63
|
+
.with({ limit: 100, cursor: nil })
|
65
64
|
.and_return(Slack::Messages::Message.new(response_metadata: { next_cursor: 'next' }))
|
66
65
|
)
|
67
66
|
expect(client).to(
|
68
|
-
receive(:users_list).with(limit: 100, cursor: 'next').exactly(5).times.and_raise(error)
|
67
|
+
receive(:users_list).with({ limit: 100, cursor: 'next' }).exactly(5).times.and_raise(error)
|
69
68
|
)
|
70
|
-
expect(error).to receive(:retry_after).exactly(4).times.and_return(9)
|
71
69
|
expect(cursor).to receive(:sleep).exactly(4).times.with(9)
|
72
70
|
expect { cursor.to_a }.to raise_error(error)
|
73
71
|
end
|
@@ -79,7 +77,7 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
|
|
79
77
|
let(:cursor) { described_class.new(client, 'users_list', limit: 42) }
|
80
78
|
|
81
79
|
it 'overrides default limit' do
|
82
|
-
expect(client).to receive(:users_list).with(limit: 42, cursor: nil)
|
80
|
+
expect(client).to receive(:users_list).with({ limit: 42, cursor: nil })
|
83
81
|
cursor.first
|
84
82
|
end
|
85
83
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'spec_helper'
|
3
|
+
require 'faraday/typhoeus'
|
3
4
|
|
4
5
|
RSpec.describe Slack::Web::Client do
|
5
6
|
before do
|
@@ -226,7 +227,10 @@ RSpec.describe Slack::Web::Client do
|
|
226
227
|
request = nil
|
227
228
|
response = conn.post do |r|
|
228
229
|
r.path = 'rtm.start'
|
229
|
-
r.
|
230
|
+
r.headers = {
|
231
|
+
'Accept' => ['application/json; charset=utf-8'],
|
232
|
+
'Authorization' => ['Bearer <SLACK_API_TOKEN>']
|
233
|
+
}
|
230
234
|
request = r
|
231
235
|
end
|
232
236
|
|
@@ -250,21 +254,6 @@ RSpec.describe Slack::Web::Client do
|
|
250
254
|
end
|
251
255
|
end
|
252
256
|
|
253
|
-
context 'when calling deprecated methods' do
|
254
|
-
let(:client) { described_class.new }
|
255
|
-
|
256
|
-
it 'produces a warning' do
|
257
|
-
expect(client.logger).to receive(:warn).with(/
|
258
|
-
^channels\.archive:\ This\ method\ is\ deprecated
|
259
|
-
.+
|
260
|
-
Alternative\ methods:\ conversations\.archive\.
|
261
|
-
/x)
|
262
|
-
|
263
|
-
expect(client).to receive(:post)
|
264
|
-
client.channels_archive(channel: 'test')
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
257
|
context 'persistent capability' do
|
269
258
|
describe '#initialize' do
|
270
259
|
it 'caches the Faraday connection to allow persistent adapters' do
|
@@ -281,21 +270,34 @@ RSpec.describe Slack::Web::Client do
|
|
281
270
|
|
282
271
|
let(:stub_slack_request) { stub_request(:post, 'https://slack.com/api/api.test') }
|
283
272
|
let(:exception) do
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
return e
|
288
|
-
end
|
273
|
+
request
|
274
|
+
rescue Slack::Web::Api::Errors::ServerError => e
|
275
|
+
return e
|
289
276
|
end
|
290
277
|
|
291
278
|
context 'parsing error' do
|
292
|
-
|
279
|
+
context 'when the response is not JSON' do
|
280
|
+
before do
|
281
|
+
stub_slack_request.to_return(body: '<html></html>', headers: { 'Content-Type' => 'text/html' })
|
282
|
+
end
|
293
283
|
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
284
|
+
it 'raises ParsingError' do
|
285
|
+
expect { request }.to raise_error(Slack::Web::Api::Errors::ParsingError).with_message('parsing_error')
|
286
|
+
expect(exception.response.body).to eq('<html></html>')
|
287
|
+
expect(exception.cause).to be_a(Faraday::ParsingError)
|
288
|
+
expect(exception.cause.cause).to be_a(JSON::ParserError)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
context 'when the response is malformed JSON' do
|
293
|
+
before { stub_slack_request.to_return(body: '{') }
|
294
|
+
|
295
|
+
it 'raises ParsingError' do
|
296
|
+
expect { request }.to raise_error(Slack::Web::Api::Errors::ParsingError).with_message('parsing_error')
|
297
|
+
expect(exception.response.body).to eq('{')
|
298
|
+
expect(exception.cause).to be_a(Faraday::ParsingError)
|
299
|
+
expect(exception.cause.cause).to be_a(JSON::ParserError)
|
300
|
+
end
|
299
301
|
end
|
300
302
|
end
|
301
303
|
|
@@ -322,12 +324,24 @@ RSpec.describe Slack::Web::Client do
|
|
322
324
|
end
|
323
325
|
|
324
326
|
context '5xx response' do
|
325
|
-
|
327
|
+
context 'with a JSON body' do
|
328
|
+
before { stub_slack_request.to_return(status: 500, body: '{}') }
|
329
|
+
|
330
|
+
it 'raises UnavailableError' do
|
331
|
+
expect { request }.to raise_error(Slack::Web::Api::Errors::UnavailableError).with_message('unavailable_error')
|
332
|
+
expect(exception.response.status).to eq(500)
|
333
|
+
end
|
334
|
+
end
|
326
335
|
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
336
|
+
context 'with a HTML response' do
|
337
|
+
before do
|
338
|
+
stub_slack_request.to_return(status: 500, body: '<html></html>', headers: { 'Content-Type' => 'text/html' })
|
339
|
+
end
|
340
|
+
|
341
|
+
it 'raises UnavailableError' do
|
342
|
+
expect { request }.to raise_error(Slack::Web::Api::Errors::UnavailableError).with_message('unavailable_error')
|
343
|
+
expect(exception.response.status).to eq(500)
|
344
|
+
end
|
331
345
|
end
|
332
346
|
end
|
333
347
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
class DummyClient
|
5
|
+
include Slack::Web::Faraday::Connection
|
6
|
+
include Slack::Web::Faraday::Request
|
7
|
+
|
8
|
+
attr_reader :token
|
9
|
+
|
10
|
+
def initialize(token)
|
11
|
+
@token = token
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
RSpec.describe Slack::Web::Faraday::Request do
|
16
|
+
let(:token) { 'by-the-power-of-grayskull' }
|
17
|
+
let(:client) { DummyClient.new(token) }
|
18
|
+
|
19
|
+
before do
|
20
|
+
Slack::Config.reset
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'authorization' do
|
24
|
+
let(:path) { '/any-path' }
|
25
|
+
let(:options) { {} }
|
26
|
+
let(:connection) { instance_double('Faraday::Connection') }
|
27
|
+
let(:request) { instance_double('Faraday::Request') }
|
28
|
+
let(:headers) { instance_double('Faraday::Utils::Headers') }
|
29
|
+
let(:response) { instance_double('Faraday::Response', body: '') }
|
30
|
+
|
31
|
+
before do
|
32
|
+
allow(client).to receive(:connection).and_return(connection)
|
33
|
+
allow(request).to receive(:url).with(path, options)
|
34
|
+
allow(request).to receive(:path=).with(path)
|
35
|
+
allow(request).to receive(:headers).and_return(headers)
|
36
|
+
allow(connection).to receive(:send)
|
37
|
+
.with(method).and_yield(request).and_return(response)
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#get' do
|
41
|
+
let(:method) { :get }
|
42
|
+
|
43
|
+
it 'sets authorization header' do
|
44
|
+
expect(headers).to receive(:[]=)
|
45
|
+
.with('Authorization', "Bearer #{token}")
|
46
|
+
client.send(method, path, options)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#post' do
|
51
|
+
let(:method) { :post }
|
52
|
+
|
53
|
+
it 'sets authorization header' do
|
54
|
+
expect(headers).to receive(:[]=)
|
55
|
+
.with('Authorization', "Bearer #{token}")
|
56
|
+
client.send(method, path, options)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#put' do
|
61
|
+
let(:method) { :put }
|
62
|
+
|
63
|
+
it 'sets authorization header' do
|
64
|
+
expect(headers).to receive(:[]=)
|
65
|
+
.with('Authorization', "Bearer #{token}")
|
66
|
+
client.send(method, path, options)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#delete' do
|
71
|
+
let(:method) { :delete }
|
72
|
+
|
73
|
+
it 'sets authorization header' do
|
74
|
+
expect(headers).to receive(:[]=)
|
75
|
+
.with('Authorization', "Bearer #{token}")
|
76
|
+
client.send(method, path, options)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -13,6 +13,7 @@ RSpec.describe Slack::Web::Faraday::Response::RaiseError do
|
|
13
13
|
describe '#on_complete' do
|
14
14
|
context 'with status of 429' do
|
15
15
|
let(:status) { 429 }
|
16
|
+
let(:response) { OpenStruct.new(headers: { 'retry-after' => 10 }) }
|
16
17
|
|
17
18
|
it 'raises a TooManyRequestsError' do
|
18
19
|
expect { raise_error_obj.on_complete(env) }.to(
|
@@ -25,7 +26,7 @@ RSpec.describe Slack::Web::Faraday::Response::RaiseError do
|
|
25
26
|
let(:body) { { 'ok' => 'true' } }
|
26
27
|
|
27
28
|
it 'is nil' do
|
28
|
-
expect(raise_error_obj.on_complete(env)).to
|
29
|
+
expect(raise_error_obj.on_complete(env)).to be_nil
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
data/spec/spec_helper.rb
CHANGED
@@ -12,7 +12,7 @@ Dir[File.join(File.dirname(__FILE__), 'support', '**/*.rb')].each do |file|
|
|
12
12
|
end
|
13
13
|
|
14
14
|
Slack.configure do |config|
|
15
|
-
config.token = ENV['SLACK_API_TOKEN']
|
15
|
+
config.token = '<SLACK_API_TOKEN>' # ENV['SLACK_API_TOKEN']
|
16
16
|
end
|
17
17
|
|
18
18
|
RSpec.configure do |config|
|
@@ -2,13 +2,7 @@
|
|
2
2
|
RSpec.shared_context 'connected client' do |opts|
|
3
3
|
let(:client) { Slack::RealTime::Client.new(opts || {}) }
|
4
4
|
let(:ws) { double(Slack::RealTime::Concurrency::Mock::WebSocket) }
|
5
|
-
let(:url)
|
6
|
-
if Slack::RealTime.config.store_class == Slack::RealTime::Stores::Store
|
7
|
-
'wss://ms173.slack-msgs.com/websocket/lqcUiAvrKTP-uuid='
|
8
|
-
else
|
9
|
-
'wss://mpmulti-w5tz.slack-msgs.com/websocket/uid'
|
10
|
-
end
|
11
|
-
end
|
5
|
+
let(:url) { 'wss://cerberus-xxxx.lb.slack-msgs.com/websocket/uid' }
|
12
6
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
13
7
|
|
14
8
|
before do
|
@@ -17,7 +11,7 @@ RSpec.shared_context 'connected client' do |opts|
|
|
17
11
|
config.store_class = (opts || {})[:store_class] || Slack::RealTime::Stores::Store
|
18
12
|
end
|
19
13
|
allow(Slack::RealTime::Socket).to(
|
20
|
-
receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
|
14
|
+
receive(:new).with(url, { ping: 30, logger: Slack::Logger.default }).and_return(socket)
|
21
15
|
)
|
22
16
|
allow(socket).to receive(:start_sync)
|
23
17
|
allow(socket).to receive(:connect!)
|
data/spec/support/vcr.rb
CHANGED
@@ -5,10 +5,41 @@ require 'webmock/rspec'
|
|
5
5
|
VCR.configure do |config|
|
6
6
|
config.cassette_library_dir = 'spec/fixtures/slack'
|
7
7
|
config.hook_into :webmock
|
8
|
-
# config.default_cassette_options = { record: :new_episodes }
|
9
8
|
config.configure_rspec_metadata!
|
9
|
+
if ENV.key?('SLACK_API_TOKEN')
|
10
|
+
config.filter_sensitive_data('<SLACK_API_TOKEN>') do
|
11
|
+
ENV['SLACK_API_TOKEN']
|
12
|
+
end
|
13
|
+
end
|
10
14
|
config.before_record do |i|
|
11
|
-
i.request.body.gsub!(ENV['SLACK_API_TOKEN'], 'token') if ENV.key?('SLACK_API_TOKEN')
|
12
15
|
i.response.body.force_encoding('UTF-8')
|
13
16
|
end
|
17
|
+
config.register_request_matcher :client_headers do |recorded, actual|
|
18
|
+
authorizations = ENV.key?('SLACK_API_TOKEN') ? actual.headers['Authorization'].map do |auth|
|
19
|
+
auth.gsub(ENV['SLACK_API_TOKEN'], '<SLACK_API_TOKEN>')
|
20
|
+
end : actual.headers['Authorization']
|
21
|
+
actual.headers['Accept'] == recorded.headers['Accept'] &&
|
22
|
+
authorizations == recorded.headers['Authorization']
|
23
|
+
end
|
24
|
+
config.default_cassette_options = {
|
25
|
+
match_requests_on: %i[method uri body client_headers]
|
26
|
+
# record: :new_episodes
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
module VCR
|
31
|
+
module Errors
|
32
|
+
class UnhandledHTTPRequestError
|
33
|
+
private
|
34
|
+
|
35
|
+
# Force unhandled HTTP error reports to include the headers
|
36
|
+
# for our custom matcher `client_headers`.
|
37
|
+
#
|
38
|
+
# This patch can be removed if https://github.com/vcr/vcr/issues/912
|
39
|
+
# is ever resolved.
|
40
|
+
def match_request_on_headers?
|
41
|
+
true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
14
45
|
end
|