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.
Files changed (234) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/danger.yml +19 -0
  3. data/.github/workflows/integtest.yml +25 -0
  4. data/.github/workflows/rubocop.yml +13 -0
  5. data/.github/workflows/test.yml +34 -0
  6. data/.gitignore +5 -3
  7. data/.rubocop.yml +6 -0
  8. data/.rubocop_todo.yml +137 -43
  9. data/CHANGELOG.md +34 -3
  10. data/CONTRIBUTING.md +4 -4
  11. data/Gemfile +18 -1
  12. data/Gemfile.danger +6 -0
  13. data/LICENSE.md +1 -1
  14. data/README.md +13 -12
  15. data/RELEASING.md +1 -1
  16. data/UPGRADING.md +42 -0
  17. data/bin/commands/admin_analytics.rb +2 -1
  18. data/bin/commands/admin_apps.rb +11 -0
  19. data/bin/commands/admin_apps_requests.rb +12 -0
  20. data/bin/commands/admin_auth_policy.rb +39 -0
  21. data/bin/commands/admin_conversations.rb +2 -1
  22. data/bin/commands/admin_conversations_restrictAccess.rb +1 -1
  23. data/bin/commands/admin_emoji.rb +2 -2
  24. data/bin/commands/admin_teams.rb +1 -1
  25. data/bin/commands/admin_users.rb +1 -0
  26. data/bin/commands/admin_users_session.rb +40 -0
  27. data/bin/commands/admin_users_unsupportedVersions.rb +15 -0
  28. data/bin/commands/apps_manifest.rb +52 -0
  29. data/bin/commands/bookmarks.rb +52 -0
  30. data/bin/commands/channels.rb +0 -157
  31. data/bin/commands/chat.rb +14 -9
  32. data/bin/commands/conversations.rb +61 -4
  33. data/bin/commands/dnd.rb +3 -1
  34. data/bin/commands/files.rb +2 -1
  35. data/bin/commands/groups.rb +0 -163
  36. data/bin/commands/im.rb +0 -62
  37. data/bin/commands/mpim.rb +0 -60
  38. data/bin/commands/oauth.rb +0 -13
  39. data/bin/commands/oauth_v2.rb +13 -1
  40. data/bin/commands/openid_connect.rb +27 -0
  41. data/bin/commands/pins.rb +2 -2
  42. data/bin/commands/reminders.rb +6 -0
  43. data/bin/commands/rtm.rb +2 -2
  44. data/bin/commands/search.rb +2 -1
  45. data/bin/commands/stars.rb +7 -6
  46. data/bin/commands/team.rb +1 -0
  47. data/bin/commands/team_billing.rb +13 -0
  48. data/bin/commands/team_preferences.rb +13 -0
  49. data/bin/commands/tooling_tokens.rb +14 -0
  50. data/bin/commands/usergroups.rb +1 -1
  51. data/bin/commands/users.rb +1 -1
  52. data/bin/commands/views.rb +1 -1
  53. data/bin/commands.rb +8 -9
  54. data/lib/slack/config.rb +1 -2
  55. data/lib/slack/events/request.rb +5 -3
  56. data/lib/slack/real_time/client.rb +6 -7
  57. data/lib/slack/real_time/concurrency/async.rb +6 -8
  58. data/lib/slack/real_time/config.rb +3 -13
  59. data/lib/slack/real_time/socket.rb +1 -2
  60. data/lib/slack/real_time/stores/base.rb +1 -6
  61. data/lib/slack/real_time/stores/starter.rb +6 -3
  62. data/lib/slack/real_time/stores/store.rb +5 -0
  63. data/lib/slack/version.rb +1 -1
  64. data/lib/slack/web/api/endpoints/admin_analytics.rb +5 -3
  65. data/lib/slack/web/api/endpoints/admin_apps.rb +21 -5
  66. data/lib/slack/web/api/endpoints/admin_apps_approved.rb +2 -2
  67. data/lib/slack/web/api/endpoints/admin_apps_requests.rb +20 -2
  68. data/lib/slack/web/api/endpoints/admin_apps_restricted.rb +2 -2
  69. data/lib/slack/web/api/endpoints/admin_auth_policy.rb +72 -0
  70. data/lib/slack/web/api/endpoints/admin_barriers.rb +6 -6
  71. data/lib/slack/web/api/endpoints/admin_conversations.rb +28 -26
  72. data/lib/slack/web/api/endpoints/admin_conversations_ekm.rb +4 -4
  73. data/lib/slack/web/api/endpoints/admin_emoji.rb +11 -11
  74. data/lib/slack/web/api/endpoints/admin_inviteRequests.rb +7 -7
  75. data/lib/slack/web/api/endpoints/admin_inviteRequests_approved.rb +3 -3
  76. data/lib/slack/web/api/endpoints/admin_inviteRequests_denied.rb +2 -2
  77. data/lib/slack/web/api/endpoints/admin_teams.rb +7 -7
  78. data/lib/slack/web/api/endpoints/admin_teams_admins.rb +2 -2
  79. data/lib/slack/web/api/endpoints/admin_teams_owners.rb +2 -2
  80. data/lib/slack/web/api/endpoints/admin_teams_settings.rb +5 -5
  81. data/lib/slack/web/api/endpoints/admin_usergroups.rb +10 -10
  82. data/lib/slack/web/api/endpoints/admin_users.rb +20 -18
  83. data/lib/slack/web/api/endpoints/admin_users_session.rb +65 -9
  84. data/lib/slack/web/api/endpoints/admin_users_unsupportedVersions.rb +25 -0
  85. data/lib/slack/web/api/endpoints/api.rb +1 -1
  86. data/lib/slack/web/api/endpoints/apps.rb +2 -2
  87. data/lib/slack/web/api/endpoints/apps_event_authorizations.rb +3 -3
  88. data/lib/slack/web/api/endpoints/apps_manifest.rb +77 -0
  89. data/lib/slack/web/api/endpoints/auth.rb +1 -1
  90. data/lib/slack/web/api/endpoints/auth_teams.rb +3 -3
  91. data/lib/slack/web/api/endpoints/bookmarks.rb +86 -0
  92. data/lib/slack/web/api/endpoints/bots.rb +2 -2
  93. data/lib/slack/web/api/endpoints/calls.rb +15 -15
  94. data/lib/slack/web/api/endpoints/calls_participants.rb +4 -4
  95. data/lib/slack/web/api/endpoints/channels.rb +0 -265
  96. data/lib/slack/web/api/endpoints/chat.rb +67 -57
  97. data/lib/slack/web/api/endpoints/chat_scheduledMessages.rb +3 -3
  98. data/lib/slack/web/api/endpoints/conversations.rb +117 -27
  99. data/lib/slack/web/api/endpoints/dialog.rb +2 -2
  100. data/lib/slack/web/api/endpoints/dnd.rb +6 -3
  101. data/lib/slack/web/api/endpoints/files.rb +16 -14
  102. data/lib/slack/web/api/endpoints/files_comments.rb +1 -1
  103. data/lib/slack/web/api/endpoints/files_remote.rb +20 -20
  104. data/lib/slack/web/api/endpoints/groups.rb +0 -273
  105. data/lib/slack/web/api/endpoints/im.rb +0 -107
  106. data/lib/slack/web/api/endpoints/migration.rb +3 -3
  107. data/lib/slack/web/api/endpoints/mpim.rb +0 -102
  108. data/lib/slack/web/api/endpoints/oauth.rb +5 -27
  109. data/lib/slack/web/api/endpoints/oauth_v2.rb +24 -6
  110. data/lib/slack/web/api/endpoints/openid_connect.rb +42 -0
  111. data/lib/slack/web/api/endpoints/pins.rb +4 -4
  112. data/lib/slack/web/api/endpoints/reactions.rb +12 -12
  113. data/lib/slack/web/api/endpoints/reminders.rb +17 -5
  114. data/lib/slack/web/api/endpoints/rtm.rb +10 -10
  115. data/lib/slack/web/api/endpoints/search.rb +24 -16
  116. data/lib/slack/web/api/endpoints/stars.rb +11 -9
  117. data/lib/slack/web/api/endpoints/team.rb +10 -8
  118. data/lib/slack/web/api/endpoints/team_billing.rb +21 -0
  119. data/lib/slack/web/api/endpoints/team_preferences.rb +21 -0
  120. data/lib/slack/web/api/endpoints/team_profile.rb +1 -1
  121. data/lib/slack/web/api/endpoints/tooling_tokens.rb +24 -0
  122. data/lib/slack/web/api/endpoints/usergroups.rb +19 -19
  123. data/lib/slack/web/api/endpoints/usergroups_users.rb +7 -7
  124. data/lib/slack/web/api/endpoints/users.rb +16 -16
  125. data/lib/slack/web/api/endpoints/users_profile.rb +4 -4
  126. data/lib/slack/web/api/endpoints/views.rb +12 -12
  127. data/lib/slack/web/api/endpoints/workflows.rb +9 -9
  128. data/lib/slack/web/api/endpoints.rb +16 -20
  129. data/lib/slack/web/api/errors/server_error.rb +37 -0
  130. data/lib/slack/web/api/errors/too_many_requests_error.rb +1 -4
  131. data/lib/slack/web/api/errors.rb +232 -16
  132. data/lib/slack/web/api/mixins.rb +0 -2
  133. data/lib/slack/web/api/patches/chat.1.patch +7 -9
  134. data/lib/slack/web/api/templates/endpoints.erb +0 -2
  135. data/lib/slack/web/faraday/connection.rb +5 -5
  136. data/lib/slack/web/faraday/request.rb +4 -1
  137. data/lib/slack/web/faraday/response/raise_error.rb +2 -14
  138. data/lib/slack/web/faraday/response/wrap_error.rb +11 -5
  139. data/lib/slack/web/pagination/cursor.rb +1 -5
  140. data/lib/slack-ruby-client.rb +3 -2
  141. data/lib/tasks/real_time.rake +1 -3
  142. data/lib/tasks/web.rake +4 -0
  143. data/slack-ruby-client.gemspec +5 -14
  144. data/spec/fixtures/slack/web/429_error.yml +50 -54
  145. data/spec/fixtures/slack/web/auth_test_error.yml +51 -18
  146. data/spec/fixtures/slack/web/auth_test_success.yml +50 -26
  147. data/spec/fixtures/slack/web/conversations_info.yml +167 -0
  148. data/spec/fixtures/slack/web/conversations_setTopic.yml +42 -27
  149. data/spec/fixtures/slack/web/conversations_setTopic_one_page.yml +89 -59
  150. data/spec/fixtures/slack/web/conversations_setTopic_paginated.yml +131 -86
  151. data/spec/fixtures/slack/web/paginated_users_list.yml +501 -69
  152. data/spec/fixtures/slack/web/rtm_connect.yml +267 -30
  153. data/spec/fixtures/slack/web/rtm_start.yml +771 -60
  154. data/spec/fixtures/slack/web/users_info.yml +153 -69
  155. data/spec/fixtures/slack/web/users_list.yml +102 -41
  156. data/spec/fixtures/slack/web/views_open_error.yml +49 -42
  157. data/spec/integration/integration_spec.rb +1 -1
  158. data/spec/slack/events/request_spec.rb +7 -6
  159. data/spec/slack/real_time/client_spec.rb +37 -39
  160. data/spec/slack/real_time/concurrency/with_concurrency_spec.rb +10 -0
  161. data/spec/slack/real_time/concurrency/without_concurrency_spec.rb +10 -0
  162. data/spec/slack/real_time/event_handlers/bot_spec.rb +1 -1
  163. data/spec/slack/real_time/event_handlers/channel_spec.rb +9 -9
  164. data/spec/slack/real_time/event_handlers/group_spec.rb +2 -2
  165. data/spec/slack/real_time/event_handlers/im_spec.rb +7 -7
  166. data/spec/slack/real_time/event_handlers/user_spec.rb +2 -2
  167. data/spec/slack/real_time/rtm_connect_spec.rb +1 -1
  168. data/spec/slack/real_time/rtm_start_spec.rb +1 -1
  169. data/spec/slack/real_time/store_spec.rb +2 -2
  170. data/spec/slack/slack_spec.rb +7 -5
  171. data/spec/slack/version_spec.rb +1 -1
  172. data/spec/slack/web/api/endpoints/admin_apps_requests_spec.rb +5 -0
  173. data/spec/slack/web/api/endpoints/admin_apps_spec.rb +5 -0
  174. data/spec/slack/web/api/endpoints/admin_auth_policy_spec.rb +35 -0
  175. data/spec/slack/web/api/endpoints/admin_conversations_spec.rb +9 -9
  176. data/spec/slack/web/api/endpoints/admin_teams_settings_spec.rb +1 -1
  177. data/spec/slack/web/api/endpoints/admin_usergroups_spec.rb +6 -6
  178. data/spec/slack/web/api/endpoints/admin_users_session_spec.rb +22 -2
  179. data/spec/slack/web/api/endpoints/admin_users_spec.rb +8 -8
  180. data/spec/slack/web/api/endpoints/admin_users_unsupportedVersions_spec.rb +8 -0
  181. data/spec/slack/web/api/endpoints/apps_manifest_spec.rb +36 -0
  182. data/spec/slack/web/api/endpoints/apps_spec.rb +2 -2
  183. data/spec/slack/web/api/endpoints/bookmarks_spec.rb +40 -0
  184. data/spec/slack/web/api/endpoints/calls_participants_spec.rb +4 -4
  185. data/spec/slack/web/api/endpoints/calls_spec.rb +2 -2
  186. data/spec/slack/web/api/endpoints/custom_specs/auth_spec.rb +4 -6
  187. data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +28 -16
  188. data/spec/slack/web/api/endpoints/custom_specs/conversations_spec.rb +13 -0
  189. data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +4 -2
  190. data/spec/slack/web/api/endpoints/custom_specs/users_spec.rb +2 -2
  191. data/spec/slack/web/api/endpoints/custom_specs/views_spec.rb +22 -14
  192. data/spec/slack/web/api/endpoints/dnd_spec.rb +0 -5
  193. data/spec/slack/web/api/endpoints/files_comments_spec.rb +2 -2
  194. data/spec/slack/web/api/endpoints/files_remote_spec.rb +3 -3
  195. data/spec/slack/web/api/endpoints/oauth_spec.rb +0 -11
  196. data/spec/slack/web/api/endpoints/oauth_v2_spec.rb +6 -3
  197. data/spec/slack/web/api/endpoints/{apps_permissions_scopes_spec.rb → openid_connect_spec.rb} +1 -1
  198. data/spec/slack/web/api/endpoints/reactions_spec.rb +3 -3
  199. data/spec/slack/web/api/endpoints/reminders_spec.rb +2 -2
  200. data/spec/slack/web/api/endpoints/{apps_permissions_resources_spec.rb → team_billing_spec.rb} +1 -1
  201. data/spec/slack/web/api/endpoints/team_preferences_spec.rb +8 -0
  202. data/spec/slack/web/api/endpoints/tooling_tokens_spec.rb +13 -0
  203. data/spec/slack/web/api/endpoints/usergroups_users_spec.rb +2 -2
  204. data/spec/slack/web/api/error_spec.rb +5 -7
  205. data/spec/slack/web/api/errors/slack_error_spec.rb +21 -26
  206. data/spec/slack/web/api/mixins/conversations_list_spec.rb +1 -1
  207. data/spec/slack/web/api/pagination/cursor_spec.rb +8 -10
  208. data/spec/slack/web/client_spec.rb +46 -32
  209. data/spec/slack/web/faraday/request_spec.rb +80 -0
  210. data/spec/slack/web/faraday/response/raise_error_spec.rb +2 -1
  211. data/spec/spec_helper.rb +1 -1
  212. data/spec/support/real_time/connected_client.rb +2 -8
  213. data/spec/support/vcr.rb +33 -2
  214. metadata +50 -297
  215. data/.travis.yml +0 -28
  216. data/lib/slack/web/api/errors/internal_error.rb +0 -14
  217. data/lib/slack/web/api/mixins/channels.id.json +0 -20
  218. data/lib/slack/web/api/mixins/channels.id.rb +0 -25
  219. data/lib/slack/web/api/mixins/groups.id.json +0 -20
  220. data/lib/slack/web/api/mixins/groups.id.rb +0 -25
  221. data/spec/fixtures/slack/web/503_error.yml +0 -14
  222. data/spec/fixtures/slack/web/channels_info.yml +0 -139
  223. data/spec/fixtures/slack/web/groups_info.yml +0 -43
  224. data/spec/slack/web/api/endpoints/admin_conversations_whitelist_spec.rb +0 -32
  225. data/spec/slack/web/api/endpoints/apps_permissions_spec.rb +0 -16
  226. data/spec/slack/web/api/endpoints/apps_permissions_users_spec.rb +0 -19
  227. data/spec/slack/web/api/endpoints/conversations_spec.rb +0 -109
  228. data/spec/slack/web/api/endpoints/custom_specs/channels_spec.rb +0 -13
  229. data/spec/slack/web/api/endpoints/custom_specs/groups_spec.rb +0 -13
  230. data/spec/slack/web/api/endpoints/im_spec.rb +0 -39
  231. data/spec/slack/web/api/endpoints/mpim_spec.rb +0 -39
  232. data/spec/slack/web/api/endpoints/views_spec.rb +0 -29
  233. data/spec/slack/web/api/mixins/channels_spec.rb +0 -43
  234. data/spec/slack/web/api/mixins/groups_spec.rb +0 -43
