slack-ruby-client 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/update_api.yml +1 -1
- data/.rubocop_todo.yml +43 -13
- data/CHANGELOG.md +12 -0
- data/CONTRIBUTING.md +7 -7
- data/Gemfile +1 -0
- data/README.md +46 -28
- data/bin/commands/admin_conversations.rb +21 -0
- data/bin/commands/admin_users_session.rb +1 -1
- data/bin/commands/admin_workflows.rb +3 -1
- data/bin/commands/admin_workflows_triggers_types_permissions.rb +4 -4
- data/bin/commands/assistant_threads.rb +45 -0
- data/bin/commands/bookmarks.rb +1 -0
- data/bin/commands/canvases.rb +4 -4
- data/bin/commands/canvases_access.rb +3 -3
- data/bin/commands/chat.rb +7 -3
- data/bin/commands/conversations.rb +5 -5
- data/bin/commands/conversations_canvases.rb +2 -2
- data/bin/commands/conversations_requestSharedInvite.rb +48 -0
- data/bin/commands/files.rb +2 -1
- data/bin/commands/usergroups.rb +5 -0
- data/bin/commands/usergroups_users.rb +2 -0
- data/examples/files_upload_v2/.env.example +1 -0
- data/examples/files_upload_v2/Gemfile +5 -0
- data/examples/files_upload_v2/README.md +13 -0
- data/examples/files_upload_v2/files_upload_v2.rb +37 -0
- data/examples/oauth_v2/.env.example +4 -0
- data/examples/oauth_v2/Gemfile +7 -0
- data/examples/oauth_v2/README.md +33 -0
- data/examples/oauth_v2/oauth_v2.rb +60 -0
- data/lib/slack/messages/formatting.rb +1 -1
- data/lib/slack/version.rb +1 -1
- data/lib/slack/web/api/endpoints/admin_conversations.rb +35 -0
- data/lib/slack/web/api/endpoints/admin_users_session.rb +2 -3
- data/lib/slack/web/api/endpoints/admin_workflows.rb +5 -1
- data/lib/slack/web/api/endpoints/admin_workflows_triggers_types_permissions.rb +2 -2
- data/lib/slack/web/api/endpoints/assistant_threads.rb +68 -0
- data/lib/slack/web/api/endpoints/bookmarks.rb +2 -0
- data/lib/slack/web/api/endpoints/canvases.rb +2 -2
- data/lib/slack/web/api/endpoints/canvases_access.rb +4 -4
- data/lib/slack/web/api/endpoints/chat.rb +12 -3
- data/lib/slack/web/api/endpoints/conversations.rb +4 -4
- data/lib/slack/web/api/endpoints/conversations_canvases.rb +1 -1
- data/lib/slack/web/api/endpoints/conversations_requestSharedInvite.rb +73 -0
- data/lib/slack/web/api/endpoints/files.rb +3 -1
- data/lib/slack/web/api/endpoints/usergroups.rb +10 -0
- data/lib/slack/web/api/endpoints/usergroups_users.rb +4 -0
- data/lib/slack/web/api/endpoints.rb +4 -0
- data/lib/slack/web/api/errors.rb +48 -4
- data/lib/slack/web/api/helpers/files.rb +87 -0
- data/lib/slack/web/api/helpers.rb +13 -0
- data/lib/slack/web/api/templates/method_spec.erb +4 -3
- data/lib/slack/web/client.rb +1 -0
- data/lib/slack/web/faraday/connection.rb +13 -26
- data/lib/slack/web/faraday/options.rb +24 -0
- data/lib/slack/web/faraday/request.rb +2 -1
- data/lib/slack-ruby-client.rb +2 -0
- data/slack-ruby-client.gemspec +2 -1
- metadata +32 -154
- data/screenshots/create-app.png +0 -0
- data/spec/fixtures/slack/web/429_error.yml +0 -81
- data/spec/fixtures/slack/web/auth_test_error.yml +0 -81
- data/spec/fixtures/slack/web/auth_test_success.yml +0 -81
- data/spec/fixtures/slack/web/conversations_info.yml +0 -167
- data/spec/fixtures/slack/web/conversations_setTopic.yml +0 -84
- data/spec/fixtures/slack/web/conversations_setTopic_one_page.yml +0 -172
- data/spec/fixtures/slack/web/conversations_setTopic_paginated.yml +0 -253
- data/spec/fixtures/slack/web/paginated_users_list.yml +0 -613
- data/spec/fixtures/slack/web/rtm_connect.yml +0 -391
- data/spec/fixtures/slack/web/users_info.yml +0 -214
- data/spec/fixtures/slack/web/users_list.yml +0 -133
- data/spec/fixtures/slack/web/views_open_error.yml +0 -83
- data/spec/integration/integration_spec.rb +0 -207
- data/spec/slack/config_spec.rb +0 -16
- data/spec/slack/events/config_spec.rb +0 -35
- data/spec/slack/events/request_spec.rb +0 -199
- data/spec/slack/messages/formatting_spec.rb +0 -156
- data/spec/slack/real_time/api/message_spec.rb +0 -20
- data/spec/slack/real_time/api/ping_spec.rb +0 -17
- data/spec/slack/real_time/api/typing_spec.rb +0 -19
- data/spec/slack/real_time/client_spec.rb +0 -601
- data/spec/slack/real_time/concurrency/clients/async_spec.rb +0 -16
- data/spec/slack/real_time/concurrency/it_behaves_like_a_realtime_socket.rb +0 -21
- data/spec/slack/real_time/concurrency/with_concurrency_spec.rb +0 -10
- data/spec/slack/real_time/concurrency/without_concurrency_spec.rb +0 -10
- data/spec/slack/real_time/event_handlers/bot_spec.rb +0 -47
- data/spec/slack/real_time/event_handlers/event_handlers_spec.rb +0 -16
- data/spec/slack/real_time/event_handlers/im_spec.rb +0 -51
- data/spec/slack/real_time/event_handlers/private_channel_spec.rb +0 -99
- data/spec/slack/real_time/event_handlers/public_channel_spec.rb +0 -123
- data/spec/slack/real_time/event_handlers/team_spec.rb +0 -63
- data/spec/slack/real_time/event_handlers/user_spec.rb +0 -65
- data/spec/slack/real_time/rtm_connect_spec.rb +0 -14
- data/spec/slack/real_time/stores/store_spec.rb +0 -50
- data/spec/slack/slack_spec.rb +0 -93
- data/spec/slack/version_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/admin_analytics_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/admin_apps_activities_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/admin_apps_approved_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/admin_apps_config_spec.rb +0 -18
- data/spec/slack/web/api/endpoints/admin_apps_requests_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/admin_apps_restricted_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/admin_apps_spec.rb +0 -18
- data/spec/slack/web/api/endpoints/admin_audit_anomaly_allow_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/admin_auth_policy_spec.rb +0 -35
- data/spec/slack/web/api/endpoints/admin_barriers_spec.rb +0 -38
- data/spec/slack/web/api/endpoints/admin_conversations_ekm_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/admin_conversations_restrictAccess_spec.rb +0 -32
- data/spec/slack/web/api/endpoints/admin_conversations_spec.rb +0 -133
- data/spec/slack/web/api/endpoints/admin_emoji_spec.rb +0 -37
- data/spec/slack/web/api/endpoints/admin_functions_permissions_spec.rb +0 -21
- data/spec/slack/web/api/endpoints/admin_functions_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/admin_inviteRequests_approved_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/admin_inviteRequests_denied_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/admin_inviteRequests_spec.rb +0 -18
- data/spec/slack/web/api/endpoints/admin_roles_spec.rb +0 -30
- data/spec/slack/web/api/endpoints/admin_teams_admins_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/admin_teams_owners_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/admin_teams_settings_spec.rb +0 -53
- data/spec/slack/web/api/endpoints/admin_teams_spec.rb +0 -16
- data/spec/slack/web/api/endpoints/admin_usergroups_spec.rb +0 -37
- data/spec/slack/web/api/endpoints/admin_users_session_spec.rb +0 -41
- data/spec/slack/web/api/endpoints/admin_users_spec.rb +0 -67
- data/spec/slack/web/api/endpoints/admin_users_unsupportedVersions_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/admin_workflows_collaborators_spec.rb +0 -24
- data/spec/slack/web/api/endpoints/admin_workflows_permissions_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/admin_workflows_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/admin_workflows_triggers_types_permissions_spec.rb +0 -21
- data/spec/slack/web/api/endpoints/api_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/apps_activities_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/apps_auth_external_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/apps_connections_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/apps_datastore_spec.rb +0 -74
- data/spec/slack/web/api/endpoints/apps_event_authorizations_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/apps_manifest_spec.rb +0 -44
- data/spec/slack/web/api/endpoints/apps_spec.rb +0 -16
- data/spec/slack/web/api/endpoints/auth_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/auth_teams_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/bookmarks_spec.rb +0 -40
- data/spec/slack/web/api/endpoints/bots_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/calls_participants_spec.rb +0 -24
- data/spec/slack/web/api/endpoints/calls_spec.rb +0 -31
- data/spec/slack/web/api/endpoints/canvases_access_spec.rb +0 -21
- data/spec/slack/web/api/endpoints/canvases_sections_spec.rb +0 -16
- data/spec/slack/web/api/endpoints/canvases_spec.rb +0 -21
- data/spec/slack/web/api/endpoints/chat_scheduledMessages_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/chat_spec.rb +0 -134
- data/spec/slack/web/api/endpoints/conversations_canvases_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/conversations_externalInvitePermissions_spec.rb +0 -19
- data/spec/slack/web/api/endpoints/conversations_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/custom_specs/auth_spec.rb +0 -27
- data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +0 -206
- data/spec/slack/web/api/endpoints/custom_specs/conversations_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +0 -40
- data/spec/slack/web/api/endpoints/custom_specs/users_spec.rb +0 -38
- data/spec/slack/web/api/endpoints/custom_specs/views_spec.rb +0 -112
- data/spec/slack/web/api/endpoints/dialog_spec.rb +0 -14
- data/spec/slack/web/api/endpoints/dnd_spec.rb +0 -18
- data/spec/slack/web/api/endpoints/emoji_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/files_comments_spec.rb +0 -16
- data/spec/slack/web/api/endpoints/files_remote_spec.rb +0 -24
- data/spec/slack/web/api/endpoints/files_spec.rb +0 -57
- data/spec/slack/web/api/endpoints/functions_distributions_permissions_spec.rb +0 -10
- data/spec/slack/web/api/endpoints/functions_spec.rb +0 -28
- data/spec/slack/web/api/endpoints/functions_workflows_steps_responses_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/functions_workflows_steps_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/migration_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/oauth_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/oauth_v2_spec.rb +0 -16
- data/spec/slack/web/api/endpoints/openid_connect_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/pins_spec.rb +0 -23
- data/spec/slack/web/api/endpoints/reactions_spec.rb +0 -24
- data/spec/slack/web/api/endpoints/reminders_spec.rb +0 -31
- data/spec/slack/web/api/endpoints/rtm_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/search_spec.rb +0 -23
- data/spec/slack/web/api/endpoints/stars_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/team_billing_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/team_externalTeams_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/team_preferences_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/team_profile_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/team_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/tooling_tokens_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/usergroups_spec.rb +0 -28
- data/spec/slack/web/api/endpoints/usergroups_users_spec.rb +0 -21
- data/spec/slack/web/api/endpoints/users_admin_spec.rb +0 -18
- data/spec/slack/web/api/endpoints/users_discoverableContacts_spec.rb +0 -13
- data/spec/slack/web/api/endpoints/users_prefs_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/users_profile_spec.rb +0 -14
- data/spec/slack/web/api/endpoints/users_spec.rb +0 -8
- data/spec/slack/web/api/endpoints/views_spec.rb +0 -65
- data/spec/slack/web/api/endpoints/workflows_spec.rb +0 -34
- data/spec/slack/web/api/endpoints/workflows_triggers_permissions_spec.rb +0 -31
- data/spec/slack/web/api/error_spec.rb +0 -14
- data/spec/slack/web/api/errors/slack_error_spec.rb +0 -33
- data/spec/slack/web/api/mixins/conversations_list_spec.rb +0 -21
- data/spec/slack/web/api/mixins/conversations_spec.rb +0 -45
- data/spec/slack/web/api/mixins/users_spec.rb +0 -52
- data/spec/slack/web/api/options_spec.rb +0 -69
- data/spec/slack/web/api/pagination/cursor_spec.rb +0 -102
- data/spec/slack/web/client_spec.rb +0 -359
- data/spec/slack/web/faraday/request_spec.rb +0 -80
- data/spec/slack/web/faraday/response/raise_error_spec.rb +0 -86
- data/spec/spec_helper.rb +0 -30
- data/spec/support/queue_with_timeout.rb +0 -35
- data/spec/support/real_time/concurrency/mock.rb +0 -31
- data/spec/support/real_time/connected_client.rb +0 -21
- data/spec/support/real_time/event.rb +0 -12
- data/spec/support/real_time/loaded_client.rb +0 -120
- data/spec/support/token.rb +0 -11
- data/spec/support/vcr.rb +0 -45
@@ -1,31 +0,0 @@
|
|
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::WorkflowsTriggersPermissions do
|
7
|
-
let(:client) { Slack::Web::Client.new }
|
8
|
-
context 'workflows.triggers.permissions_add' do
|
9
|
-
it 'requires trigger_id' do
|
10
|
-
expect { client.workflows_triggers_permissions_add }.to raise_error ArgumentError, /Required arguments :trigger_id missing/
|
11
|
-
end
|
12
|
-
end
|
13
|
-
context 'workflows.triggers.permissions_list' do
|
14
|
-
it 'requires trigger_id' do
|
15
|
-
expect { client.workflows_triggers_permissions_list }.to raise_error ArgumentError, /Required arguments :trigger_id missing/
|
16
|
-
end
|
17
|
-
end
|
18
|
-
context 'workflows.triggers.permissions_remove' do
|
19
|
-
it 'requires trigger_id' do
|
20
|
-
expect { client.workflows_triggers_permissions_remove }.to raise_error ArgumentError, /Required arguments :trigger_id missing/
|
21
|
-
end
|
22
|
-
end
|
23
|
-
context 'workflows.triggers.permissions_set' do
|
24
|
-
it 'requires permission_type' do
|
25
|
-
expect { client.workflows_triggers_permissions_set(trigger_id: %q[Ft0000000001]) }.to raise_error ArgumentError, /Required arguments :permission_type missing/
|
26
|
-
end
|
27
|
-
it 'requires trigger_id' do
|
28
|
-
expect { client.workflows_triggers_permissions_set(permission_type: %q[]) }.to raise_error ArgumentError, /Required arguments :trigger_id missing/
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
RSpec.describe Slack::Web::Api::Error do
|
5
|
-
let(:client) { Slack::Web::Client.new }
|
6
|
-
|
7
|
-
it 'provides access to the response object', vcr: { cassette_name: 'web/auth_test_error' } do
|
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
|
13
|
-
end
|
14
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
RSpec.describe Slack::Web::Api::Errors::SlackError do
|
5
|
-
let(:client) { Slack::Web::Client.new }
|
6
|
-
|
7
|
-
it 'provides access to the response object', vcr: { cassette_name: 'web/auth_test_error' } do
|
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
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'provides access to any response_metadata', vcr: { cassette_name: 'web/views_open_error' } do
|
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
|
-
)
|
32
|
-
end
|
33
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
RSpec.describe Slack::Web::Client do
|
5
|
-
context 'conversations_setTopic' do
|
6
|
-
it 'does not invoke conversations_list', vcr: { cassette_name: 'web/conversations_setTopic' } do
|
7
|
-
rc = subject.conversations_setTopic({ channel: 'C019CV63UTC', topic: 'new topic' })
|
8
|
-
expect(rc.channel.topic.value).to eq 'new topic'
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'resolves IDs via conversations_list', vcr: { cassette_name: 'web/conversations_setTopic_one_page' } do
|
12
|
-
rc = subject.conversations_setTopic({ channel: '#1', topic: 'new topic' })
|
13
|
-
expect(rc.channel.topic.value).to eq 'new topic'
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'paginates to resolve IDs', vcr: { cassette_name: 'web/conversations_setTopic_paginated' } do
|
17
|
-
rc = subject.conversations_setTopic({ channel: '#topic', topic: 'new topic' })
|
18
|
-
expect(rc.channel.topic.value).to eq 'new topic'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
RSpec.describe Slack::Web::Api::Mixins::Conversations do
|
5
|
-
subject(:conversations) do
|
6
|
-
klass.new
|
7
|
-
end
|
8
|
-
|
9
|
-
let(:klass) do
|
10
|
-
Class.new do
|
11
|
-
include Slack::Web::Api::Mixins::Conversations
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
before do
|
16
|
-
allow(conversations).to receive(:conversations_list).and_yield(
|
17
|
-
Slack::Messages::Message.new(
|
18
|
-
'channels' => [{
|
19
|
-
'id' => 'CDEADBEEF',
|
20
|
-
'name' => 'general'
|
21
|
-
}]
|
22
|
-
)
|
23
|
-
)
|
24
|
-
end
|
25
|
-
|
26
|
-
describe '#conversations_id' do
|
27
|
-
it 'leaves channels specified by ID alone' do
|
28
|
-
expect(conversations.conversations_id(channel: 'C123456')).to(
|
29
|
-
eq('ok' => true, 'channel' => { 'id' => 'C123456' })
|
30
|
-
)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'translates a channel that starts with a #' do
|
34
|
-
expect(conversations.conversations_id(channel: '#general')).to(
|
35
|
-
eq('ok' => true, 'channel' => { 'id' => 'CDEADBEEF' })
|
36
|
-
)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'fails with an exception' do
|
40
|
-
expect { conversations.conversations_id(channel: '#invalid') }.to(
|
41
|
-
raise_error(Slack::Web::Api::Errors::SlackError, 'channel_not_found')
|
42
|
-
)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
RSpec.describe Slack::Web::Api::Mixins::Users do
|
5
|
-
subject(:users) do
|
6
|
-
klass.new
|
7
|
-
end
|
8
|
-
|
9
|
-
let(:klass) do
|
10
|
-
Class.new do
|
11
|
-
include Slack::Web::Api::Mixins::Users
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
before do
|
16
|
-
allow(users).to receive(:users_list).and_yield(
|
17
|
-
Slack::Messages::Message.new(
|
18
|
-
'members' => [{
|
19
|
-
'id' => 'UDEADBEEF',
|
20
|
-
'name' => 'aws',
|
21
|
-
'profile' => {}
|
22
|
-
}]
|
23
|
-
)
|
24
|
-
)
|
25
|
-
end
|
26
|
-
|
27
|
-
context '#users_id' do
|
28
|
-
it 'leaves users specified by ID alone' do
|
29
|
-
expect(users.users_id(user: 'U123456')).to eq('ok' => true, 'user' => { 'id' => 'U123456' })
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'translates a user that starts with a #' do
|
33
|
-
expect(users.users_id(user: '@aws')).to eq('ok' => true, 'user' => { 'id' => 'UDEADBEEF' })
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'fails with an exception' do
|
37
|
-
expect { users.users_id(user: '@foo') }.to(
|
38
|
-
raise_error(Slack::Web::Api::Errors::SlackError, 'user_not_found')
|
39
|
-
)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
if defined?(Picky)
|
44
|
-
context '#users_search' do
|
45
|
-
it 'finds a user' do
|
46
|
-
expect(users.users_search(user: 'aws')).to(
|
47
|
-
eq('ok' => true, 'members' => [{ 'id' => 'UDEADBEEF', 'name' => 'aws', 'profile' => {} }])
|
48
|
-
)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
RSpec.describe Slack::Web::Api::Error do
|
5
|
-
let(:client) { Slack::Web::Client.new }
|
6
|
-
|
7
|
-
describe '#encode_options_as_json' do
|
8
|
-
let(:encoded_options) { client.encode_options_as_json(options, keys) }
|
9
|
-
|
10
|
-
let(:keys) { %i[attachments blocks metadata] }
|
11
|
-
|
12
|
-
context 'with some of the keys present in the options' do
|
13
|
-
let(:options) do
|
14
|
-
{
|
15
|
-
text: 'Hello, world!',
|
16
|
-
blocks: blocks,
|
17
|
-
metadata: metadata
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'and non-string objects in those keys' do
|
22
|
-
let(:blocks) { [{ type: 'section' }, { type: 'actions' }] }
|
23
|
-
let(:metadata) { { external_id: SecureRandom.uuid } }
|
24
|
-
|
25
|
-
it 'encodes the named keys into json' do
|
26
|
-
expect(encoded_options).to eql(
|
27
|
-
text: 'Hello, world!',
|
28
|
-
blocks: JSON.dump(blocks),
|
29
|
-
metadata: JSON.dump(metadata)
|
30
|
-
)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'and string objects in those keys' do
|
35
|
-
let(:blocks) { JSON.dump([{ type: 'section' }, { type: 'actions' }]) }
|
36
|
-
let(:metadata) { JSON.dump({ external_id: SecureRandom.uuid }) }
|
37
|
-
|
38
|
-
it 'returns the original options' do
|
39
|
-
expect(encoded_options).to eql(options)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'with none of the keys present in the options' do
|
45
|
-
let(:options) do
|
46
|
-
{
|
47
|
-
text: 'Hello, world!'
|
48
|
-
}
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'returns the original options' do
|
52
|
-
expect(encoded_options).to eql(options)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context 'with no keys given' do
|
57
|
-
let(:options) do
|
58
|
-
{
|
59
|
-
text: 'Hello, world!'
|
60
|
-
}
|
61
|
-
end
|
62
|
-
let(:keys) { [] }
|
63
|
-
|
64
|
-
it 'returns the original options' do
|
65
|
-
expect(encoded_options).to eql(options)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,102 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
RSpec.describe Slack::Web::Api::Pagination::Cursor do
|
5
|
-
let(:client) { Slack::Web::Client.new }
|
6
|
-
|
7
|
-
context 'default cursor' do
|
8
|
-
let(:cursor) { described_class.new(client, 'users_list', {}) }
|
9
|
-
|
10
|
-
it 'provides a default limit' do
|
11
|
-
expect(client).to receive(:users_list).with({ limit: 100, cursor: nil })
|
12
|
-
cursor.first
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'handles blank response metadata' do
|
16
|
-
expect(client).to receive(:users_list).once.and_return(Slack::Messages::Message.new)
|
17
|
-
cursor.to_a
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'handles nil response metadata' do
|
21
|
-
expect(client).to(
|
22
|
-
receive(:users_list).once.and_return(Slack::Messages::Message.new(response_metadata: nil))
|
23
|
-
)
|
24
|
-
cursor.to_a
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'paginates with a cursor inside response metadata' do
|
28
|
-
expect(client).to receive(:users_list).twice.and_return(
|
29
|
-
Slack::Messages::Message.new(response_metadata: { next_cursor: 'next' }),
|
30
|
-
Slack::Messages::Message.new
|
31
|
-
)
|
32
|
-
expect(cursor).not_to receive(:sleep)
|
33
|
-
cursor.to_a
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'with rate limiting' do
|
37
|
-
let(:error) { Slack::Web::Api::Errors::TooManyRequestsError.new(OpenStruct.new(headers: { 'retry-after' => 9 })) }
|
38
|
-
|
39
|
-
context 'with default max retries' do
|
40
|
-
it 'sleeps after a TooManyRequestsError' do
|
41
|
-
expect(client).to(
|
42
|
-
receive(:users_list)
|
43
|
-
.with({ limit: 100, cursor: nil })
|
44
|
-
.ordered
|
45
|
-
.and_return(Slack::Messages::Message.new(response_metadata: { next_cursor: 'next' }))
|
46
|
-
)
|
47
|
-
expect(client).to(
|
48
|
-
receive(:users_list).with({ limit: 100, cursor: 'next' }).ordered.and_raise(error)
|
49
|
-
)
|
50
|
-
expect(cursor).to receive(:sleep).once.ordered.with(9)
|
51
|
-
expect(client).to(
|
52
|
-
receive(:users_list)
|
53
|
-
.with({ limit: 100, cursor: 'next' })
|
54
|
-
.ordered
|
55
|
-
.and_return(Slack::Messages::Message.new)
|
56
|
-
)
|
57
|
-
cursor.to_a
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'with a custom max_retries' do
|
62
|
-
let(:cursor) { described_class.new(client, 'users_list', max_retries: 4) }
|
63
|
-
|
64
|
-
it 'raises the error after hitting the max retries' do
|
65
|
-
expect(client).to(
|
66
|
-
receive(:users_list)
|
67
|
-
.with({ limit: 100, cursor: nil })
|
68
|
-
.and_return(Slack::Messages::Message.new(response_metadata: { next_cursor: 'next' }))
|
69
|
-
)
|
70
|
-
expect(client).to(
|
71
|
-
receive(:users_list).with({ limit: 100, cursor: 'next' }).exactly(5).times.and_raise(error)
|
72
|
-
)
|
73
|
-
expect(cursor).to receive(:sleep).exactly(4).times.with(9)
|
74
|
-
expect { cursor.to_a }.to raise_error(error)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'with a custom limit' do
|
81
|
-
let(:cursor) { described_class.new(client, 'users_list', limit: 42) }
|
82
|
-
|
83
|
-
it 'overrides default limit' do
|
84
|
-
expect(client).to receive(:users_list).with({ limit: 42, cursor: nil })
|
85
|
-
cursor.first
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'with a custom sleep_interval' do
|
90
|
-
let(:cursor) { described_class.new(client, 'users_list', sleep_interval: 3) }
|
91
|
-
|
92
|
-
it 'sleeps between requests' do
|
93
|
-
expect(client).to receive(:users_list).exactly(3).times.and_return(
|
94
|
-
Slack::Messages::Message.new(response_metadata: { next_cursor: 'next_a' }),
|
95
|
-
Slack::Messages::Message.new(response_metadata: { next_cursor: 'next_b' }),
|
96
|
-
Slack::Messages::Message.new
|
97
|
-
)
|
98
|
-
expect(cursor).to receive(:sleep).with(3).twice
|
99
|
-
cursor.to_a
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|