From 64069e26e9b0b9c8c445d7c3961cd2eebe39a7fe Mon Sep 17 00:00:00 2001 From: Greg Saab Date: Fri, 31 Jan 2025 00:05:42 -0500 Subject: [PATCH] add a spec for using all params, rename the valid_params to required_params --- .../web/files_upload_v2_with_all_options.yml | 226 ++++++++++++++++++ .../api/endpoints/custom_specs/files_spec.rb | 25 +- 2 files changed, 243 insertions(+), 8 deletions(-) create mode 100644 spec/fixtures/slack/web/files_upload_v2_with_all_options.yml diff --git a/spec/fixtures/slack/web/files_upload_v2_with_all_options.yml b/spec/fixtures/slack/web/files_upload_v2_with_all_options.yml new file mode 100644 index 00000000..bee99525 --- /dev/null +++ b/spec/fixtures/slack/web/files_upload_v2_with_all_options.yml @@ -0,0 +1,226 @@ +--- +http_interactions: +- request: + method: post + uri: https://slack.com/api/files.getUploadURLExternal + body: + encoding: UTF-8 + string: alt_txt=alt_txt&filename=test.txt&length=18&snippet_type=text + headers: + Accept: + - application/json; charset=utf-8 + User-Agent: + - Slack Ruby Client/2.4.1 + Authorization: + - Bearer + Content-Type: + - application/x-www-form-urlencoded + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 31 Jan 2025 05:03:37 GMT + Server: + - Apache + Vary: + - Accept-Encoding + X-Slack-Req-Id: + - '08a4120c91e504a26bb6ad0f08b83f10' + X-Content-Type-Options: + - nosniff + X-Xss-Protection: + - '0' + Pragma: + - no-cache + Cache-Control: + - private, no-cache, no-store, must-revalidate + Expires: + - Sat, 26 Jul 1997 05:00:00 GMT + Content-Type: + - application/json; charset=utf-8 + X-Accepted-Oauth-Scopes: + - files:write + X-Oauth-Scopes: + - files:read,files:write,channels:join,channels:read,chat:write,chat:write.public + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts, x-b3-traceid, x-b3-spanid, x-b3-parentspanid, + x-b3-sampled, x-b3-flags + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + X-Slack-Unique-Id: + - Z5xZqfkSz9PenwPz93v7hQAAABo + X-Slack-Backend: + - r + Access-Control-Allow-Origin: + - "*" + Via: + - 1.1 slack-prod.tinyspeck.com, envoy-www-iad-irfmimyl,envoy-edge-iad-cmkfvfyz + Content-Length: + - '234' + X-Envoy-Attempt-Count: + - '1' + X-Envoy-Upstream-Service-Time: + - '47' + X-Backend: + - main_normal main_canary_with_overflow main_control_with_overflow + X-Server: + - slack-www-hhvm-main-iad-yxst + X-Slack-Shared-Secret-Outcome: + - no-match + X-Edge-Backend: + - envoy-www + X-Geoname-Id: + - notfound + X-Slack-Edge-Shared-Secret-Outcome: + - no-match + body: + encoding: UTF-8 + string: '{"ok":true,"upload_url":"https:\/\/files.slack.com\/upload\/v1\/CwABAAAAWgoAAUMFEWsSXP2oCgACGB-ueVlte-AMAAMLAAEAAAAJVDM5QTBCWThQCwACAAAAC1UwOEIyMVRKSjRCCwADAAAAC0YwOEFRMzhNTUZIAAoABAAAAAAAAAASAAsAAgAAABRvbR_xaVNIFgq8eQkjf777RQFUngA","file_id":"F08AQ38MMFH"}' + recorded_at: Fri, 31 Jan 2025 05:03:37 GMT +- request: + method: post + uri: https://files.slack.com/upload/v1/CwABAAAAWgoAAUMFEWsSXP2oCgACGB-ueVlte-AMAAMLAAEAAAAJVDM5QTBCWThQCwACAAAAC1UwOEIyMVRKSjRCCwADAAAAC0YwOEFRMzhNTUZIAAoABAAAAAAAAAASAAsAAgAAABRvbR_xaVNIFgq8eQkjf777RQFUngA + body: + encoding: UTF-8 + string: Test File Contents + headers: + Accept: + - application/json; charset=utf-8 + User-Agent: + - Slack Ruby Client/2.4.1 + Authorization: + - Bearer + Content-Type: + - application/x-www-form-urlencoded + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - text/plain; charset=utf-8 + Content-Length: + - '7' + Connection: + - keep-alive + X-Backend: + - miata-prod-iad-v2-d8874bfdc-646g4 + Date: + - Fri, 31 Jan 2025 05:03:37 GMT + X-Envoy-Upstream-Service-Time: + - '156' + Via: + - envoy-edge-iad-pcujsuod, 1.1 75bba5dfd2aa92cc6ca63ecca3b5248c.cloudfront.net + (CloudFront) + X-Slack-Edge-Shared-Secret-Outcome: + - shared-secret + Server: + - envoy + X-Cache: + - Miss from cloudfront + X-Amz-Cf-Pop: + - IAD79-C3 + X-Amz-Cf-Id: + - MKn11ZfbGkhwXuHvmxzDsHnrJJhH9erL6bvM9bWPUFRIqoMhNtRiOQ== + Cross-Origin-Resource-Policy: + - cross-origin + body: + encoding: UTF-8 + string: OK - 18 + recorded_at: Fri, 31 Jan 2025 05:03:37 GMT +- request: + method: post + uri: https://slack.com/api/files.completeUploadExternal + body: + encoding: UTF-8 + string: channels=C08AZ76CA4V&files=%5B%7B%22id%22%3A%22F08AQ38MMFH%22%2C%22title%22%3A%22title%22%7D%5D&initial_comment=initial_comment + headers: + Accept: + - application/json; charset=utf-8 + User-Agent: + - Slack Ruby Client/2.4.1 + Authorization: + - Bearer + Content-Type: + - application/x-www-form-urlencoded + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 31 Jan 2025 05:03:37 GMT + Server: + - Apache + Vary: + - Accept-Encoding + X-Slack-Req-Id: + - dadedeb80dd7922265135a83c7b306fd + X-Content-Type-Options: + - nosniff + X-Xss-Protection: + - '0' + Pragma: + - no-cache + Cache-Control: + - private, no-cache, no-store, must-revalidate + Expires: + - Sat, 26 Jul 1997 05:00:00 GMT + Content-Type: + - application/json; charset=utf-8 + X-Accepted-Oauth-Scopes: + - files:write + X-Oauth-Scopes: + - files:read,files:write,channels:join,channels:read,chat:write,chat:write.public + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + Access-Control-Allow-Headers: + - slack-route, x-slack-version-ts, x-b3-traceid, x-b3-spanid, x-b3-parentspanid, + x-b3-sampled, x-b3-flags + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + X-Slack-Unique-Id: + - Z5xZqRE03IpTB-HlvgG1UAAAECQ + X-Slack-Backend: + - r + Access-Control-Allow-Origin: + - "*" + Via: + - 1.1 slack-prod.tinyspeck.com, envoy-www-iad-ejtlsucm,envoy-edge-iad-xalqpjvx + Content-Length: + - '451' + X-Envoy-Attempt-Count: + - '1' + X-Envoy-Upstream-Service-Time: + - '77' + X-Backend: + - main_normal main_canary_with_overflow main_control_with_overflow + X-Server: + - slack-www-hhvm-main-iad-pjmv + X-Slack-Shared-Secret-Outcome: + - no-match + X-Edge-Backend: + - envoy-www + X-Geoname-Id: + - notfound + X-Slack-Edge-Shared-Secret-Outcome: + - no-match + body: + encoding: UTF-8 + string: '{"ok":true,"files":[{"id":"F08AQ38MMFH","created":1738299817,"timestamp":1738299817,"name":"test.txt","title":"title","mimetype":"","filetype":"","pretty_type":"","user":"U08B21TJJ4B","user_team":"T39A0BY8P","editable":false,"size":18,"mode":"hosted","is_external":false,"external_type":"","is_public":false,"public_url_shared":false,"display_as_bot":false,"username":"","url_private":"https:\/\/files.slack.com\/files-pri\/T39A0BY8P-F08AQ38MMFH\/test.txt","url_private_download":"https:\/\/files.slack.com\/files-pri\/T39A0BY8P-F08AQ38MMFH\/download\/test.txt","media_display_type":"unknown","permalink":"https:\/\/popsql.slack.com\/files\/U08B21TJJ4B\/F08AQ38MMFH\/test.txt","permalink_public":"https:\/\/slack-files.com\/T39A0BY8P-F08AQ38MMFH-d69430e477","comments_count":0,"is_starred":false,"shares":{},"channels":[],"groups":[],"ims":[],"has_more_shares":false,"has_rich_preview":false,"file_access":"visible"}]}' + recorded_at: Fri, 31 Jan 2025 05:03:37 GMT +recorded_with: VCR 6.3.1 diff --git a/spec/slack/web/api/endpoints/custom_specs/files_spec.rb b/spec/slack/web/api/endpoints/custom_specs/files_spec.rb index 447ab356..0307c926 100644 --- a/spec/slack/web/api/endpoints/custom_specs/files_spec.rb +++ b/spec/slack/web/api/endpoints/custom_specs/files_spec.rb @@ -3,43 +3,52 @@ RSpec.describe Slack::Web::Api::Endpoints::Files do let(:client) { Slack::Web::Client.new } - let(:valid_params) do + let(:required_params) do { filename: 'test.txt', content: 'Test File Contents', channels: 'C08AZ76CA4V' } end + let(:all_params) do + required_params.merge!({ title: 'title', alt_txt: 'alt_txt', snippet_type: 'text', initial_comment: 'initial_comment' }) + end context 'when filename is missing from options' do before do - valid_params.delete(:filename) + required_params.delete(:filename) end it 'throws argument error' do - expect { client.files_upload_v2(valid_params) }.to raise_error ArgumentError + expect { client.files_upload_v2(required_params) }.to raise_error ArgumentError end end context 'when channels is missing from options' do before do - valid_params.delete(:channels) + required_params.delete(:channels) end it 'throws argument error' do - expect { client.files_upload_v2(valid_params) }.to raise_error ArgumentError + expect { client.files_upload_v2(required_params) }.to raise_error ArgumentError end end context 'when content is missing from options' do before do - valid_params.delete(:content) + required_params.delete(:content) end it 'throws argument error' do - expect { client.files_upload_v2(valid_params) }.to raise_error ArgumentError + expect { client.files_upload_v2(required_params) }.to raise_error ArgumentError end end context 'when all required options are sent', vcr: { cassette_name: 'web/files_upload_v2' } do it 'completes the upload' do - client.files_upload_v2(valid_params) + client.files_upload_v2(required_params) + end + end + + context 'when all options specified', vcr: { cassette_name: 'web/files_upload_v2_with_all_options' } do + it 'completes the upload' do + client.files_upload_v2(all_params) end end end