slack-ruby-client 1.0.0 → 2.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/FUNDING.yml +1 -0
- data/.github/workflows/integration_test.yml +45 -0
- data/.github/workflows/lint.yml +14 -0
- data/.github/workflows/pr_lint.yml +21 -0
- data/.github/workflows/test.yml +37 -0
- data/.gitignore +4 -3
- data/.rubocop.yml +6 -1
- data/.rubocop_todo.yml +88 -34
- data/.ruby-version +1 -0
- data/CHANGELOG.md +36 -0
- data/CONTRIBUTING.md +6 -5
- data/Gemfile +13 -1
- data/Gemfile.danger +6 -0
- data/README.md +78 -76
- data/RELEASING.md +2 -2
- data/SECURITY.md +9 -0
- data/UPGRADING.md +28 -0
- data/bin/commands/admin_analytics.rb +16 -10
- data/bin/commands/admin_apps.rb +48 -42
- data/bin/commands/admin_apps_approved.rb +17 -11
- data/bin/commands/admin_apps_requests.rb +28 -11
- data/bin/commands/admin_apps_restricted.rb +17 -11
- data/bin/commands/admin_audit_anomaly_allow.rb +29 -0
- data/bin/commands/admin_auth_policy.rb +37 -31
- data/bin/commands/admin_barriers.rb +44 -38
- data/bin/commands/admin_conversations.rb +221 -163
- data/bin/commands/admin_conversations_ekm.rb +17 -11
- data/bin/commands/admin_conversations_restrictAccess.rb +35 -29
- data/bin/commands/admin_emoji.rb +50 -44
- data/bin/commands/admin_inviteRequests.rb +34 -28
- data/bin/commands/admin_inviteRequests_approved.rb +16 -10
- data/bin/commands/admin_inviteRequests_denied.rb +16 -10
- data/bin/commands/admin_roles.rb +46 -0
- data/bin/commands/admin_teams.rb +26 -20
- data/bin/commands/admin_teams_admins.rb +16 -10
- data/bin/commands/admin_teams_owners.rb +16 -10
- data/bin/commands/admin_teams_settings.rb +59 -53
- data/bin/commands/admin_usergroups.rb +45 -39
- data/bin/commands/admin_users.rb +91 -85
- data/bin/commands/admin_users_session.rb +72 -66
- data/bin/commands/admin_users_unsupportedVersions.rb +21 -0
- data/bin/commands/api.rb +14 -8
- data/bin/commands/apps.rb +15 -9
- data/bin/commands/apps_connections.rb +13 -7
- data/bin/commands/apps_event_authorizations.rb +16 -10
- data/bin/commands/apps_manifest.rb +48 -41
- data/bin/commands/auth.rb +21 -15
- data/bin/commands/auth_teams.rb +16 -10
- data/bin/commands/bookmarks.rb +59 -0
- data/bin/commands/bots.rb +15 -9
- data/bin/commands/calls.rb +49 -43
- data/bin/commands/calls_participants.rb +24 -18
- data/bin/commands/chat.rb +150 -141
- data/bin/commands/chat_scheduledMessages.rb +19 -13
- data/bin/commands/conversations.rb +233 -225
- data/bin/commands/dialog.rb +15 -9
- data/bin/commands/dnd.rb +46 -40
- data/bin/commands/emoji.rb +14 -7
- data/bin/commands/files.rb +112 -83
- data/bin/commands/files_comments.rb +15 -9
- data/bin/commands/files_remote.rb +73 -67
- data/bin/commands/functions_workflows_steps.rb +22 -0
- data/bin/commands/functions_workflows_steps_responses.rb +22 -0
- data/bin/commands/migration.rb +16 -10
- data/bin/commands/oauth.rb +18 -12
- data/bin/commands/oauth_v2.rb +28 -22
- data/bin/commands/openid_connect.rb +26 -20
- data/bin/commands/pins.rb +33 -26
- data/bin/commands/reactions.rb +52 -46
- data/bin/commands/reminders.rb +53 -47
- data/bin/commands/rtm.rb +15 -24
- data/bin/commands/search.rb +43 -37
- data/bin/commands/stars.rb +38 -32
- data/bin/commands/team.rb +47 -38
- data/bin/commands/team_billing.rb +13 -7
- data/bin/commands/team_preferences.rb +13 -7
- data/bin/commands/team_profile.rb +14 -8
- data/bin/commands/tooling_tokens.rb +14 -8
- data/bin/commands/usergroups.rb +64 -58
- data/bin/commands/usergroups_users.rb +27 -21
- data/bin/commands/users.rb +111 -105
- data/bin/commands/users_admin.rb +28 -22
- data/bin/commands/users_prefs.rb +13 -7
- data/bin/commands/users_profile.rb +26 -20
- data/bin/commands/views.rb +47 -39
- data/bin/commands/workflows.rb +36 -30
- data/bin/slack +48 -43
- data/lib/slack/real_time/api/message.rb +3 -2
- data/lib/slack/real_time/api/templates/event_handler.erb +5 -1
- data/lib/slack/real_time/api/typing.rb +2 -1
- data/lib/slack/real_time/client.rb +10 -28
- data/lib/slack/real_time/config.rb +3 -3
- data/lib/slack/real_time/models/channel.rb +4 -0
- data/lib/slack/real_time/models/{group.rb → mpim.rb} +1 -1
- data/lib/slack/real_time/models.rb +2 -1
- data/lib/slack/real_time/stores/base.rb +25 -9
- data/lib/slack/real_time/stores/starter.rb +323 -309
- data/lib/slack/real_time/stores/store.rb +265 -198
- data/lib/slack/real_time/stores.rb +1 -7
- data/lib/slack/version.rb +1 -1
- data/lib/slack/web/api/endpoints/admin_analytics.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_apps.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_apps_requests.rb +16 -0
- data/lib/slack/web/api/endpoints/admin_audit_anomaly_allow.rb +34 -0
- data/lib/slack/web/api/endpoints/admin_auth_policy.rb +7 -7
- data/lib/slack/web/api/endpoints/admin_barriers.rb +8 -8
- data/lib/slack/web/api/endpoints/admin_conversations.rb +110 -28
- data/lib/slack/web/api/endpoints/admin_conversations_restrictAccess.rb +6 -6
- data/lib/slack/web/api/endpoints/admin_emoji.rb +9 -9
- data/lib/slack/web/api/endpoints/admin_inviteRequests.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_roles.rb +73 -0
- data/lib/slack/web/api/endpoints/admin_teams.rb +2 -2
- data/lib/slack/web/api/endpoints/admin_teams_admins.rb +1 -1
- data/lib/slack/web/api/endpoints/admin_teams_owners.rb +1 -1
- data/lib/slack/web/api/endpoints/admin_teams_settings.rb +11 -11
- data/lib/slack/web/api/endpoints/admin_usergroups.rb +7 -7
- data/lib/slack/web/api/endpoints/admin_users.rb +16 -16
- data/lib/slack/web/api/endpoints/admin_users_session.rb +8 -8
- data/lib/slack/web/api/endpoints/admin_users_unsupportedVersions.rb +25 -0
- data/lib/slack/web/api/endpoints/apps.rb +2 -2
- data/lib/slack/web/api/endpoints/apps_connections.rb +1 -1
- data/lib/slack/web/api/endpoints/apps_event_authorizations.rb +1 -1
- data/lib/slack/web/api/endpoints/apps_manifest.rb +8 -6
- data/lib/slack/web/api/endpoints/bookmarks.rb +88 -0
- data/lib/slack/web/api/endpoints/bots.rb +1 -1
- data/lib/slack/web/api/endpoints/calls.rb +5 -5
- data/lib/slack/web/api/endpoints/calls_participants.rb +4 -4
- data/lib/slack/web/api/endpoints/chat.rb +37 -31
- data/lib/slack/web/api/endpoints/conversations.rb +38 -34
- data/lib/slack/web/api/endpoints/dialog.rb +2 -2
- data/lib/slack/web/api/endpoints/dnd.rb +1 -1
- data/lib/slack/web/api/endpoints/emoji.rb +2 -0
- data/lib/slack/web/api/endpoints/files.rb +45 -10
- data/lib/slack/web/api/endpoints/files_comments.rb +2 -2
- data/lib/slack/web/api/endpoints/files_remote.rb +8 -8
- data/lib/slack/web/api/endpoints/functions_workflows_steps.rb +28 -0
- data/lib/slack/web/api/endpoints/functions_workflows_steps_responses.rb +28 -0
- data/lib/slack/web/api/endpoints/migration.rb +1 -1
- data/lib/slack/web/api/endpoints/oauth_v2.rb +2 -2
- data/lib/slack/web/api/endpoints/pins.rb +5 -3
- data/lib/slack/web/api/endpoints/reactions.rb +4 -4
- data/lib/slack/web/api/endpoints/reminders.rb +5 -5
- data/lib/slack/web/api/endpoints/rtm.rb +0 -23
- data/lib/slack/web/api/endpoints/search.rb +3 -3
- data/lib/slack/web/api/endpoints/team.rb +13 -1
- data/lib/slack/web/api/endpoints/tooling_tokens.rb +1 -1
- data/lib/slack/web/api/endpoints/usergroups.rb +5 -5
- data/lib/slack/web/api/endpoints/usergroups_users.rb +3 -3
- data/lib/slack/web/api/endpoints/users.rb +4 -4
- data/lib/slack/web/api/endpoints/users_admin.rb +2 -2
- data/lib/slack/web/api/endpoints/users_profile.rb +1 -1
- data/lib/slack/web/api/endpoints/views.rb +16 -11
- data/lib/slack/web/api/endpoints/workflows.rb +4 -4
- data/lib/slack/web/api/endpoints.rb +12 -0
- data/lib/slack/web/api/errors.rb +146 -8
- data/lib/slack/web/api/mixins/conversations.id.rb +1 -1
- data/lib/slack/web/api/mixins/users.id.rb +1 -1
- data/lib/slack/web/api/mixins/users.search.rb +2 -1
- data/lib/slack/web/api/patches/{chat.1.patch → chat.attachments-blocks.patch} +13 -14
- data/lib/slack/web/api/patches/{dialog.1.open-json-support.patch → dialog.encoded-json.patch} +4 -4
- data/lib/slack/web/api/patches/views.view-json.patch +55 -0
- data/lib/slack/web/api/templates/command.erb +18 -12
- data/lib/slack/web/api/templates/method.erb +1 -1
- data/lib/slack/web/config.rb +2 -2
- data/lib/slack/web/faraday/connection.rb +4 -4
- data/lib/slack/web/faraday/request.rb +2 -0
- data/lib/slack/web/faraday/response/raise_error.rb +2 -10
- data/lib/slack/web/faraday/response/wrap_error.rb +1 -1
- data/lib/slack-ruby-client.rb +2 -1
- data/lib/tasks/real_time.rake +44 -24
- data/lib/tasks/web.rake +9 -8
- data/slack-ruby-client.gemspec +5 -14
- data/spec/fixtures/slack/web/rtm_connect.yml +85 -1
- data/spec/integration/integration_spec.rb +1 -1
- data/spec/slack/events/config_spec.rb +2 -0
- data/spec/slack/events/request_spec.rb +5 -1
- data/spec/slack/messages/formatting_spec.rb +10 -0
- data/spec/slack/real_time/api/message_spec.rb +1 -1
- data/spec/slack/real_time/api/ping_spec.rb +1 -1
- data/spec/slack/real_time/api/typing_spec.rb +1 -1
- data/spec/slack/real_time/client_spec.rb +91 -127
- data/spec/slack/real_time/event_handlers/bot_spec.rb +19 -17
- data/spec/slack/real_time/event_handlers/event_handlers_spec.rb +1 -1
- data/spec/slack/real_time/event_handlers/im_spec.rb +30 -27
- data/spec/slack/real_time/event_handlers/{group_spec.rb → private_channel_spec.rb} +35 -27
- data/spec/slack/real_time/event_handlers/{channel_spec.rb → public_channel_spec.rb} +27 -23
- data/spec/slack/real_time/event_handlers/team_spec.rb +7 -8
- data/spec/slack/real_time/event_handlers/user_spec.rb +6 -5
- data/spec/slack/real_time/stores/store_spec.rb +50 -0
- data/spec/slack/slack_spec.rb +5 -4
- data/spec/slack/version_spec.rb +1 -1
- data/spec/slack/web/api/endpoints/admin_apps_requests_spec.rb +5 -0
- data/spec/slack/web/api/endpoints/admin_audit_anomaly_allow_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/admin_conversations_spec.rb +31 -0
- data/spec/slack/web/api/endpoints/admin_roles_spec.rb +30 -0
- data/spec/slack/web/api/endpoints/admin_users_unsupportedVersions_spec.rb +8 -0
- data/spec/slack/web/api/endpoints/bookmarks_spec.rb +40 -0
- data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +45 -17
- data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +6 -2
- data/spec/slack/web/api/endpoints/custom_specs/views_spec.rb +33 -16
- data/spec/slack/web/api/endpoints/files_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/functions_workflows_steps_responses_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/functions_workflows_steps_spec.rb +13 -0
- data/spec/slack/web/api/mixins/conversations_spec.rb +2 -0
- data/spec/slack/web/api/mixins/users_spec.rb +2 -0
- data/spec/slack/web/api/pagination/cursor_spec.rb +11 -7
- data/spec/slack/web/client_spec.rb +39 -11
- data/spec/slack/web/faraday/response/raise_error_spec.rb +1 -1
- data/spec/support/real_time/connected_client.rb +1 -1
- data/spec/support/real_time/loaded_client.rb +120 -0
- metadata +45 -197
- data/.travis.yml +0 -29
- data/bin/commands/admin_conversations_whitelist.rb +0 -37
- data/bin/commands/apps_permissions.rb +0 -23
- data/bin/commands/apps_permissions_resources.rb +0 -15
- data/bin/commands/apps_permissions_scopes.rb +0 -13
- data/bin/commands/apps_permissions_users.rb +0 -26
- data/bin/commands/channels.rb +0 -23
- data/bin/commands/groups.rb +0 -14
- data/bin/commands/im.rb +0 -6
- data/bin/commands/mpim.rb +0 -6
- data/bin/commands.rb +0 -66
- data/lib/slack/web/api/endpoints/admin_conversations_whitelist.rb +0 -64
- data/lib/slack/web/api/endpoints/apps_permissions.rb +0 -36
- data/lib/slack/web/api/endpoints/apps_permissions_resources.rb +0 -31
- data/lib/slack/web/api/endpoints/apps_permissions_scopes.rb +0 -21
- data/lib/slack/web/api/endpoints/apps_permissions_users.rb +0 -50
- data/lib/slack/web/api/endpoints/channels.rb +0 -25
- data/lib/slack/web/api/endpoints/groups.rb +0 -13
- data/lib/slack/web/api/endpoints/im.rb +0 -13
- data/lib/slack/web/api/endpoints/mpim.rb +0 -13
- data/lib/slack/web/api/endpoints/presence.rb +0 -23
- data/lib/slack/web/api/patches/views.1.view-json.patch +0 -40
- data/lib/slack/web/api/patches/views.1.views-published.patch +0 -16
- data/lib/slack/web/api/templates/commands.erb +0 -6
- data/spec/fixtures/slack/web/rtm_start.yml +0 -815
- data/spec/slack/real_time/rtm_start_spec.rb +0 -14
- data/spec/slack/real_time/store_spec.rb +0 -12
@@ -0,0 +1,40 @@
|
|
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::Bookmarks do
|
7
|
+
let(:client) { Slack::Web::Client.new }
|
8
|
+
context 'bookmarks_add' do
|
9
|
+
it 'requires channel_id' do
|
10
|
+
expect { client.bookmarks_add(title: %q[], type: %q[]) }.to raise_error ArgumentError, /Required arguments :channel_id missing/
|
11
|
+
end
|
12
|
+
it 'requires title' do
|
13
|
+
expect { client.bookmarks_add(channel_id: %q[], type: %q[]) }.to raise_error ArgumentError, /Required arguments :title missing/
|
14
|
+
end
|
15
|
+
it 'requires type' do
|
16
|
+
expect { client.bookmarks_add(channel_id: %q[], title: %q[]) }.to raise_error ArgumentError, /Required arguments :type missing/
|
17
|
+
end
|
18
|
+
end
|
19
|
+
context 'bookmarks_edit' do
|
20
|
+
it 'requires bookmark_id' do
|
21
|
+
expect { client.bookmarks_edit(channel_id: %q[]) }.to raise_error ArgumentError, /Required arguments :bookmark_id missing/
|
22
|
+
end
|
23
|
+
it 'requires channel_id' do
|
24
|
+
expect { client.bookmarks_edit(bookmark_id: %q[]) }.to raise_error ArgumentError, /Required arguments :channel_id missing/
|
25
|
+
end
|
26
|
+
end
|
27
|
+
context 'bookmarks_list' do
|
28
|
+
it 'requires channel_id' do
|
29
|
+
expect { client.bookmarks_list }.to raise_error ArgumentError, /Required arguments :channel_id missing/
|
30
|
+
end
|
31
|
+
end
|
32
|
+
context 'bookmarks_remove' do
|
33
|
+
it 'requires bookmark_id' do
|
34
|
+
expect { client.bookmarks_remove(channel_id: %q[]) }.to raise_error ArgumentError, /Required arguments :bookmark_id missing/
|
35
|
+
end
|
36
|
+
it 'requires channel_id' do
|
37
|
+
expect { client.bookmarks_remove(bookmark_id: %q[]) }.to raise_error ArgumentError, /Required arguments :channel_id missing/
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -14,11 +14,13 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
|
|
14
14
|
it 'automatically converts attachments and blocks into JSON' do
|
15
15
|
expect(client).to receive(:post).with(
|
16
16
|
'chat.postEphemeral',
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
{
|
18
|
+
channel: 'channel',
|
19
|
+
text: 'text',
|
20
|
+
user: '123',
|
21
|
+
attachments: '[]',
|
22
|
+
blocks: '[]'
|
23
|
+
}
|
22
24
|
)
|
23
25
|
client.chat_postEphemeral(
|
24
26
|
channel: 'channel',
|
@@ -28,17 +30,20 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
|
|
28
30
|
blocks: []
|
29
31
|
)
|
30
32
|
end
|
33
|
+
|
31
34
|
context 'text and user arguments' do
|
32
35
|
it 'requires text or attachments' do
|
33
36
|
expect { client.chat_postEphemeral(channel: 'channel') }.to(
|
34
37
|
raise_error(ArgumentError, /Required arguments :text, :attachments or :blocks missing/)
|
35
38
|
)
|
36
39
|
end
|
40
|
+
|
37
41
|
it 'requires user' do
|
38
42
|
expect { client.chat_postEphemeral(channel: 'channel', text: 'text') }.to(
|
39
43
|
raise_error(ArgumentError, /Required arguments :user missing/)
|
40
44
|
)
|
41
45
|
end
|
46
|
+
|
42
47
|
it 'both text and user' do
|
43
48
|
expect(client).to(
|
44
49
|
receive(:post).with('chat.postEphemeral', hash_including(text: 'text', user: '123'))
|
@@ -58,6 +63,7 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
|
|
58
63
|
client.chat_postEphemeral(channel: 'channel', text: 'text', user: '123', attachments: [])
|
59
64
|
end.not_to raise_error
|
60
65
|
end
|
66
|
+
|
61
67
|
it 'attachments without text' do
|
62
68
|
expect(client).to(
|
63
69
|
receive(:post).with('chat.postEphemeral', hash_including(attachments: '[]'))
|
@@ -75,6 +81,7 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
|
|
75
81
|
client.chat_postEphemeral(channel: 'channel', text: 'text', user: '123', blocks: [])
|
76
82
|
end.not_to raise_error
|
77
83
|
end
|
84
|
+
|
78
85
|
it 'blocks without text' do
|
79
86
|
expect(client).to receive(:post).with('chat.postEphemeral', hash_including(blocks: '[]'))
|
80
87
|
expect do
|
@@ -88,31 +95,38 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
|
|
88
95
|
it 'automatically converts attachments and blocks into JSON' do
|
89
96
|
expect(client).to receive(:post).with(
|
90
97
|
'chat.postMessage',
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
98
|
+
{
|
99
|
+
channel: 'channel',
|
100
|
+
text: 'text',
|
101
|
+
attachments: '[]',
|
102
|
+
blocks: '[]'
|
103
|
+
}
|
95
104
|
)
|
96
105
|
client.chat_postMessage(channel: 'channel', text: 'text', attachments: [], blocks: [])
|
97
106
|
end
|
107
|
+
|
98
108
|
context 'text, attachment and blocks arguments' do
|
99
109
|
it 'requires text, attachments or blocks' do
|
100
110
|
expect { client.chat_postMessage(channel: 'channel') }.to(
|
101
111
|
raise_error(ArgumentError, /Required arguments :text, :attachments or :blocks missing/)
|
102
112
|
)
|
103
113
|
end
|
114
|
+
|
104
115
|
it 'only text' do
|
105
116
|
expect(client).to receive(:post).with('chat.postMessage', hash_including(text: 'text'))
|
106
117
|
expect { client.chat_postMessage(channel: 'channel', text: 'text') }.not_to raise_error
|
107
118
|
end
|
119
|
+
|
108
120
|
it 'only attachments' do
|
109
121
|
expect(client).to receive(:post).with('chat.postMessage', hash_including(attachments: '[]'))
|
110
122
|
expect { client.chat_postMessage(channel: 'channel', attachments: []) }.not_to raise_error
|
111
123
|
end
|
124
|
+
|
112
125
|
it 'only blocks' do
|
113
126
|
expect(client).to receive(:post).with('chat.postMessage', hash_including(blocks: '[]'))
|
114
127
|
expect { client.chat_postMessage(channel: 'channel', blocks: []) }.not_to raise_error
|
115
128
|
end
|
129
|
+
|
116
130
|
it 'all text, attachments and blocks' do
|
117
131
|
expect(client).to(
|
118
132
|
receive(:post)
|
@@ -131,46 +145,60 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
|
|
131
145
|
it 'automatically converts attachments and blocks into JSON' do
|
132
146
|
expect(client).to receive(:post).with(
|
133
147
|
'chat.update',
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
148
|
+
{
|
149
|
+
channel: 'channel',
|
150
|
+
text: 'text',
|
151
|
+
ts: ts,
|
152
|
+
attachments: '[]',
|
153
|
+
blocks: '[]'
|
154
|
+
}
|
139
155
|
)
|
140
156
|
client.chat_update(channel: 'channel', text: 'text', ts: ts, attachments: [], blocks: [])
|
141
157
|
end
|
158
|
+
|
142
159
|
context 'ts arguments' do
|
143
160
|
it 'requires ts' do
|
144
161
|
expect do
|
145
162
|
client.chat_update(channel: 'channel', text: 'text')
|
146
|
-
end.to raise_error(ArgumentError, /Required arguments :ts missing
|
163
|
+
end.to raise_error(ArgumentError, /Required arguments :ts missing/)
|
147
164
|
end
|
148
165
|
end
|
149
166
|
|
150
167
|
context 'text, attachment and blocks arguments' do
|
151
|
-
it 'requires text, attachments or
|
168
|
+
it 'requires text, attachments, blocks or reply_broadcast' do
|
152
169
|
expect { client.chat_update(channel: 'channel', ts: ts) }.to(
|
153
|
-
raise_error(ArgumentError, /Required arguments :text, :attachments or :
|
170
|
+
raise_error(ArgumentError, /Required arguments :text, :attachments, :blocks or :reply_broadcast missing/)
|
154
171
|
)
|
155
172
|
end
|
173
|
+
|
156
174
|
it 'only text' do
|
157
175
|
expect(client).to receive(:post).with('chat.update', hash_including(text: 'text'))
|
158
176
|
expect do
|
159
177
|
client.chat_update(channel: 'channel', text: 'text', ts: ts)
|
160
178
|
end.not_to raise_error
|
161
179
|
end
|
180
|
+
|
162
181
|
it 'only attachments' do
|
163
182
|
expect(client).to receive(:post).with('chat.update', hash_including(attachments: '[]'))
|
164
183
|
expect do
|
165
184
|
client.chat_update(channel: 'channel', ts: ts, attachments: [])
|
166
185
|
end.not_to raise_error
|
167
186
|
end
|
187
|
+
|
168
188
|
it 'only blocks' do
|
169
189
|
expect(client).to receive(:post).with('chat.update', hash_including(blocks: '[]'))
|
170
190
|
expect do
|
171
191
|
client.chat_update(channel: 'channel', ts: ts, blocks: [])
|
172
192
|
end.not_to raise_error
|
173
193
|
end
|
194
|
+
|
195
|
+
it 'only reply_broadcast' do
|
196
|
+
expect(client).to receive(:post).with('chat.update', hash_including(reply_broadcast: true))
|
197
|
+
expect do
|
198
|
+
client.chat_update(channel: 'channel', ts: ts, reply_broadcast: true)
|
199
|
+
end.not_to raise_error
|
200
|
+
end
|
201
|
+
|
174
202
|
it 'all text, attachments and blocks' do
|
175
203
|
expect(client).to(
|
176
204
|
receive(:post)
|
@@ -8,8 +8,10 @@ RSpec.describe Slack::Web::Api::Endpoints::Dialog do
|
|
8
8
|
it 'automatically converts dialog into JSON' do
|
9
9
|
expect(client).to receive(:post).with(
|
10
10
|
'dialog.open',
|
11
|
-
|
12
|
-
|
11
|
+
{
|
12
|
+
trigger_id: '12345.98765.abcd2358fdea',
|
13
|
+
dialog: '[]'
|
14
|
+
}
|
13
15
|
)
|
14
16
|
client.dialog_open(trigger_id: '12345.98765.abcd2358fdea', dialog: [])
|
15
17
|
end
|
@@ -20,11 +22,13 @@ RSpec.describe Slack::Web::Api::Endpoints::Dialog do
|
|
20
22
|
raise_error(ArgumentError, /Required arguments :dialog missing/)
|
21
23
|
)
|
22
24
|
end
|
25
|
+
|
23
26
|
it 'requires trigger_id' do
|
24
27
|
expect { client.dialog_open(dialog: []) }.to(
|
25
28
|
raise_error(ArgumentError, /Required arguments :trigger_id missing/)
|
26
29
|
)
|
27
30
|
end
|
31
|
+
|
28
32
|
it 'likes both dialog and trigger_id' do
|
29
33
|
expect(client).to(
|
30
34
|
receive(:post).with('dialog.open', hash_including(trigger_id: '123', dialog: '[]'))
|
@@ -4,13 +4,14 @@ require 'spec_helper'
|
|
4
4
|
RSpec.describe Slack::Web::Api::Endpoints::Views do
|
5
5
|
let(:client) { Slack::Web::Client.new }
|
6
6
|
let(:trigger_id) { '12345.98765.abcd2358fdea' }
|
7
|
+
let(:view_id) { 'abc123567' }
|
7
8
|
|
8
9
|
describe 'views_open' do
|
9
10
|
context 'with a hash for view' do
|
10
11
|
let(:view_str) { '{"celery":"man"}' }
|
11
12
|
|
12
13
|
it 'automatically converts view into JSON' do
|
13
|
-
expect(client).to receive(:post).with('views.open', trigger_id: trigger_id, view: view_str)
|
14
|
+
expect(client).to receive(:post).with('views.open', { trigger_id: trigger_id, view: view_str })
|
14
15
|
client.views_open(trigger_id: trigger_id, view: { celery: 'man' })
|
15
16
|
end
|
16
17
|
end
|
@@ -19,7 +20,7 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
|
|
19
20
|
let(:view_str) { 'celery man' }
|
20
21
|
|
21
22
|
it 'leaves view as is' do
|
22
|
-
expect(client).to receive(:post).with('views.open', trigger_id: trigger_id, view: view_str)
|
23
|
+
expect(client).to receive(:post).with('views.open', { trigger_id: trigger_id, view: view_str })
|
23
24
|
client.views_open(trigger_id: trigger_id, view: 'celery man')
|
24
25
|
end
|
25
26
|
end
|
@@ -32,10 +33,14 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
|
|
32
33
|
let(:view_str) { '{"celery":"man"}' }
|
33
34
|
|
34
35
|
it 'automatically converts view into JSON' do
|
35
|
-
expect(client).to receive(:post).with(
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
expect(client).to receive(:post).with(
|
37
|
+
'views.publish',
|
38
|
+
{
|
39
|
+
trigger_id: trigger_id,
|
40
|
+
user_id: user_id,
|
41
|
+
view: view_str
|
42
|
+
}
|
43
|
+
)
|
39
44
|
client.views_publish(user_id: user_id, trigger_id: trigger_id, view: { celery: 'man' })
|
40
45
|
end
|
41
46
|
end
|
@@ -44,10 +49,14 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
|
|
44
49
|
let(:view_str) { 'celery man' }
|
45
50
|
|
46
51
|
it 'leaves view as is' do
|
47
|
-
expect(client).to receive(:post).with(
|
48
|
-
|
49
|
-
|
50
|
-
|
52
|
+
expect(client).to receive(:post).with(
|
53
|
+
'views.publish',
|
54
|
+
{
|
55
|
+
user_id: user_id,
|
56
|
+
trigger_id: trigger_id,
|
57
|
+
view: view_str
|
58
|
+
}
|
59
|
+
)
|
51
60
|
client.views_publish(user_id: user_id, trigger_id: trigger_id, view: 'celery man')
|
52
61
|
end
|
53
62
|
end
|
@@ -58,7 +67,7 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
|
|
58
67
|
let(:view_str) { '{"celery":"man"}' }
|
59
68
|
|
60
69
|
it 'automatically converts view into JSON' do
|
61
|
-
expect(client).to receive(:post).with('views.push', trigger_id: trigger_id, view: view_str)
|
70
|
+
expect(client).to receive(:post).with('views.push', { trigger_id: trigger_id, view: view_str })
|
62
71
|
client.views_push(trigger_id: trigger_id, view: { celery: 'man' })
|
63
72
|
end
|
64
73
|
end
|
@@ -67,7 +76,7 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
|
|
67
76
|
let(:view_str) { 'celery man' }
|
68
77
|
|
69
78
|
it 'leaves view as is' do
|
70
|
-
expect(client).to receive(:post).with('views.push', trigger_id: trigger_id, view: view_str)
|
79
|
+
expect(client).to receive(:post).with('views.push', { trigger_id: trigger_id, view: view_str })
|
71
80
|
client.views_push(trigger_id: trigger_id, view: 'celery man')
|
72
81
|
end
|
73
82
|
end
|
@@ -78,8 +87,8 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
|
|
78
87
|
let(:view_str) { '{"celery":"man"}' }
|
79
88
|
|
80
89
|
it 'automatically converts view into JSON' do
|
81
|
-
expect(client).to receive(:post).with('views.update', view: view_str)
|
82
|
-
client.views_update(view: { celery: 'man' })
|
90
|
+
expect(client).to receive(:post).with('views.update', { view_id: view_id, view: view_str })
|
91
|
+
client.views_update(view_id: view_id, view: { celery: 'man' })
|
83
92
|
end
|
84
93
|
end
|
85
94
|
|
@@ -87,8 +96,16 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
|
|
87
96
|
let(:view_str) { 'celery man' }
|
88
97
|
|
89
98
|
it 'leaves view as is' do
|
90
|
-
expect(client).to receive(:post).with('views.update', view: view_str)
|
91
|
-
client.views_update(view: 'celery man')
|
99
|
+
expect(client).to receive(:post).with('views.update', { view_id: view_id, view: view_str })
|
100
|
+
client.views_update(view_id: view_id, view: 'celery man')
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'with both an external_id and view_id' do
|
104
|
+
it 'raises error' do
|
105
|
+
expect do
|
106
|
+
client.views_update(external_id: trigger_id, view_id: view_id, view: 'celery man')
|
107
|
+
end.to raise_error ArgumentError, 'One of :external_id, :view_id is required'
|
108
|
+
end
|
92
109
|
end
|
93
110
|
end
|
94
111
|
end
|
@@ -5,6 +5,11 @@ require 'spec_helper'
|
|
5
5
|
|
6
6
|
RSpec.describe Slack::Web::Api::Endpoints::Files do
|
7
7
|
let(:client) { Slack::Web::Client.new }
|
8
|
+
context 'files_completeUploadExternal' do
|
9
|
+
it 'requires files' do
|
10
|
+
expect { client.files_completeUploadExternal }.to raise_error ArgumentError, /Required arguments :files missing/
|
11
|
+
end
|
12
|
+
end
|
8
13
|
context 'files_delete' do
|
9
14
|
it 'requires file' do
|
10
15
|
expect { client.files_delete }.to raise_error ArgumentError, /Required arguments :file missing/
|
@@ -18,6 +23,14 @@ RSpec.describe Slack::Web::Api::Endpoints::Files do
|
|
18
23
|
expect { client.files_edit(file: %q[F2147483862]) }.to raise_error ArgumentError, /Required arguments :title missing/
|
19
24
|
end
|
20
25
|
end
|
26
|
+
context 'files_getUploadURLExternal' do
|
27
|
+
it 'requires filename' do
|
28
|
+
expect { client.files_getUploadURLExternal(length: %q[]) }.to raise_error ArgumentError, /Required arguments :filename missing/
|
29
|
+
end
|
30
|
+
it 'requires length' do
|
31
|
+
expect { client.files_getUploadURLExternal(filename: %q[]) }.to raise_error ArgumentError, /Required arguments :length missing/
|
32
|
+
end
|
33
|
+
end
|
21
34
|
context 'files_info' do
|
22
35
|
it 'requires file' do
|
23
36
|
expect { client.files_info }.to raise_error ArgumentError, /Required arguments :file missing/
|
@@ -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::FunctionsWorkflowsStepsResponses do
|
7
|
+
let(:client) { Slack::Web::Client.new }
|
8
|
+
context 'functions.workflows.steps.responses_export' do
|
9
|
+
it 'requires step_id' do
|
10
|
+
expect { client.functions_workflows_steps_responses_export }.to raise_error ArgumentError, /Required arguments :step_id missing/
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -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::FunctionsWorkflowsSteps do
|
7
|
+
let(:client) { Slack::Web::Client.new }
|
8
|
+
context 'functions.workflows.steps_list' do
|
9
|
+
it 'requires function_id' do
|
10
|
+
expect { client.functions_workflows_steps_list }.to raise_error ArgumentError, /Required arguments :function_id missing/
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -29,11 +29,13 @@ RSpec.describe Slack::Web::Api::Mixins::Conversations do
|
|
29
29
|
eq('ok' => true, 'channel' => { 'id' => 'C123456' })
|
30
30
|
)
|
31
31
|
end
|
32
|
+
|
32
33
|
it 'translates a channel that starts with a #' do
|
33
34
|
expect(conversations.conversations_id(channel: '#general')).to(
|
34
35
|
eq('ok' => true, 'channel' => { 'id' => 'CDEADBEEF' })
|
35
36
|
)
|
36
37
|
end
|
38
|
+
|
37
39
|
it 'fails with an exception' do
|
38
40
|
expect { conversations.conversations_id(channel: '#invalid') }.to(
|
39
41
|
raise_error(Slack::Web::Api::Errors::SlackError, 'channel_not_found')
|
@@ -28,9 +28,11 @@ RSpec.describe Slack::Web::Api::Mixins::Users do
|
|
28
28
|
it 'leaves users specified by ID alone' do
|
29
29
|
expect(users.users_id(user: 'U123456')).to eq('ok' => true, 'user' => { 'id' => 'U123456' })
|
30
30
|
end
|
31
|
+
|
31
32
|
it 'translates a user that starts with a #' do
|
32
33
|
expect(users.users_id(user: '@aws')).to eq('ok' => true, 'user' => { 'id' => 'UDEADBEEF' })
|
33
34
|
end
|
35
|
+
|
34
36
|
it 'fails with an exception' do
|
35
37
|
expect { users.users_id(user: '@foo') }.to(
|
36
38
|
raise_error(Slack::Web::Api::Errors::SlackError, 'user_not_found')
|
@@ -8,19 +8,22 @@ 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
15
|
it 'handles blank response metadata' do
|
15
16
|
expect(client).to receive(:users_list).once.and_return(Slack::Messages::Message.new)
|
16
17
|
cursor.to_a
|
17
18
|
end
|
19
|
+
|
18
20
|
it 'handles nil response metadata' do
|
19
21
|
expect(client).to(
|
20
22
|
receive(:users_list).once.and_return(Slack::Messages::Message.new(response_metadata: nil))
|
21
23
|
)
|
22
24
|
cursor.to_a
|
23
25
|
end
|
26
|
+
|
24
27
|
it 'paginates with a cursor inside response metadata' do
|
25
28
|
expect(client).to receive(:users_list).twice.and_return(
|
26
29
|
Slack::Messages::Message.new(response_metadata: { next_cursor: 'next' }),
|
@@ -29,6 +32,7 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
|
|
29
32
|
expect(cursor).not_to receive(:sleep)
|
30
33
|
cursor.to_a
|
31
34
|
end
|
35
|
+
|
32
36
|
context 'with rate limiting' do
|
33
37
|
let(:error) { Slack::Web::Api::Errors::TooManyRequestsError.new(OpenStruct.new(headers: { 'retry-after' => 9 })) }
|
34
38
|
|
@@ -36,17 +40,17 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
|
|
36
40
|
it 'sleeps after a TooManyRequestsError' do
|
37
41
|
expect(client).to(
|
38
42
|
receive(:users_list)
|
39
|
-
.with(limit: 100, cursor: nil)
|
43
|
+
.with({ limit: 100, cursor: nil })
|
40
44
|
.ordered
|
41
45
|
.and_return(Slack::Messages::Message.new(response_metadata: { next_cursor: 'next' }))
|
42
46
|
)
|
43
47
|
expect(client).to(
|
44
|
-
receive(:users_list).with(limit: 100, cursor: 'next').ordered.and_raise(error)
|
48
|
+
receive(:users_list).with({ limit: 100, cursor: 'next' }).ordered.and_raise(error)
|
45
49
|
)
|
46
50
|
expect(cursor).to receive(:sleep).once.ordered.with(9)
|
47
51
|
expect(client).to(
|
48
52
|
receive(:users_list)
|
49
|
-
.with(limit: 100, cursor: 'next')
|
53
|
+
.with({ limit: 100, cursor: 'next' })
|
50
54
|
.ordered
|
51
55
|
.and_return(Slack::Messages::Message.new)
|
52
56
|
)
|
@@ -60,11 +64,11 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
|
|
60
64
|
it 'raises the error after hitting the max retries' do
|
61
65
|
expect(client).to(
|
62
66
|
receive(:users_list)
|
63
|
-
.with(limit: 100, cursor: nil)
|
67
|
+
.with({ limit: 100, cursor: nil })
|
64
68
|
.and_return(Slack::Messages::Message.new(response_metadata: { next_cursor: 'next' }))
|
65
69
|
)
|
66
70
|
expect(client).to(
|
67
|
-
receive(:users_list).with(limit: 100, cursor: 'next').exactly(5).times.and_raise(error)
|
71
|
+
receive(:users_list).with({ limit: 100, cursor: 'next' }).exactly(5).times.and_raise(error)
|
68
72
|
)
|
69
73
|
expect(cursor).to receive(:sleep).exactly(4).times.with(9)
|
70
74
|
expect { cursor.to_a }.to raise_error(error)
|
@@ -77,7 +81,7 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
|
|
77
81
|
let(:cursor) { described_class.new(client, 'users_list', limit: 42) }
|
78
82
|
|
79
83
|
it 'overrides default limit' do
|
80
|
-
expect(client).to receive(:users_list).with(limit: 42, cursor: nil)
|
84
|
+
expect(client).to receive(:users_list).with({ limit: 42, cursor: nil })
|
81
85
|
cursor.first
|
82
86
|
end
|
83
87
|
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
|
@@ -14,6 +15,7 @@ RSpec.describe Slack::Web::Client do
|
|
14
15
|
expect(client.user_agent).to eq Slack::Web::Config.user_agent
|
15
16
|
expect(client.user_agent).to include Slack::VERSION
|
16
17
|
end
|
18
|
+
|
17
19
|
(Slack::Web::Config::ATTRIBUTES - [:logger]).each do |key|
|
18
20
|
it "sets #{key}" do
|
19
21
|
expect(client.send(key)).to eq Slack::Web::Config.send(key)
|
@@ -55,6 +57,7 @@ RSpec.describe Slack::Web::Client do
|
|
55
57
|
it 'sets user-agent' do
|
56
58
|
expect(client.user_agent).to eq 'custom/user-agent'
|
57
59
|
end
|
60
|
+
|
58
61
|
it 'creates a connection with the custom user-agent' do
|
59
62
|
expect(client.send(:connection).headers).to eq(
|
60
63
|
'Accept' => 'application/json; charset=utf-8',
|
@@ -75,6 +78,7 @@ RSpec.describe Slack::Web::Client do
|
|
75
78
|
client = described_class.new
|
76
79
|
expect(client.token).to eq 'global default'
|
77
80
|
end
|
81
|
+
|
78
82
|
context 'with web config' do
|
79
83
|
before do
|
80
84
|
described_class.configure do |config|
|
@@ -86,6 +90,7 @@ RSpec.describe Slack::Web::Client do
|
|
86
90
|
client = described_class.new
|
87
91
|
expect(client.token).to eq 'custom web token'
|
88
92
|
end
|
93
|
+
|
89
94
|
it 'overrides token to specific token' do
|
90
95
|
client = described_class.new(token: 'local token')
|
91
96
|
expect(client.token).to eq 'local token'
|
@@ -104,6 +109,7 @@ RSpec.describe Slack::Web::Client do
|
|
104
109
|
it 'sets proxy' do
|
105
110
|
expect(client.proxy).to eq 'http://localhost:8080'
|
106
111
|
end
|
112
|
+
|
107
113
|
it 'creates a connection with the proxy' do
|
108
114
|
expect(client.send(:connection).proxy.uri.to_s).to eq 'http://localhost:8080'
|
109
115
|
end
|
@@ -123,6 +129,7 @@ RSpec.describe Slack::Web::Client do
|
|
123
129
|
expect(client.ca_path).to eq '/ca_path'
|
124
130
|
expect(client.ca_file).to eq '/ca_file'
|
125
131
|
end
|
132
|
+
|
126
133
|
it 'creates a connection with ssl options' do
|
127
134
|
ssl = client.send(:connection).ssl
|
128
135
|
expect(ssl.ca_path).to eq '/ca_path'
|
@@ -144,6 +151,7 @@ RSpec.describe Slack::Web::Client do
|
|
144
151
|
it 'sets logger' do
|
145
152
|
expect(client.logger).to eq logger
|
146
153
|
end
|
154
|
+
|
147
155
|
it 'creates a connection with a logger' do
|
148
156
|
expect(client.send(:connection).builder.handlers).to include ::Faraday::Response::Logger
|
149
157
|
end
|
@@ -167,6 +175,7 @@ RSpec.describe Slack::Web::Client do
|
|
167
175
|
it 'sets adapter' do
|
168
176
|
expect(client.adapter).to eq adapter
|
169
177
|
end
|
178
|
+
|
170
179
|
it 'creates a connection with an adapter' do
|
171
180
|
expect(client.send(:connection).adapter).to eq adapter_class
|
172
181
|
end
|
@@ -187,6 +196,7 @@ RSpec.describe Slack::Web::Client do
|
|
187
196
|
it 'sets adapter' do
|
188
197
|
expect(client.adapter).to eq adapter
|
189
198
|
end
|
199
|
+
|
190
200
|
it 'creates a connection with an adapter' do
|
191
201
|
expect(client.send(:connection).adapter).to eq adapter_class
|
192
202
|
end
|
@@ -207,6 +217,7 @@ RSpec.describe Slack::Web::Client do
|
|
207
217
|
expect(client.timeout).to eq 10
|
208
218
|
expect(client.open_timeout).to eq 15
|
209
219
|
end
|
220
|
+
|
210
221
|
it 'creates a connection with timeout options' do
|
211
222
|
conn = client.send(:connection)
|
212
223
|
expect(conn.options.timeout).to eq 10
|
@@ -216,16 +227,16 @@ RSpec.describe Slack::Web::Client do
|
|
216
227
|
end
|
217
228
|
|
218
229
|
context 'per-request options' do
|
219
|
-
it 'applies timeout', vcr: { cassette_name: 'web/
|
230
|
+
it 'applies timeout', vcr: { cassette_name: 'web/rtm_connect', allow_playback_repeats: true } do
|
220
231
|
# reuse the same connection for the test, otherwise it creates a new one every time
|
221
232
|
conn = client.send(:connection)
|
222
233
|
expect(client).to receive(:connection).and_return(conn)
|
223
234
|
|
224
235
|
# get the yielded request to reuse in the next call to
|
225
|
-
#
|
236
|
+
# rtm.connect so that we can examine request.options later
|
226
237
|
request = nil
|
227
238
|
response = conn.post do |r|
|
228
|
-
r.path = 'rtm.
|
239
|
+
r.path = 'rtm.connect'
|
229
240
|
r.headers = {
|
230
241
|
'Accept' => ['application/json; charset=utf-8'],
|
231
242
|
'Authorization' => ['Bearer <SLACK_API_TOKEN>']
|
@@ -235,7 +246,7 @@ RSpec.describe Slack::Web::Client do
|
|
235
246
|
|
236
247
|
expect(conn).to receive(:post).and_yield(request).and_return(response)
|
237
248
|
|
238
|
-
client.
|
249
|
+
client.rtm_connect(request: { timeout: 3 })
|
239
250
|
|
240
251
|
expect(request.options.timeout).to eq 3
|
241
252
|
end
|
@@ -275,13 +286,28 @@ RSpec.describe Slack::Web::Client do
|
|
275
286
|
end
|
276
287
|
|
277
288
|
context 'parsing error' do
|
278
|
-
|
289
|
+
context 'when the response is not JSON' do
|
290
|
+
before do
|
291
|
+
stub_slack_request.to_return(body: '<html></html>', headers: { 'Content-Type' => 'text/html' })
|
292
|
+
end
|
293
|
+
|
294
|
+
it 'raises ParsingError' do
|
295
|
+
expect { request }.to raise_error(Slack::Web::Api::Errors::ParsingError).with_message('parsing_error')
|
296
|
+
expect(exception.response.body).to eq('<html></html>')
|
297
|
+
expect(exception.cause).to be_a(Faraday::ParsingError)
|
298
|
+
expect(exception.cause.cause).to be_a(JSON::ParserError)
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
context 'when the response is malformed JSON' do
|
303
|
+
before { stub_slack_request.to_return(body: '{') }
|
279
304
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
305
|
+
it 'raises ParsingError' do
|
306
|
+
expect { request }.to raise_error(Slack::Web::Api::Errors::ParsingError).with_message('parsing_error')
|
307
|
+
expect(exception.response.body).to eq('{')
|
308
|
+
expect(exception.cause).to be_a(Faraday::ParsingError)
|
309
|
+
expect(exception.cause.cause).to be_a(JSON::ParserError)
|
310
|
+
end
|
285
311
|
end
|
286
312
|
end
|
287
313
|
|
@@ -318,7 +344,9 @@ RSpec.describe Slack::Web::Client do
|
|
318
344
|
end
|
319
345
|
|
320
346
|
context 'with a HTML response' do
|
321
|
-
before
|
347
|
+
before do
|
348
|
+
stub_slack_request.to_return(status: 500, body: '<html></html>', headers: { 'Content-Type' => 'text/html' })
|
349
|
+
end
|
322
350
|
|
323
351
|
it 'raises UnavailableError' do
|
324
352
|
expect { request }.to raise_error(Slack::Web::Api::Errors::UnavailableError).with_message('unavailable_error')
|