slack-ruby-client 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/{integtest.yml → integration_test.yml} +6 -5
  3. data/.github/workflows/{rubocop.yml → lint.yml} +5 -4
  4. data/.github/workflows/{danger.yml → pr_lint.yml} +8 -6
  5. data/.github/workflows/test.yml +4 -2
  6. data/.gitignore +0 -1
  7. data/.rubocop.yml +4 -0
  8. data/.rubocop_todo.yml +8 -14
  9. data/.ruby-version +1 -0
  10. data/CHANGELOG.md +14 -0
  11. data/CONTRIBUTING.md +5 -4
  12. data/Gemfile +1 -6
  13. data/README.md +60 -63
  14. data/RELEASING.md +1 -1
  15. data/UPGRADING.md +28 -0
  16. data/bin/commands/admin_audit_anomaly_allow.rb +23 -0
  17. data/bin/commands/admin_conversations.rb +12 -11
  18. data/bin/commands/admin_users.rb +1 -1
  19. data/bin/commands/admin_users_session.rb +1 -1
  20. data/bin/commands/apps_connections.rb +2 -2
  21. data/bin/commands/bookmarks.rb +1 -0
  22. data/bin/commands/chat.rb +9 -6
  23. data/bin/commands/conversations.rb +8 -6
  24. data/bin/commands/files.rb +24 -0
  25. data/bin/commands/rtm.rb +0 -15
  26. data/bin/commands/views.rb +4 -2
  27. data/bin/commands.rb +1 -0
  28. data/bin/slack +1 -1
  29. data/lib/slack/real_time/api/message.rb +3 -2
  30. data/lib/slack/real_time/api/templates/event_handler.erb +5 -1
  31. data/lib/slack/real_time/api/typing.rb +2 -1
  32. data/lib/slack/real_time/client.rb +8 -26
  33. data/lib/slack/real_time/config.rb +3 -3
  34. data/lib/slack/real_time/models/channel.rb +4 -0
  35. data/lib/slack/real_time/models/{group.rb → mpim.rb} +1 -1
  36. data/lib/slack/real_time/models.rb +2 -1
  37. data/lib/slack/real_time/stores/base.rb +25 -9
  38. data/lib/slack/real_time/stores/starter.rb +323 -309
  39. data/lib/slack/real_time/stores/store.rb +265 -198
  40. data/lib/slack/real_time/stores.rb +1 -7
  41. data/lib/slack/version.rb +1 -1
  42. data/lib/slack/web/api/endpoints/admin_analytics.rb +1 -1
  43. data/lib/slack/web/api/endpoints/admin_apps.rb +2 -2
  44. data/lib/slack/web/api/endpoints/admin_apps_requests.rb +1 -1
  45. data/lib/slack/web/api/endpoints/admin_audit_anomaly_allow.rb +34 -0
  46. data/lib/slack/web/api/endpoints/admin_auth_policy.rb +7 -7
  47. data/lib/slack/web/api/endpoints/admin_barriers.rb +8 -8
  48. data/lib/slack/web/api/endpoints/admin_conversations.rb +30 -28
  49. data/lib/slack/web/api/endpoints/admin_conversations_restrictAccess.rb +6 -6
  50. data/lib/slack/web/api/endpoints/admin_emoji.rb +7 -7
  51. data/lib/slack/web/api/endpoints/admin_inviteRequests.rb +2 -2
  52. data/lib/slack/web/api/endpoints/admin_teams.rb +2 -2
  53. data/lib/slack/web/api/endpoints/admin_teams_admins.rb +1 -1
  54. data/lib/slack/web/api/endpoints/admin_teams_owners.rb +1 -1
  55. data/lib/slack/web/api/endpoints/admin_teams_settings.rb +11 -11
  56. data/lib/slack/web/api/endpoints/admin_usergroups.rb +7 -7
  57. data/lib/slack/web/api/endpoints/admin_users.rb +16 -16
  58. data/lib/slack/web/api/endpoints/admin_users_session.rb +8 -8
  59. data/lib/slack/web/api/endpoints/apps.rb +2 -2
  60. data/lib/slack/web/api/endpoints/apps_connections.rb +1 -1
  61. data/lib/slack/web/api/endpoints/apps_event_authorizations.rb +1 -1
  62. data/lib/slack/web/api/endpoints/apps_manifest.rb +6 -6
  63. data/lib/slack/web/api/endpoints/bookmarks.rb +10 -8
  64. data/lib/slack/web/api/endpoints/bots.rb +1 -1
  65. data/lib/slack/web/api/endpoints/calls.rb +5 -5
  66. data/lib/slack/web/api/endpoints/calls_participants.rb +4 -4
  67. data/lib/slack/web/api/endpoints/chat.rb +36 -30
  68. data/lib/slack/web/api/endpoints/conversations.rb +37 -33
  69. data/lib/slack/web/api/endpoints/dialog.rb +2 -2
  70. data/lib/slack/web/api/endpoints/dnd.rb +1 -1
  71. data/lib/slack/web/api/endpoints/files.rb +45 -8
  72. data/lib/slack/web/api/endpoints/files_comments.rb +2 -2
  73. data/lib/slack/web/api/endpoints/files_remote.rb +8 -8
  74. data/lib/slack/web/api/endpoints/migration.rb +1 -1
  75. data/lib/slack/web/api/endpoints/oauth_v2.rb +2 -2
  76. data/lib/slack/web/api/endpoints/pins.rb +3 -3
  77. data/lib/slack/web/api/endpoints/reactions.rb +4 -4
  78. data/lib/slack/web/api/endpoints/reminders.rb +5 -5
  79. data/lib/slack/web/api/endpoints/rtm.rb +0 -23
  80. data/lib/slack/web/api/endpoints/search.rb +3 -3
  81. data/lib/slack/web/api/endpoints/tooling_tokens.rb +1 -1
  82. data/lib/slack/web/api/endpoints/usergroups.rb +4 -4
  83. data/lib/slack/web/api/endpoints/usergroups_users.rb +3 -3
  84. data/lib/slack/web/api/endpoints/users.rb +4 -4
  85. data/lib/slack/web/api/endpoints/users_admin.rb +2 -2
  86. data/lib/slack/web/api/endpoints/views.rb +16 -11
  87. data/lib/slack/web/api/endpoints/workflows.rb +4 -4
  88. data/lib/slack/web/api/endpoints.rb +2 -0
  89. data/lib/slack/web/api/errors.rb +56 -6
  90. data/lib/slack/web/api/mixins/conversations.id.rb +1 -1
  91. data/lib/slack/web/api/mixins/users.id.rb +1 -1
  92. data/lib/slack/web/api/mixins/users.search.rb +2 -1
  93. data/lib/slack/web/api/patches/{chat.1.patch → chat.attachments-blocks.patch} +13 -14
  94. data/lib/slack/web/api/patches/{dialog.1.open-json-support.patch → dialog.encoded-json.patch} +4 -4
  95. data/lib/slack/web/api/patches/views.view-json.patch +55 -0
  96. data/lib/slack/web/api/templates/method.erb +1 -1
  97. data/lib/slack/web/config.rb +2 -2
  98. data/lib/tasks/real_time.rake +44 -22
  99. data/lib/tasks/web.rake +9 -2
  100. data/spec/fixtures/slack/web/rtm_connect.yml +85 -1
  101. data/spec/slack/events/config_spec.rb +2 -0
  102. data/spec/slack/events/request_spec.rb +4 -0
  103. data/spec/slack/messages/formatting_spec.rb +10 -0
  104. data/spec/slack/real_time/api/message_spec.rb +1 -1
  105. data/spec/slack/real_time/api/ping_spec.rb +1 -1
  106. data/spec/slack/real_time/api/typing_spec.rb +1 -1
  107. data/spec/slack/real_time/client_spec.rb +73 -111
  108. data/spec/slack/real_time/event_handlers/bot_spec.rb +19 -17
  109. data/spec/slack/real_time/event_handlers/event_handlers_spec.rb +1 -1
  110. data/spec/slack/real_time/event_handlers/im_spec.rb +28 -25
  111. data/spec/slack/real_time/event_handlers/{group_spec.rb → private_channel_spec.rb} +35 -27
  112. data/spec/slack/real_time/event_handlers/{channel_spec.rb → public_channel_spec.rb} +24 -20
  113. data/spec/slack/real_time/event_handlers/team_spec.rb +7 -8
  114. data/spec/slack/real_time/event_handlers/user_spec.rb +6 -5
  115. data/spec/slack/real_time/stores/store_spec.rb +50 -0
  116. data/spec/slack/slack_spec.rb +1 -0
  117. data/spec/slack/web/api/endpoints/admin_audit_anomaly_allow_spec.rb +8 -0
  118. data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +17 -1
  119. data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +2 -0
  120. data/spec/slack/web/api/endpoints/custom_specs/views_spec.rb +13 -4
  121. data/spec/slack/web/api/endpoints/files_spec.rb +13 -0
  122. data/spec/slack/web/api/mixins/conversations_spec.rb +2 -0
  123. data/spec/slack/web/api/mixins/users_spec.rb +2 -0
  124. data/spec/slack/web/api/pagination/cursor_spec.rb +4 -0
  125. data/spec/slack/web/client_spec.rb +14 -4
  126. data/spec/support/real_time/loaded_client.rb +120 -0
  127. metadata +18 -35
  128. data/bin/commands/admin_conversations_whitelist.rb +0 -37
  129. data/bin/commands/apps_permissions.rb +0 -23
  130. data/bin/commands/apps_permissions_resources.rb +0 -15
  131. data/bin/commands/apps_permissions_scopes.rb +0 -13
  132. data/bin/commands/apps_permissions_users.rb +0 -26
  133. data/bin/commands/channels.rb +0 -23
  134. data/bin/commands/groups.rb +0 -14
  135. data/bin/commands/im.rb +0 -6
  136. data/bin/commands/mpim.rb +0 -6
  137. data/lib/slack/web/api/endpoints/admin_conversations_whitelist.rb +0 -64
  138. data/lib/slack/web/api/endpoints/apps_permissions.rb +0 -36
  139. data/lib/slack/web/api/endpoints/apps_permissions_resources.rb +0 -31
  140. data/lib/slack/web/api/endpoints/apps_permissions_scopes.rb +0 -21
  141. data/lib/slack/web/api/endpoints/apps_permissions_users.rb +0 -50
  142. data/lib/slack/web/api/endpoints/channels.rb +0 -25
  143. data/lib/slack/web/api/endpoints/groups.rb +0 -13
  144. data/lib/slack/web/api/endpoints/im.rb +0 -13
  145. data/lib/slack/web/api/endpoints/mpim.rb +0 -13
  146. data/lib/slack/web/api/endpoints/presence.rb +0 -23
  147. data/lib/slack/web/api/patches/views.1.view-json.patch +0 -40
  148. data/lib/slack/web/api/patches/views.1.views-published.patch +0 -16
  149. data/spec/fixtures/slack/web/rtm_start.yml +0 -815
  150. data/spec/slack/real_time/rtm_start_spec.rb +0 -14
  151. data/spec/slack/real_time/store_spec.rb +0 -12