@@ -0,0 +1,8 @@
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::TeamPreferences do
7
+ let(:client) { Slack::Web::Client.new }
8
+ 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::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[U060R4BJ4,U060RNRCZ]) }.to raise_error ArgumentError, /Required arguments :usergroup missing/
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[S0604QSJC]) }.to raise_error ArgumentError, /Required arguments :users missing/
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
- begin
9
- client.auth_test
10
- raise 'Expected to receive Slack::Web::Api::Error.'
11
- rescue described_class => e
12
- expect(e.response).not_to be_nil
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
- begin
9
- client.auth_test
10
- raise 'Expected to receive Slack::Web::Api::Errors::SlackError.'
11
- rescue described_class => e
12
- expect(e.response).not_to be_nil
13
- expect(e.response.status).to eq 200
14
- expect(e.message).to eql 'not_authed'
15
- expect(e.error).to eql 'not_authed'
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
- begin
22
- client.views_open(trigger_id: 'trigger_id', view: {})
23
- raise 'Expected to receive Slack::Web::Api::Errors::SlackError.'
24
- rescue described_class => e
25
- expect(e.response).not_to be_nil
26
- expect(e.response.status).to eq 200
27
- expect(e.message).to eql 'invalid_arguments'
28
- expect(e.error).to eql 'invalid_arguments'
29
- expect(e.response_metadata).to eq(
30
- 'messages' => [
31
- "[ERROR] missing required field: title [json-pointer:\/view]",
32
- "[ERROR] missing required field: blocks [json-pointer:\/view]",
33
- "[ERROR] missing required field: type [json-pointer:\/view]"
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: 'C018Y6VH39D', topic: 'new topic' })
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(nil) }
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.body = { token: 'token' }
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
- begin
285
- request
286
- rescue Slack::Web::Api::Errors::ServerError => e
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
- before { stub_slack_request.to_return(body: '<html></html>') }
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
- 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.cause).to be_a(JSON::ParserError)
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
- before { stub_slack_request.to_return(status: 500, body: '{}') }
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
- it 'raises UnavailableError' do
328
- expect { request }.to raise_error(Slack::Web::Api::Errors::UnavailableError).with_message('unavailable_error')
329
- expect(exception.cause).to be_a(Faraday::ServerError)
330
- expect(exception.response.status).to eq(500)
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 eq nil
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) do
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