diff --git a/.floo b/.floo new file mode 100644 index 00000000..05b8e45b --- /dev/null +++ b/.floo @@ -0,0 +1,3 @@ +{ + "url": "https://floobits.com/idagoitom/slack-cli" +} \ No newline at end of file diff --git a/.flooignore b/.flooignore new file mode 100644 index 00000000..ed824d39 --- /dev/null +++ b/.flooignore @@ -0,0 +1,6 @@ +extern +node_modules +tmp +vendor +.idea/workspace.xml +.idea/misc.xml diff --git a/.gitignore b/.gitignore index 3ff4fada..e651d86e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ # Ignore environemnt variables .env +.floo +.flooignore diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..8bf4d45d --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,6 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.rakeTasks b/.idea/.rakeTasks new file mode 100644 index 00000000..f88db1a3 --- /dev/null +++ b/.idea/.rakeTasks @@ -0,0 +1,7 @@ + + diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..510e7fcc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..7a98b196 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/slack-cli.iml b/.idea/slack-cli.iml new file mode 100644 index 00000000..329312d1 --- /dev/null +++ b/.idea/slack-cli.iml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/lib/channel.rb b/lib/channel.rb new file mode 100644 index 00000000..5c8b1f25 --- /dev/null +++ b/lib/channel.rb @@ -0,0 +1,27 @@ +require_relative 'recipient' + +class Channel < Recipient + attr_reader :topic, :member_count + + def initialize(slack_id:, name:, topic:, member_count:) + super(slack_id: slack_id, name: name) + @topic = topic + @member_count = member_count + end + + def details + return "Name: #{@name}, ID: #{@slack_id}, Topic: #{@topic}, Member count: #{@member_count}" + end + + def self.list_all + response = self.get(CHANNELS_URL, PARAMS) + response["channels"].map do |channel| + Channel.new( + slack_id: channel["id"], + name: channel["name"], + topic: channel["topic"]["value"], + member_count: channel["num_members"] + ) + end + end +end \ No newline at end of file diff --git a/lib/recipient.rb b/lib/recipient.rb new file mode 100644 index 00000000..e5c4f177 --- /dev/null +++ b/lib/recipient.rb @@ -0,0 +1,54 @@ +require 'httparty' +require 'dotenv' + +Dotenv.load + +class SlackApiError < StandardError; end + +class Recipient + USERS_URL = 'https://slack.com/api/users.list' + CHANNELS_URL = 'https://slack.com/api/conversations.list' + MESSAGE_URL = 'https://slack.com/api/chat.postMessage' + PARAMS = 'SLACK_API_TOKEN' + SLACK_BOT_TOKEN = 'SLACK_BOT_API_TOKEN' + + attr_reader :slack_id, :name + + def initialize(slack_id: nil, name: nil) + @slack_id = slack_id + @name = name + end + + def self.get(url, params) + sleep(0.5) + HTTParty.get(url, query: {token: ENV[params]}) + end + + def send_message(message) + sleep(0.5) + + response = HTTParty.post( + MESSAGE_URL, + body: { + token: ENV[SLACK_BOT_TOKEN], + channel: @slack_id, + text: message + }, + headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } + ) + + unless response.code == 200 && response.parsed_response["ok"] + raise SlackApiError, "Error when posting #{message} to #{@slack_id}, error: #{response.parsed_response["error"]}" + end + return response + end + + def details + raise NotImplementedError, 'Implement me in a child class!' + end + + def self.list_all + raise NotImplementedError, 'Implement me in a child class!' + end + +end \ No newline at end of file diff --git a/lib/slack.rb b/lib/slack.rb index 8a0b659b..d06efdba 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,12 +1,52 @@ #!/usr/bin/env ruby +require 'table_print' +require_relative 'workspace' + def main puts "Welcome to the Ada Slack CLI!" + workspace = Workspace.new - # TODO project + puts "We have #{workspace.channels.size} channels and #{workspace.users.size} users loaded.\n" + + end_program = false + until end_program + puts "\nThere are several options to interact with this program. Please pick one: " + puts "1. list users" + puts "2. list channels" + puts "3. select user" + puts "4. select channel" + puts "5. details" + puts "6. send message" + puts "7. quit\n\n" - puts "Thank you for using the Ada Slack CLI" + user_input = gets.chomp + + case user_input + when "list users" + tp User.list_all, "real_name", "slack_id", "name" + when "list channels" + tp Channel.list_all, "name", "topic", "slack_id", "member_count" + when "select user" + puts "Please enter a user name or user id:" + select_user_input = gets.chomp + workspace.select_user(select_user_input) + when "select channel" + puts "Select a channel name or id:" + channel_input = gets.chomp + workspace.select_channel(channel_input) + when "details" + puts workspace.show_details + when "send message" + workspace.send_message + when "quit" + puts "Thank you for using the Ada Slack CLI" + end_program = true + end + end end -main if __FILE__ == $PROGRAM_NAME \ No newline at end of file +main if __FILE__ == $PROGRAM_NAME + + diff --git a/lib/user.rb b/lib/user.rb new file mode 100644 index 00000000..13f8b732 --- /dev/null +++ b/lib/user.rb @@ -0,0 +1,26 @@ +require_relative 'recipient' + +class User < Recipient + attr_reader :real_name + + def initialize(slack_id:, name:, real_name:) + super(slack_id: slack_id, name: name) + @real_name = real_name + end + + def details + return "Name: #{@real_name}, ID: #{@slack_id}, Username: #{@name}" + end + + def self.list_all + response = self.get(USERS_URL, PARAMS) + + response["members"].map do |member| + User.new( + slack_id: member["id"], + name: member["name"], + real_name: member["real_name"] + ) + end + end +end \ No newline at end of file diff --git a/lib/workspace.rb b/lib/workspace.rb new file mode 100644 index 00000000..8803729a --- /dev/null +++ b/lib/workspace.rb @@ -0,0 +1,61 @@ +require_relative 'user' +require_relative 'channel' + +class Workspace + attr_reader :users, :channels, :selected + + def initialize + @users = User.list_all + @channels = Channel.list_all + @selected = nil + end + + def select_user(user) + @users.each do |member| + if user == member.slack_id || user == member.name + @selected = member + end + end + + if @selected.nil? + puts "This user was not found." + end + + return @selected + end + + def select_channel(name) + @channels.each do |channel| + if name == channel.name || name == channel.slack_id + @selected = channel + end + end + + if @selected.nil? + puts "This channel was not found." + end + + return @selected + end + + def show_details + if @selected.nil? + puts "No recipient is currently selected." + return + end + + @selected.details + end + + def send_message + if @selected.nil? + puts "No recipient is currently selected to send a message to." + return + end + + puts "Please enter a message:" + message = gets.chomp + + @selected.send_message(message) + end +end \ No newline at end of file diff --git a/test/cassettes/channel.yml b/test/cassettes/channel.yml new file mode 100644 index 00000000..6ab817cf --- /dev/null +++ b/test/cassettes/channel.yml @@ -0,0 +1,206 @@ +--- +http_interactions: +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=xoxb-1411248079363-1404340511606-fOwOmFcNFbWUGeb3ZyMTMXRE&channel=fake&text=This%20post%20should%20not%20work + headers: + Content-Type: + - application/x-www-form-urlencoded + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 09 Oct 2020 17:43:47 GMT + Server: + - Apache + X-Slack-Req-Id: + - 2d733a8d8fccc28aa59eaff2366e7ea2 + X-Oauth-Scopes: + - chat:write,users:read,channels:read + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + Access-Control-Allow-Origin: + - "*" + X-Slack-Backend: + - r + X-Content-Type-Options: + - nosniff + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write + 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 + Vary: + - Accept-Encoding + Pragma: + - no-cache + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Content-Length: + - '60' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-na7m,haproxy-edge-pdx-gxzc + body: + encoding: ASCII-8BIT + string: '{"ok":false,"error":"channel_not_found"}' + recorded_at: Fri, 09 Oct 2020 17:43:47 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=xoxb-1411248079363-1404340511606-fOwOmFcNFbWUGeb3ZyMTMXRE&channel=C01BW93UN8N&text=hello%20testing + headers: + Content-Type: + - application/x-www-form-urlencoded + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 09 Oct 2020 17:43:48 GMT + Server: + - Apache + X-Slack-Req-Id: + - d08fe44cee134d767061fb96d409e63a + X-Oauth-Scopes: + - chat:write,users:read,channels:read + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + Access-Control-Allow-Origin: + - "*" + X-Slack-Backend: + - r + X-Content-Type-Options: + - nosniff + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - chat:write + 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 + Vary: + - Accept-Encoding + Pragma: + - no-cache + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Content-Length: + - '334' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-ngke,haproxy-edge-pdx-locq + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channel":"C01BW93UN8N","ts":"1602265428.001000","message":{"bot_id":"B01BN9RATAB","type":"message","text":"hello + testing","user":"U01BWA0F1HU","ts":"1602265428.001000","team":"T01C37A2BAP","bot_profile":{"id":"B01BN9RATAB","deleted":false,"name":"C14 + - Ida - API Project","updated":1602265137,"app_id":"A01C37SFXEX","icons":{"image_36":"https:\/\/a.slack-edge.com\/80588\/img\/plugins\/app\/bot_36.png","image_48":"https:\/\/a.slack-edge.com\/80588\/img\/plugins\/app\/bot_48.png","image_72":"https:\/\/a.slack-edge.com\/80588\/img\/plugins\/app\/service_72.png"},"team_id":"T01C37A2BAP"}}}' + recorded_at: Fri, 09 Oct 2020 17:43:48 GMT +- request: + method: get + uri: https://slack.com/api/conversations.list?token= + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 09 Oct 2020 17:43:49 GMT + Server: + - Apache + X-Slack-Req-Id: + - 33a3b5c979172b5149b7fe0b0ef36251 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + Access-Control-Allow-Origin: + - "*" + X-Slack-Backend: + - r + X-Content-Type-Options: + - nosniff + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - channels:read,groups:read,mpim:read,im:read,read + 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 + Vary: + - Accept-Encoding + Pragma: + - no-cache + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Content-Length: + - '691' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-7n0o,haproxy-edge-pdx-pim9 + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"C01BW93UN8N","name":"random","is_channel":true,"is_group":false,"is_im":false,"created":1602015082,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"random","is_shared":false,"parent_conversation":null,"creator":"U01C95Y5RUL","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01C37A2BAP"],"pending_shared":[],"pending_connected_team_ids":[],"is_pending_ext_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"topic":{"value":"super + random!","creator":"U01BN903TU7","last_set":1602021102},"purpose":{"value":"This + channel is for... well, everything else. It\u2019s a place for team jokes, + spur-of-the-moment ideas, and funny GIFs. Go wild!","creator":"U01C95Y5RUL","last_set":1602015082},"previous_names":[],"num_members":4},{"id":"C01C37A2T1R","name":"general","is_channel":true,"is_group":false,"is_im":false,"created":1602015081,"is_archived":false,"is_general":true,"unlinked":0,"name_normalized":"general","is_shared":false,"parent_conversation":null,"creator":"U01C95Y5RUL","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01C37A2BAP"],"pending_shared":[],"pending_connected_team_ids":[],"is_pending_ext_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"topic":{"value":"very + general","creator":"U01BN903TU7","last_set":1602021116},"purpose":{"value":"This + is the one channel that will always include everyone. It\u2019s a great spot + for announcements and team-wide conversations.","creator":"U01C95Y5RUL","last_set":1602015081},"previous_names":[],"num_members":4},{"id":"C01CSS4N2QG","name":"slack-cli","is_channel":true,"is_group":false,"is_im":false,"created":1602015214,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"slack-cli","is_shared":false,"parent_conversation":null,"creator":"U01C95Y5RUL","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01C37A2BAP"],"pending_shared":[],"pending_connected_team_ids":[],"is_pending_ext_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"This + *channel* is for working on a project. Hold meetings, share docs, and make + decisions together with your team.","creator":"U01C95Y5RUL","last_set":1602015214},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + recorded_at: Fri, 09 Oct 2020 17:43:49 GMT +recorded_with: VCR 6.0.0 diff --git a/test/cassettes/user.yml b/test/cassettes/user.yml new file mode 100644 index 00000000..1203fc45 --- /dev/null +++ b/test/cassettes/user.yml @@ -0,0 +1,79 @@ +--- +http_interactions: +- request: + method: get + uri: https://slack.com/api/users.list?token= + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 09 Oct 2020 17:43:51 GMT + Server: + - Apache + X-Slack-Req-Id: + - d0d8551062a5800e36f1cb7ee92e70cc + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + Access-Control-Allow-Origin: + - "*" + X-Slack-Backend: + - r + X-Content-Type-Options: + - nosniff + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - users:read + 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 + Vary: + - Accept-Encoding + Pragma: + - no-cache + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Content-Length: + - '1342' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-98pr,haproxy-edge-pdx-1350 + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"T01C37A2BAP","name":"slackbot","deleted":false,"color":"757575","real_name":"Slackbot","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Slackbot","real_name_normalized":"Slackbot","display_name":"Slackbot","display_name_normalized":"Slackbot","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"sv41d8cd98f0","always_active":true,"first_name":"slackbot","last_name":"","image_24":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/80588\/marketing\/img\/avatars\/slackbot\/avatar-slackbot.png","image_512":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_512.png","status_text_canonical":"","team":"T01C37A2BAP"},"is_admin":false,"is_owner":false,"is_primary_owner":false,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":0},{"id":"U01BN903TU7","team_id":"T01C37A2BAP","name":"anna.kim93","deleted":false,"color":"4bbe2e","real_name":"Anna + Kim","tz":"America\/New_York","tz_label":"Eastern Daylight Time","tz_offset":-14400,"profile":{"title":"","phone":"","skype":"","real_name":"Anna + Kim","real_name_normalized":"Anna Kim","display_name":"Anna Kim","display_name_normalized":"Anna + Kim","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"a203b1bd15bb","image_original":"https:\/\/avatars.slack-edge.com\/2020-10-06\/1434891540032_a203b1bd15bb3f14de6a_original.jpg","is_custom_image":true,"image_24":"https:\/\/avatars.slack-edge.com\/2020-10-06\/1434891540032_a203b1bd15bb3f14de6a_24.jpg","image_32":"https:\/\/avatars.slack-edge.com\/2020-10-06\/1434891540032_a203b1bd15bb3f14de6a_32.jpg","image_48":"https:\/\/avatars.slack-edge.com\/2020-10-06\/1434891540032_a203b1bd15bb3f14de6a_48.jpg","image_72":"https:\/\/avatars.slack-edge.com\/2020-10-06\/1434891540032_a203b1bd15bb3f14de6a_72.jpg","image_192":"https:\/\/avatars.slack-edge.com\/2020-10-06\/1434891540032_a203b1bd15bb3f14de6a_192.jpg","image_512":"https:\/\/avatars.slack-edge.com\/2020-10-06\/1434891540032_a203b1bd15bb3f14de6a_512.jpg","image_1024":"https:\/\/avatars.slack-edge.com\/2020-10-06\/1434891540032_a203b1bd15bb3f14de6a_1024.jpg","status_text_canonical":"","team":"T01C37A2BAP"},"is_admin":false,"is_owner":false,"is_primary_owner":false,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":1602015284,"has_2fa":false},{"id":"U01BWA0F1HU","team_id":"T01C37A2BAP","name":"c14_ida_api_project","deleted":false,"color":"3c989f","real_name":"C14 + - Ida - API Project","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight + Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"C14 + - Ida - API Project","real_name_normalized":"C14 - Ida - API Project","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g49c0e26fbc0","api_app_id":"A01C37SFXEX","always_active":false,"bot_id":"B01BN9RATAB","first_name":"C14","last_name":"- + Ida - API Project","image_24":"https:\/\/secure.gravatar.com\/avatar\/49c0e26fbc009f1477edb016e33c0538.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0010-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/49c0e26fbc009f1477edb016e33c0538.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0010-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/49c0e26fbc009f1477edb016e33c0538.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0010-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/49c0e26fbc009f1477edb016e33c0538.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0010-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/49c0e26fbc009f1477edb016e33c0538.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0010-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/49c0e26fbc009f1477edb016e33c0538.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0010-512.png","status_text_canonical":"","team":"T01C37A2BAP"},"is_admin":false,"is_owner":false,"is_primary_owner":false,"is_restricted":false,"is_ultra_restricted":false,"is_bot":true,"is_app_user":false,"updated":1602265137},{"id":"U01C321FX0S","team_id":"T01C37A2BAP","name":"fire_anna_api_project","deleted":false,"color":"e7392d","real_name":"Fire + - Anna - API Project","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight + Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Fire + - Anna - API Project","real_name_normalized":"Fire - Anna - API Project","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gb8fb0a1ad1a","api_app_id":"A01BZUFBESZ","always_active":false,"bot_id":"B01C384T91R","first_name":"Fire","last_name":"- + Anna - API Project","image_24":"https:\/\/secure.gravatar.com\/avatar\/b8fb0a1ad1a4a57f392bde7157d0e26f.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0000-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/b8fb0a1ad1a4a57f392bde7157d0e26f.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0000-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/b8fb0a1ad1a4a57f392bde7157d0e26f.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0000-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/b8fb0a1ad1a4a57f392bde7157d0e26f.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0000-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/b8fb0a1ad1a4a57f392bde7157d0e26f.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0000-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/b8fb0a1ad1a4a57f392bde7157d0e26f.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0000-512.png","status_text_canonical":"","team":"T01C37A2BAP"},"is_admin":false,"is_owner":false,"is_primary_owner":false,"is_restricted":false,"is_ultra_restricted":false,"is_bot":true,"is_app_user":false,"updated":1602196479},{"id":"U01C95Y5RUL","team_id":"T01C37A2BAP","name":"ida.goitom","deleted":false,"color":"9f69e7","real_name":"ida.goitom","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"ida.goitom","real_name_normalized":"ida.goitom","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g8213e08b600","image_24":"https:\/\/secure.gravatar.com\/avatar\/8213e08b600990ea9cc0628ea90eb078.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0006-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/8213e08b600990ea9cc0628ea90eb078.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0006-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/8213e08b600990ea9cc0628ea90eb078.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0006-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/8213e08b600990ea9cc0628ea90eb078.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0006-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/8213e08b600990ea9cc0628ea90eb078.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0006-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/8213e08b600990ea9cc0628ea90eb078.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0006-512.png","status_text_canonical":"","team":"T01C37A2BAP"},"is_admin":true,"is_owner":true,"is_primary_owner":true,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":1602015081,"has_2fa":false}],"cache_ts":1602265431,"response_metadata":{"next_cursor":""}}' + recorded_at: Fri, 09 Oct 2020 17:43:51 GMT +recorded_with: VCR 6.0.0 diff --git a/test/cassettes/workspace.yml b/test/cassettes/workspace.yml new file mode 100644 index 00000000..ebab3a35 --- /dev/null +++ b/test/cassettes/workspace.yml @@ -0,0 +1,150 @@ +--- +http_interactions: +- request: + method: get + uri: https://slack.com/api/users.list?token= + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 09 Oct 2020 17:43:46 GMT + Server: + - Apache + X-Slack-Req-Id: + - 656429dbe3999f0504d3078281b235e5 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + Access-Control-Allow-Origin: + - "*" + X-Slack-Backend: + - r + X-Content-Type-Options: + - nosniff + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - users:read + 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 + Vary: + - Accept-Encoding + Pragma: + - no-cache + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Content-Length: + - '1342' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-oxoh,haproxy-edge-pdx-8ea4 + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"T01C37A2BAP","name":"slackbot","deleted":false,"color":"757575","real_name":"Slackbot","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Slackbot","real_name_normalized":"Slackbot","display_name":"Slackbot","display_name_normalized":"Slackbot","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"sv41d8cd98f0","always_active":true,"first_name":"slackbot","last_name":"","image_24":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_24.png","image_32":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_32.png","image_48":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_48.png","image_72":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_72.png","image_192":"https:\/\/a.slack-edge.com\/80588\/marketing\/img\/avatars\/slackbot\/avatar-slackbot.png","image_512":"https:\/\/a.slack-edge.com\/80588\/img\/slackbot_512.png","status_text_canonical":"","team":"T01C37A2BAP"},"is_admin":false,"is_owner":false,"is_primary_owner":false,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":0},{"id":"U01BN903TU7","team_id":"T01C37A2BAP","name":"anna.kim93","deleted":false,"color":"4bbe2e","real_name":"Anna + Kim","tz":"America\/New_York","tz_label":"Eastern Daylight Time","tz_offset":-14400,"profile":{"title":"","phone":"","skype":"","real_name":"Anna + Kim","real_name_normalized":"Anna Kim","display_name":"Anna Kim","display_name_normalized":"Anna + Kim","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"a203b1bd15bb","image_original":"https:\/\/avatars.slack-edge.com\/2020-10-06\/1434891540032_a203b1bd15bb3f14de6a_original.jpg","is_custom_image":true,"image_24":"https:\/\/avatars.slack-edge.com\/2020-10-06\/1434891540032_a203b1bd15bb3f14de6a_24.jpg","image_32":"https:\/\/avatars.slack-edge.com\/2020-10-06\/1434891540032_a203b1bd15bb3f14de6a_32.jpg","image_48":"https:\/\/avatars.slack-edge.com\/2020-10-06\/1434891540032_a203b1bd15bb3f14de6a_48.jpg","image_72":"https:\/\/avatars.slack-edge.com\/2020-10-06\/1434891540032_a203b1bd15bb3f14de6a_72.jpg","image_192":"https:\/\/avatars.slack-edge.com\/2020-10-06\/1434891540032_a203b1bd15bb3f14de6a_192.jpg","image_512":"https:\/\/avatars.slack-edge.com\/2020-10-06\/1434891540032_a203b1bd15bb3f14de6a_512.jpg","image_1024":"https:\/\/avatars.slack-edge.com\/2020-10-06\/1434891540032_a203b1bd15bb3f14de6a_1024.jpg","status_text_canonical":"","team":"T01C37A2BAP"},"is_admin":false,"is_owner":false,"is_primary_owner":false,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":1602015284,"has_2fa":false},{"id":"U01BWA0F1HU","team_id":"T01C37A2BAP","name":"c14_ida_api_project","deleted":false,"color":"3c989f","real_name":"C14 + - Ida - API Project","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight + Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"C14 + - Ida - API Project","real_name_normalized":"C14 - Ida - API Project","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g49c0e26fbc0","api_app_id":"A01C37SFXEX","always_active":false,"bot_id":"B01BN9RATAB","first_name":"C14","last_name":"- + Ida - API Project","image_24":"https:\/\/secure.gravatar.com\/avatar\/49c0e26fbc009f1477edb016e33c0538.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0010-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/49c0e26fbc009f1477edb016e33c0538.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0010-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/49c0e26fbc009f1477edb016e33c0538.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0010-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/49c0e26fbc009f1477edb016e33c0538.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0010-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/49c0e26fbc009f1477edb016e33c0538.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0010-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/49c0e26fbc009f1477edb016e33c0538.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0010-512.png","status_text_canonical":"","team":"T01C37A2BAP"},"is_admin":false,"is_owner":false,"is_primary_owner":false,"is_restricted":false,"is_ultra_restricted":false,"is_bot":true,"is_app_user":false,"updated":1602265137},{"id":"U01C321FX0S","team_id":"T01C37A2BAP","name":"fire_anna_api_project","deleted":false,"color":"e7392d","real_name":"Fire + - Anna - API Project","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight + Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Fire + - Anna - API Project","real_name_normalized":"Fire - Anna - API Project","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gb8fb0a1ad1a","api_app_id":"A01BZUFBESZ","always_active":false,"bot_id":"B01C384T91R","first_name":"Fire","last_name":"- + Anna - API Project","image_24":"https:\/\/secure.gravatar.com\/avatar\/b8fb0a1ad1a4a57f392bde7157d0e26f.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0000-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/b8fb0a1ad1a4a57f392bde7157d0e26f.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0000-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/b8fb0a1ad1a4a57f392bde7157d0e26f.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0000-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/b8fb0a1ad1a4a57f392bde7157d0e26f.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0000-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/b8fb0a1ad1a4a57f392bde7157d0e26f.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0000-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/b8fb0a1ad1a4a57f392bde7157d0e26f.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0000-512.png","status_text_canonical":"","team":"T01C37A2BAP"},"is_admin":false,"is_owner":false,"is_primary_owner":false,"is_restricted":false,"is_ultra_restricted":false,"is_bot":true,"is_app_user":false,"updated":1602196479},{"id":"U01C95Y5RUL","team_id":"T01C37A2BAP","name":"ida.goitom","deleted":false,"color":"9f69e7","real_name":"ida.goitom","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"ida.goitom","real_name_normalized":"ida.goitom","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g8213e08b600","image_24":"https:\/\/secure.gravatar.com\/avatar\/8213e08b600990ea9cc0628ea90eb078.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0006-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/8213e08b600990ea9cc0628ea90eb078.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0006-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/8213e08b600990ea9cc0628ea90eb078.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0006-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/8213e08b600990ea9cc0628ea90eb078.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0006-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/8213e08b600990ea9cc0628ea90eb078.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0006-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/8213e08b600990ea9cc0628ea90eb078.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0006-512.png","status_text_canonical":"","team":"T01C37A2BAP"},"is_admin":true,"is_owner":true,"is_primary_owner":true,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"is_app_user":false,"updated":1602015081,"has_2fa":false}],"cache_ts":1602265426,"response_metadata":{"next_cursor":""}}' + recorded_at: Fri, 09 Oct 2020 17:43:46 GMT +- request: + method: get + uri: https://slack.com/api/conversations.list?token= + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 09 Oct 2020 17:43:46 GMT + Server: + - Apache + X-Slack-Req-Id: + - b51e2a4e145fcc744fe159ee4e19ee59 + X-Oauth-Scopes: + - identify,channels:read,users:read,chat:write + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + Access-Control-Allow-Origin: + - "*" + X-Slack-Backend: + - r + X-Content-Type-Options: + - nosniff + Expires: + - Mon, 26 Jul 1997 05:00:00 GMT + Cache-Control: + - private, no-cache, no-store, must-revalidate + X-Xss-Protection: + - '0' + X-Accepted-Oauth-Scopes: + - channels:read,groups:read,mpim:read,im:read,read + 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 + Vary: + - Accept-Encoding + Pragma: + - no-cache + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + Content-Length: + - '691' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-fe3y,haproxy-edge-pdx-ttqn + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"C01BW93UN8N","name":"random","is_channel":true,"is_group":false,"is_im":false,"created":1602015082,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"random","is_shared":false,"parent_conversation":null,"creator":"U01C95Y5RUL","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01C37A2BAP"],"pending_shared":[],"pending_connected_team_ids":[],"is_pending_ext_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"topic":{"value":"super + random!","creator":"U01BN903TU7","last_set":1602021102},"purpose":{"value":"This + channel is for... well, everything else. It\u2019s a place for team jokes, + spur-of-the-moment ideas, and funny GIFs. Go wild!","creator":"U01C95Y5RUL","last_set":1602015082},"previous_names":[],"num_members":4},{"id":"C01C37A2T1R","name":"general","is_channel":true,"is_group":false,"is_im":false,"created":1602015081,"is_archived":false,"is_general":true,"unlinked":0,"name_normalized":"general","is_shared":false,"parent_conversation":null,"creator":"U01C95Y5RUL","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01C37A2BAP"],"pending_shared":[],"pending_connected_team_ids":[],"is_pending_ext_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"topic":{"value":"very + general","creator":"U01BN903TU7","last_set":1602021116},"purpose":{"value":"This + is the one channel that will always include everyone. It\u2019s a great spot + for announcements and team-wide conversations.","creator":"U01C95Y5RUL","last_set":1602015081},"previous_names":[],"num_members":4},{"id":"C01CSS4N2QG","name":"slack-cli","is_channel":true,"is_group":false,"is_im":false,"created":1602015214,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"slack-cli","is_shared":false,"parent_conversation":null,"creator":"U01C95Y5RUL","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01C37A2BAP"],"pending_shared":[],"pending_connected_team_ids":[],"is_pending_ext_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"This + *channel* is for working on a project. Hold meetings, share docs, and make + decisions together with your team.","creator":"U01C95Y5RUL","last_set":1602015214},"previous_names":[],"num_members":2}],"response_metadata":{"next_cursor":""}}' + recorded_at: Fri, 09 Oct 2020 17:43:46 GMT +recorded_with: VCR 6.0.0 diff --git a/test/channel_test.rb b/test/channel_test.rb new file mode 100644 index 00000000..04e41b3e --- /dev/null +++ b/test/channel_test.rb @@ -0,0 +1,42 @@ +require_relative 'test_helper' + +describe "Channel class" do + + describe "list_all" do + it "get channels" do + VCR.use_cassette("channel") do + response = Channel.list_all + expect(response[0].name).wont_be_nil + expect(response[0].name).must_equal "random" + expect(response[0].slack_id).must_equal "C01BW93UN8N" + expect(response[0].member_count).must_equal 4 + end + end + end + + describe "send_message" do + it "recipient" do + VCR.use_cassette("channel") do + expect { + new_recipient = Channel.new(slack_id: "fake", name: "fake", topic: "fake", member_count: "fake") + new_recipient.send_message("This post should not work") + }.must_raise SlackApiError + end + end + it "sends a message to a channel" do + VCR.use_cassette("channel") do + new_recipient = Channel.new(slack_id: "C01BW93UN8N", name: "random", topic: "super random!", member_count: 3) + expect(new_recipient.send_message("hello testing").code).must_equal 200 + end + end + + end + + describe "details" do + it "must return correct details" do + test_channel = Channel.new(slack_id: "12345", name: "ida.goitom", topic: "happy", member_count: 5) + expect(test_channel.details).must_equal "Name: ida.goitom, ID: 12345, Topic: happy, Member count: 5" + end + end + +end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index 1fcf2bab..575ee716 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,7 +8,11 @@ require 'minitest/reporters' require 'minitest/skip_dsl' require 'vcr' +require "dotenv" +require_relative '../lib/workspace' +require_relative '../lib/slack' +Dotenv.load Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new VCR.configure do |config| @@ -25,5 +29,7 @@ } # Don't leave our token lying around in a cassette file. - + config.filter_sensitive_data("") do + ENV["SLACK_API_TOKEN"] + end end diff --git a/test/user_test.rb b/test/user_test.rb new file mode 100644 index 00000000..4bdeec0d --- /dev/null +++ b/test/user_test.rb @@ -0,0 +1,23 @@ +require_relative 'test_helper' + +describe "User class" do + + describe "list_all" do + it "get users" do + VCR.use_cassette("user") do + response = User.list_all + + expect(response[0].name).wont_be_nil + expect(response[0].name).must_equal "slackbot" + expect(response[0].real_name).must_equal "Slackbot" + end + end + end + + describe "details" do + it "must return correct details" do + test_user = User.new(slack_id: "891012", name: "anna" , real_name: "anna") + expect(test_user.details).must_equal "Name: anna, ID: 891012, Username: anna" + end + end +end diff --git a/test/workspace_test.rb b/test/workspace_test.rb new file mode 100644 index 00000000..b14a1ed0 --- /dev/null +++ b/test/workspace_test.rb @@ -0,0 +1,34 @@ +require_relative 'test_helper' + +describe "Workspace Class" do + let(:workspace) { Workspace.new } + + describe 'constructor' do + it 'is set up for specific attributes and data types' do + VCR.use_cassette("workspace") do + [:users, :channels, :selected].each do |prop| + expect(workspace).must_respond_to prop + end + end + end + end + + describe 'select_user' do + it "selects the user" do + VCR.use_cassette("workspace") do + workspace.select_user("ida.goitom") + expect(workspace.selected.name).must_equal "ida.goitom" + end + end + end + + describe 'select_channel' do + it "selects the right channel when provided name or ID" do + VCR.use_cassette("workspace") do + workspace.select_channel("random") + expect(workspace.selected.name).must_equal "random" + end + end + end +end +