@@ -1,15 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
  require 'spec_helper'
3
3
 
4
- RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' } do
4
+ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_connect' } do
5
5
  include_context 'connected client'
6
+ include_context 'loaded client'
6
7
 
7
- context 'channel' do
8
- it 'sets channel data' do
9
- expect(client.channels.count).to eq 156
10
- end
8
+ context 'public channel' do
11
9
  it 'channel_archive' do
12
- channel = client.channels['C0HNTD0CW']
10
+ channel = client.public_channels['C0HNTD0CW']
13
11
  expect(channel.is_archived).to be false
14
12
  event = Slack::RealTime::Event.new(
15
13
  'type' => 'channel_archive',
@@ -19,36 +17,39 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
19
17
  client.send(:dispatch, event)
20
18
  expect(channel.is_archived).to be true
21
19
  end
20
+
22
21
  it 'channel_created' do
23
- expect(client.channels['C024BE91L']).to be_nil
22
+ expect(client.public_channels['C024BE91L']).to be_nil
24
23
  event = Slack::RealTime::Event.new(
25
24
  'type' => 'channel_created',
26
25
  'channel' => {
27
26
  'id' => 'C024BE91L',
28
27
  'name' => 'fun',
29
- 'created' => 1_360_782_804,
28
+ 'created' => 1360782804,
30
29
  'creator' => 'U04KB5WQR'
31
30
  }
32
31
  )
33
32
  client.send(:dispatch, event)
34
- channel = client.channels['C024BE91L']
33
+ channel = client.public_channels['C024BE91L']
35
34
  expect(channel).not_to be_nil
36
35
  expect(channel.name).to eq 'fun'
37
36
  expect(channel.creator).to eq 'U04KB5WQR'
38
- expect(channel.created).to eq 1_360_782_804
37
+ expect(channel.created).to eq 1360782804
39
38
  end
39
+
40
40
  it 'channel_deleted' do
41
- expect(client.channels['C0HLE0BBL']).not_to be_nil
41
+ expect(client.public_channels['C0HLE0BBL']).not_to be_nil
42
42
  event = Slack::RealTime::Event.new(
43
43
  'type' => 'channel_deleted',
44
44
  'channel' => 'C0HLE0BBL'
45
45
  )
46
46
  client.send(:dispatch, event)
47
- expect(client.channels['C0HLE0BBL']).to be_nil
47
+ expect(client.public_channels['C0HLE0BBL']).to be_nil
48
48
  end
49
+
49
50
  context 'channel_joined' do
50
51
  it 'creates channel' do
51
- expect(client.channels['CDEADBEEF']).to be_nil
52
+ expect(client.public_channels['CDEADBEEF']).to be_nil
52
53
  event = Slack::RealTime::Event.new(
53
54
  'type' => 'channel_joined',
54
55
  'channel' => {
@@ -57,13 +58,14 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
57
58
  }
58
59
  )
59
60
  client.send(:dispatch, event)
60
- channel = client.channels['CDEADBEEF']
61
+ channel = client.public_channels['CDEADBEEF']
61
62
  expect(channel).not_to be_nil
62
63
  expect(channel.name).to eq 'beef'
63
64
  end
65
+
64
66
  it 'updates channel' do
65
- expect(client.channels['CDEADBEEF']).to be_nil
66
- client.channels['CDEADBEEF'] =
67
+ expect(client.public_channels['CDEADBEEF']).to be_nil
68
+ client.public_channels['CDEADBEEF'] =
67
69
  Slack::RealTime::Models::Channel.new('id' => 'CDEADBEEF', name: 'beef')
68
70
  event = Slack::RealTime::Event.new(
69
71
  'type' => 'channel_joined',
@@ -74,14 +76,14 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
74
76
  }
75
77
  )
76
78
  client.send(:dispatch, event)
77
- channel = client.channels['CDEADBEEF']
79
+ channel = client.public_channels['CDEADBEEF']
78
80
  expect(channel).not_to be_nil
79
81
  expect(channel.updated).to be true
80
82
  end
81
83
  end
82
84
 
83
85
  it 'channel_left' do
84
- channel = client.channels['C0JHNAB5H']
86
+ channel = client.public_channels['C0JHNAB5H']
85
87
  expect(channel.members).to include client.self.id
86
88
  event = Slack::RealTime::Event.new(
87
89
  'type' => 'channel_left',
@@ -90,8 +92,9 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
90
92
  client.send(:dispatch, event)
91
93
  expect(channel.members).not_to include client.self.id
92
94
  end
95
+
93
96
  it 'channel_rename' do
94
- channel = client.channels['C0HLE0BBL']
97
+ channel = client.public_channels['C0HLE0BBL']
95
98
  expect(channel.name).to eq 'gifs'
96
99
  event = Slack::RealTime::Event.new(
97
100
  'type' => 'channel_rename',
@@ -104,8 +107,9 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
104
107
  client.send(:dispatch, event)
105
108
  expect(channel.name).to eq 'updated'
106
109
  end
110
+
107
111
  it 'channel_unarchive' do
108
- channel = client.channels['C0HLE0BBL']
112
+ channel = client.public_channels['C0HLE0BBL']
109
113
  expect(channel.is_archived).to be true
110
114
  event = Slack::RealTime::Event.new(
111
115
  'type' => 'channel_unarchive',
@@ -2,20 +2,15 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  [Slack::RealTime::Stores::Store, Slack::RealTime::Stores::Starter].each do |store_class|
5
- cassette = store_class == Slack::RealTime::Stores::Store ? 'web/rtm_start' : 'web/rtm_connect'
6
- RSpec.describe store_class, vcr: { cassette_name: cassette } do
5
+ RSpec.describe store_class, vcr: { cassette_name: 'web/rtm_connect' } do
7
6
  include_context 'connected client', store_class: store_class
8
7
 
9
8
  context 'team' do
10
- it 'sets team data on rtm.start' do
9
+ it 'sets team data on rtm.connect' do
11
10
  expect(client.team.name).to eq 'dblock'
12
11
  expect(client.team.domain).to eq 'dblockdotorg'
13
- if store_class == Slack::RealTime::Stores::Store
14
- expect(client.team.email_domain).to eq 'dblock.org'
15
- expect(client.team.prefs.invites_only_admins).to be true
16
- expect(client.team.plan).to eq ''
17
- end
18
12
  end
13
+
19
14
  it 'team_domain_change' do
20
15
  event = Slack::RealTime::Event.new(
21
16
  'type' => 'team_domain_change',
@@ -26,6 +21,7 @@ require 'spec_helper'
26
21
  expect(client.team.domain).to eq 'my'
27
22
  expect(client.team['url']).to eq 'https://my.slack.com'
28
23
  end
24
+
29
25
  it 'email_domain_changed' do
30
26
  event = Slack::RealTime::Event.new(
31
27
  'type' => 'email_domain_changed',
@@ -34,6 +30,7 @@ require 'spec_helper'
34
30
  client.send(:dispatch, event)
35
31
  expect(client.team.email_domain).to eq 'example.com'
36
32
  end
33
+
37
34
  it 'team_pref_change' do
38
35
  event = Slack::RealTime::Event.new(
39
36
  'type' => 'team_pref_change',
@@ -43,6 +40,7 @@ require 'spec_helper'
43
40
  client.send(:dispatch, event)
44
41
  expect(client.team.prefs.invites_only_admins).to be false
45
42
  end
43
+
46
44
  it 'team_rename' do
47
45
  event = Slack::RealTime::Event.new(
48
46
  'type' => 'team_rename',
@@ -51,6 +49,7 @@ require 'spec_helper'
51
49
  client.send(:dispatch, event)
52
50
  expect(client.team.name).to eq 'New Team Name Inc.'
53
51
  end
52
+
54
53
  it 'team_plan_change' do
55
54
  event = Slack::RealTime::Event.new(
56
55
  'type' => 'team_plan_change',
@@ -1,14 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
  require 'spec_helper'
3
3
 
4
- RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' } do
4
+ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_connect' } do
5
5
  include_context 'connected client'
6
+ include_context 'loaded client'
6
7
 
7
8
  context 'user' do
8
- it 'combines user and self data on rtm.start' do
9
- expect(client.users['U0J1GAHN1'].name).to eq 'travis-ci'
10
- expect(client.users['U0J1GAHN1']['prefs']['push_sound']).to eq 'b2.mp3'
11
- end
12
9
  it 'user_change' do
13
10
  expect(client.users['U07KECJ77'].name).to eq 'aws'
14
11
  event = Slack::RealTime::Event.new(
@@ -20,6 +17,7 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
20
17
  client.send(:dispatch, event)
21
18
  expect(client.users['U07KECJ77'].name).to eq 'renamed'
22
19
  end
20
+
23
21
  it 'team_join' do
24
22
  expect do
25
23
  event = Slack::RealTime::Event.new(
@@ -32,6 +30,7 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
32
30
  end.to change(client.users, :count).by(1)
33
31
  expect(client.users['DEADBEEF'].name).to eq 'added'
34
32
  end
33
+
35
34
  it 'pref_change' do
36
35
  event = Slack::RealTime::Event.new(
37
36
  'type' => 'pref_change',
@@ -41,6 +40,7 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
41
40
  client.send(:dispatch, event)
42
41
  expect(client.self.prefs['push_sound']).to eq 'updated.mp3'
43
42
  end
43
+
44
44
  it 'presence_change' do
45
45
  expect(client.users['U07KECJ77'].presence).to eq 'away'
46
46
  event = Slack::RealTime::Event.new(
@@ -51,6 +51,7 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
51
51
  client.send(:dispatch, event)
52
52
  expect(client.users['U07KECJ77'].presence).to eq 'updated'
53
53
  end
54
+
54
55
  it 'manual_presence_change' do
55
56
  expect(client.self['presence']).to eq 'away'
56
57
  event = Slack::RealTime::Event.new(
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Slack::RealTime::Stores::Store do
6
+ it 'can be initialized with an empty hash' do
7
+ store = described_class.new(Hashie::Mash.new)
8
+ expect(store.team).to be_nil
9
+ expect(store.teams.count).to eq 0
10
+ expect(store.self).to be_nil
11
+ expect(store.public_channels.count).to eq 0
12
+ expect(store.private_channels.count).to eq 0
13
+ end
14
+
15
+ it 'includes event handlers in subclasses' do
16
+ subclass = Class.new(described_class)
17
+ expect(subclass.events.key?('channel_created')).to be true
18
+ end
19
+
20
+ context 'with client started' do
21
+ let(:client) { Slack::RealTime::Client.new(store_class: described_class, concurrency: Slack::RealTime::Concurrency::Mock) }
22
+
23
+ before do
24
+ client.store = described_class.new(Hashie::Mash.new, { caches: :all })
25
+ end
26
+
27
+ it 'initializes itself with data' do
28
+ team_info = Hashie::Mash.new(team: {})
29
+ allow(client.web_client).to receive(:team_info).and_return(team_info)
30
+ expect(client.web_client).to receive(:team_info)
31
+ expect(client.web_client).to receive(:users_list)
32
+ expect(client.web_client).to receive(:conversations_list).with(types: 'public_channel,private_channel,im,mpim')
33
+ event = Slack::RealTime::Event.new('type' => 'hello', 'start' => true)
34
+ client.send(:dispatch, event)
35
+ end
36
+
37
+ context 'when configured to only cache some types' do
38
+ before do
39
+ client.store = described_class.new(Hashie::Mash.new, { caches: %i[users public_channels] })
40
+ end
41
+
42
+ it 'initializes specified caches with data' do
43
+ expect(client.web_client).to receive(:users_list)
44
+ expect(client.web_client).to receive(:conversations_list).with(types: 'public_channel')
45
+ event = Slack::RealTime::Event.new('type' => 'hello', 'start' => true)
46
+ client.send(:dispatch, event)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -30,6 +30,7 @@ describe Slack do
30
30
  expect(output).to include 'POST https://slack.com/api/auth.test'
31
31
  expect(output).to include 'Status 200'
32
32
  end
33
+
33
34
  it 'requires --slack-api-token' do
34
35
  err = `"#{slack}" auth test 2>&1`
35
36
  expect(err).to(
@@ -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::AdminAuditAnomalyAllow do
7
+ let(:client) { Slack::Web::Client.new }
8
+ end
@@ -30,17 +30,20 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
30
30
  blocks: []
31
31
  )
32
32
  end
33
+
33
34
  context 'text and user arguments' do
34
35
  it 'requires text or attachments' do
35
36
  expect { client.chat_postEphemeral(channel: 'channel') }.to(
36
37
  raise_error(ArgumentError, /Required arguments :text, :attachments or :blocks missing/)
37
38
  )
38
39
  end
40
+
39
41
  it 'requires user' do
40
42
  expect { client.chat_postEphemeral(channel: 'channel', text: 'text') }.to(
41
43
  raise_error(ArgumentError, /Required arguments :user missing/)
42
44
  )
43
45
  end
46
+
44
47
  it 'both text and user' do
45
48
  expect(client).to(
46
49
  receive(:post).with('chat.postEphemeral', hash_including(text: 'text', user: '123'))
@@ -60,6 +63,7 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
60
63
  client.chat_postEphemeral(channel: 'channel', text: 'text', user: '123', attachments: [])
61
64
  end.not_to raise_error
62
65
  end
66
+
63
67
  it 'attachments without text' do
64
68
  expect(client).to(
65
69
  receive(:post).with('chat.postEphemeral', hash_including(attachments: '[]'))
@@ -77,6 +81,7 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
77
81
  client.chat_postEphemeral(channel: 'channel', text: 'text', user: '123', blocks: [])
78
82
  end.not_to raise_error
79
83
  end
84
+
80
85
  it 'blocks without text' do
81
86
  expect(client).to receive(:post).with('chat.postEphemeral', hash_including(blocks: '[]'))
82
87
  expect do
@@ -99,24 +104,29 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
99
104
  )
100
105
  client.chat_postMessage(channel: 'channel', text: 'text', attachments: [], blocks: [])
101
106
  end
107
+
102
108
  context 'text, attachment and blocks arguments' do
103
109
  it 'requires text, attachments or blocks' do
104
110
  expect { client.chat_postMessage(channel: 'channel') }.to(
105
111
  raise_error(ArgumentError, /Required arguments :text, :attachments or :blocks missing/)
106
112
  )
107
113
  end
114
+
108
115
  it 'only text' do
109
116
  expect(client).to receive(:post).with('chat.postMessage', hash_including(text: 'text'))
110
117
  expect { client.chat_postMessage(channel: 'channel', text: 'text') }.not_to raise_error
111
118
  end
119
+
112
120
  it 'only attachments' do
113
121
  expect(client).to receive(:post).with('chat.postMessage', hash_including(attachments: '[]'))
114
122
  expect { client.chat_postMessage(channel: 'channel', attachments: []) }.not_to raise_error
115
123
  end
124
+
116
125
  it 'only blocks' do
117
126
  expect(client).to receive(:post).with('chat.postMessage', hash_including(blocks: '[]'))
118
127
  expect { client.chat_postMessage(channel: 'channel', blocks: []) }.not_to raise_error
119
128
  end
129
+
120
130
  it 'all text, attachments and blocks' do
121
131
  expect(client).to(
122
132
  receive(:post)
@@ -145,11 +155,12 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
145
155
  )
146
156
  client.chat_update(channel: 'channel', text: 'text', ts: ts, attachments: [], blocks: [])
147
157
  end
158
+
148
159
  context 'ts arguments' do
149
160
  it 'requires ts' do
150
161
  expect do
151
162
  client.chat_update(channel: 'channel', text: 'text')
152
- end.to raise_error(ArgumentError, /Required arguments :ts missing>/)
163
+ end.to raise_error(ArgumentError, /Required arguments :ts missing/)
153
164
  end
154
165
  end
155
166
 
@@ -159,30 +170,35 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
159
170
  raise_error(ArgumentError, /Required arguments :text, :attachments, :blocks or :reply_broadcast missing/)
160
171
  )
161
172
  end
173
+
162
174
  it 'only text' do
163
175
  expect(client).to receive(:post).with('chat.update', hash_including(text: 'text'))
164
176
  expect do
165
177
  client.chat_update(channel: 'channel', text: 'text', ts: ts)
166
178
  end.not_to raise_error
167
179
  end
180
+
168
181
  it 'only attachments' do
169
182
  expect(client).to receive(:post).with('chat.update', hash_including(attachments: '[]'))
170
183
  expect do
171
184
  client.chat_update(channel: 'channel', ts: ts, attachments: [])
172
185
  end.not_to raise_error
173
186
  end
187
+
174
188
  it 'only blocks' do
175
189
  expect(client).to receive(:post).with('chat.update', hash_including(blocks: '[]'))
176
190
  expect do
177
191
  client.chat_update(channel: 'channel', ts: ts, blocks: [])
178
192
  end.not_to raise_error
179
193
  end
194
+
180
195
  it 'only reply_broadcast' do
181
196
  expect(client).to receive(:post).with('chat.update', hash_including(reply_broadcast: true))
182
197
  expect do
183
198
  client.chat_update(channel: 'channel', ts: ts, reply_broadcast: true)
184
199
  end.not_to raise_error
185
200
  end
201
+
186
202
  it 'all text, attachments and blocks' do
187
203
  expect(client).to(
188
204
  receive(:post)
@@ -22,11 +22,13 @@ RSpec.describe Slack::Web::Api::Endpoints::Dialog do
22
22
  raise_error(ArgumentError, /Required arguments :dialog missing/)
23
23
  )
24
24
  end
25
+
25
26
  it 'requires trigger_id' do
26
27
  expect { client.dialog_open(dialog: []) }.to(
27
28
  raise_error(ArgumentError, /Required arguments :trigger_id missing/)
28
29
  )
29
30
  end
31
+
30
32
  it 'likes both dialog and trigger_id' do
31
33
  expect(client).to(
32
34
  receive(:post).with('dialog.open', hash_including(trigger_id: '123', dialog: '[]'))
@@ -4,6 +4,7 @@ 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
@@ -86,8 +87,8 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
86
87
  let(:view_str) { '{"celery":"man"}' }
87
88
 
88
89
  it 'automatically converts view into JSON' do
89
- expect(client).to receive(:post).with('views.update', { view: view_str })
90
- 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' })
91
92
  end
92
93
  end
93
94
 
@@ -95,8 +96,16 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
95
96
  let(:view_str) { 'celery man' }
96
97
 
97
98
  it 'leaves view as is' do
98
- expect(client).to receive(:post).with('views.update', { view: view_str })
99
- 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
100
109
  end
101
110
  end
102
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/
@@ -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')
@@ -11,16 +11,19 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
11
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
 
@@ -15,6 +15,7 @@ RSpec.describe Slack::Web::Client do
15
15
  expect(client.user_agent).to eq Slack::Web::Config.user_agent
16
16
  expect(client.user_agent).to include Slack::VERSION
17
17
  end
18
+
18
19
  (Slack::Web::Config::ATTRIBUTES - [:logger]).each do |key|
19
20
  it "sets #{key}" do
20
21
  expect(client.send(key)).to eq Slack::Web::Config.send(key)
@@ -56,6 +57,7 @@ RSpec.describe Slack::Web::Client do
56
57
  it 'sets user-agent' do
57
58
  expect(client.user_agent).to eq 'custom/user-agent'
58
59
  end
60
+
59
61
  it 'creates a connection with the custom user-agent' do
60
62
  expect(client.send(:connection).headers).to eq(
61
63
  'Accept' => 'application/json; charset=utf-8',
@@ -76,6 +78,7 @@ RSpec.describe Slack::Web::Client do
76
78
  client = described_class.new
77
79
  expect(client.token).to eq 'global default'
78
80
  end
81
+
79
82
  context 'with web config' do
80
83
  before do
81
84
  described_class.configure do |config|
@@ -87,6 +90,7 @@ RSpec.describe Slack::Web::Client do
87
90
  client = described_class.new
88
91
  expect(client.token).to eq 'custom web token'
89
92
  end
93
+
90
94
  it 'overrides token to specific token' do
91
95
  client = described_class.new(token: 'local token')
92
96
  expect(client.token).to eq 'local token'
@@ -105,6 +109,7 @@ RSpec.describe Slack::Web::Client do
105
109
  it 'sets proxy' do
106
110
  expect(client.proxy).to eq 'http://localhost:8080'
107
111
  end
112
+
108
113
  it 'creates a connection with the proxy' do
109
114
  expect(client.send(:connection).proxy.uri.to_s).to eq 'http://localhost:8080'
110
115
  end
@@ -124,6 +129,7 @@ RSpec.describe Slack::Web::Client do
124
129
  expect(client.ca_path).to eq '/ca_path'
125
130
  expect(client.ca_file).to eq '/ca_file'
126
131
  end
132
+
127
133
  it 'creates a connection with ssl options' do
128
134
  ssl = client.send(:connection).ssl
129
135
  expect(ssl.ca_path).to eq '/ca_path'
@@ -145,6 +151,7 @@ RSpec.describe Slack::Web::Client do
145
151
  it 'sets logger' do
146
152
  expect(client.logger).to eq logger
147
153
  end
154
+
148
155
  it 'creates a connection with a logger' do
149
156
  expect(client.send(:connection).builder.handlers).to include ::Faraday::Response::Logger
150
157
  end
@@ -168,6 +175,7 @@ RSpec.describe Slack::Web::Client do
168
175
  it 'sets adapter' do
169
176
  expect(client.adapter).to eq adapter
170
177
  end
178
+
171
179
  it 'creates a connection with an adapter' do
172
180
  expect(client.send(:connection).adapter).to eq adapter_class
173
181
  end
@@ -188,6 +196,7 @@ RSpec.describe Slack::Web::Client do
188
196
  it 'sets adapter' do
189
197
  expect(client.adapter).to eq adapter
190
198
  end
199
+
191
200
  it 'creates a connection with an adapter' do
192
201
  expect(client.send(:connection).adapter).to eq adapter_class
193
202
  end
@@ -208,6 +217,7 @@ RSpec.describe Slack::Web::Client do
208
217
  expect(client.timeout).to eq 10
209
218
  expect(client.open_timeout).to eq 15
210
219
  end
220
+
211
221
  it 'creates a connection with timeout options' do
212
222
  conn = client.send(:connection)
213
223
  expect(conn.options.timeout).to eq 10
@@ -217,16 +227,16 @@ RSpec.describe Slack::Web::Client do
217
227
  end
218
228
 
219
229
  context 'per-request options' do
220
- it 'applies timeout', vcr: { cassette_name: 'web/rtm_start', allow_playback_repeats: true } do
230
+ it 'applies timeout', vcr: { cassette_name: 'web/rtm_connect', allow_playback_repeats: true } do
221
231
  # reuse the same connection for the test, otherwise it creates a new one every time
222
232
  conn = client.send(:connection)
223
233
  expect(client).to receive(:connection).and_return(conn)
224
234
 
225
235
  # get the yielded request to reuse in the next call to
226
- # rtm_start so that we can examine request.options later
236
+ # rtm.connect so that we can examine request.options later
227
237
  request = nil
228
238
  response = conn.post do |r|
229
- r.path = 'rtm.start'
239
+ r.path = 'rtm.connect'
230
240
  r.headers = {
231
241
  'Accept' => ['application/json; charset=utf-8'],
232
242
  'Authorization' => ['Bearer <SLACK_API_TOKEN>']
@@ -236,7 +246,7 @@ RSpec.describe Slack::Web::Client do
236
246
 
237
247
  expect(conn).to receive(:post).and_yield(request).and_return(response)
238
248
 
239
- client.rtm_start(request: { timeout: 3 })
249
+ client.rtm_connect(request: { timeout: 3 })
240
250
 
241
251
  expect(request.options.timeout).to eq 3
242
252
  end