From c64313a77cb9bb06543b9f87543ed73517b8e1cb Mon Sep 17 00:00:00 2001 From: OlgaSe Date: Tue, 6 Oct 2020 16:49:31 -0700 Subject: [PATCH 01/25] Created User class, Channel class, Recipient --- lib/channel.rb | 31 +++++++++++++++++++++++++++++++ lib/recipient.rb | 26 ++++++++++++++++++++++++++ lib/slack.rb | 13 +++++++++++++ lib/user.rb | 36 ++++++++++++++++++++++++++++++++++++ lib/workspace.rb | 8 ++++++++ test/test_helper.rb | 11 +++++------ 6 files changed, 119 insertions(+), 6 deletions(-) create mode 100644 lib/channel.rb create mode 100644 lib/recipient.rb create mode 100644 lib/user.rb create mode 100644 lib/workspace.rb diff --git a/lib/channel.rb b/lib/channel.rb new file mode 100644 index 00000000..ba55fd25 --- /dev/null +++ b/lib/channel.rb @@ -0,0 +1,31 @@ +require_relative 'recipient' + +require 'dotenv' + +Dotenv.load +BOT_TOKEN = ENV["SLACK_BOT_TOKEN"] +BASE_URL = "https://slack.com/api/conversations.list" + +class Channel < Recipient + attr_reader :topic, :member_count + + def initialize(topic, member_count) + @topic = topic + @member_count = member_count + end + + def details + + end + + def self.list_all + response = self.get(BASE_URL, { token: BOT_TOKEN }) + + channels_array = [] + response["channels"].each do |channels_hash| + channels_array << Channel.new(channels_hash["topic"], + channels_hash["num_members"]) + end + return channels_array + end +end \ No newline at end of file diff --git a/lib/recipient.rb b/lib/recipient.rb new file mode 100644 index 00000000..fc58d878 --- /dev/null +++ b/lib/recipient.rb @@ -0,0 +1,26 @@ +require 'httparty' + +class Recipient + attr_reader :slack_id, :name + + def initialize + @slack_id = slack_id + @name = name + end + + def send_message(message) + + end + + def self.get(url, params) + return HTTParty.get(url, query: params) + end + + def details + raise NotImplementedError + end + + def self.list_all + raise NotImplementedError + end +end \ No newline at end of file diff --git a/lib/slack.rb b/lib/slack.rb index 8a0b659b..653d275e 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,10 +1,23 @@ #!/usr/bin/env ruby +require_relative 'workspace' +require_relative 'user' def main puts "Welcome to the Ada Slack CLI!" workspace = Workspace.new # TODO project + puts "What would you like to do?" + puts "1. list users\n2. list channels\n3. quit" + print ">> " + user_input = gets.chomp.downcase + + if user_input == "list users" + puts User.list_all + elsif user_input == "list channels" + elsif user_input == "quit" + exit + end puts "Thank you for using the Ada Slack CLI" end diff --git a/lib/user.rb b/lib/user.rb new file mode 100644 index 00000000..cc26372f --- /dev/null +++ b/lib/user.rb @@ -0,0 +1,36 @@ +require_relative 'recipient' + +require 'dotenv' + +Dotenv.load +BOT_TOKEN = ENV["SLACK_BOT_TOKEN"] + +BASE_URL = "https://slack.com/api/users.list" + +class User < Recipient + attr_reader :real_name, :status_text, :status_emoji + + def initialize(real_name, status_text, status_emoji) + @real_name = real_name + @status_text = status_text + @status_emoji = status_emoji + end + + def details + + end + + def self.list_all + response = self.get(BASE_URL, { token: BOT_TOKEN }) + + user_array = [] + response["members"].each do |members_hash| + user_array << User.new(members_hash["profile"]["real_name"], + members_hash["profile"]["status_text"], + members_hash["profile"]["status_emoji"]) + end + + return user_array + end + +end \ No newline at end of file diff --git a/lib/workspace.rb b/lib/workspace.rb new file mode 100644 index 00000000..a63baaff --- /dev/null +++ b/lib/workspace.rb @@ -0,0 +1,8 @@ +class Workspace + attr_reader :users, :channels + + def initialize + @users = [] + @channels = [] + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 1fcf2bab..f0e3f366 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,14 +8,11 @@ require 'minitest/reporters' require 'minitest/skip_dsl' require 'vcr' +require "dotenv" +Dotenv.load Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new -VCR.configure do |config| - config.cassette_library_dir = "test/cassettes" - config.hook_into :webmock -end - VCR.configure do |config| config.cassette_library_dir = "test/cassettes" # folder where casettes will be located config.hook_into :webmock # tie into this other tool called webmock @@ -25,5 +22,7 @@ } # Don't leave our token lying around in a cassette file. - + config.filter_sensitive_data("") do + ENV["SLACK_BOT_TOKEN"] + end end From de592f0a7e1552b95ed9642ac884ad03550fdd4b Mon Sep 17 00:00:00 2001 From: beauttie Date: Wed, 7 Oct 2020 01:51:34 -0700 Subject: [PATCH 02/25] Refactor methods and use Table Print gem to format output --- .gitignore | 2 +- lib/channel.rb | 25 +++++++++++-------------- lib/recipient.rb | 10 +++++++--- lib/slack.rb | 22 ++++++++++++++++------ lib/user.rb | 21 +++++++-------------- lib/workspace.rb | 18 ++++++++++++++++-- 6 files changed, 58 insertions(+), 40 deletions(-) diff --git a/.gitignore b/.gitignore index 3ff4fada..82cc5be2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ .DS_Store -# Ignore environemnt variables +# Ignore environment variables .env diff --git a/lib/channel.rb b/lib/channel.rb index ba55fd25..5c9c6d1f 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,15 +1,12 @@ require_relative 'recipient' -require 'dotenv' - -Dotenv.load -BOT_TOKEN = ENV["SLACK_BOT_TOKEN"] -BASE_URL = "https://slack.com/api/conversations.list" +CHANNEL_BASE_URL = "https://slack.com/api/conversations.list" class Channel < Recipient attr_reader :topic, :member_count - def initialize(topic, member_count) + def initialize(slack_id, name, topic, member_count) + super(slack_id, name) @topic = topic @member_count = member_count end @@ -19,13 +16,13 @@ def details end def self.list_all - response = self.get(BASE_URL, { token: BOT_TOKEN }) - - channels_array = [] - response["channels"].each do |channels_hash| - channels_array << Channel.new(channels_hash["topic"], - channels_hash["num_members"]) - end - return channels_array + response = self.get(CHANNEL_BASE_URL, { token: BOT_TOKEN }) + + channels_list = response["channels"].map do |channels_hash| + Channel.new(channels_hash["id"], channels_hash["name"], channels_hash["topic"], channels_hash["num_members"]) + end + + return channels_list end + end \ No newline at end of file diff --git a/lib/recipient.rb b/lib/recipient.rb index fc58d878..190857ef 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,9 +1,13 @@ require 'httparty' +require 'dotenv' + +Dotenv.load +BOT_TOKEN = ENV["SLACK_BOT_TOKEN"] class Recipient attr_reader :slack_id, :name - def initialize + def initialize(slack_id, name) @slack_id = slack_id @name = name end @@ -17,10 +21,10 @@ def self.get(url, params) end def details - raise NotImplementedError + raise NotImplementedError, "Implement me in a child class!" end def self.list_all - raise NotImplementedError + 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 653d275e..13faa6e9 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,25 +1,35 @@ #!/usr/bin/env ruby require_relative 'workspace' require_relative 'user' +require_relative 'channel' def main puts "Welcome to the Ada Slack CLI!" workspace = Workspace.new # TODO project - puts "What would you like to do?" + puts "What do you want to do?" puts "1. list users\n2. list channels\n3. quit" print ">> " + user_input = gets.chomp.downcase - if user_input == "list users" - puts User.list_all - elsif user_input == "list channels" - elsif user_input == "quit" - exit + until user_input == "quit" + case user_input + when "list users" + workspace.list_users + when "list channels" + workspace.list_channels + else + puts "Invalid input. Try again." + end + + print "What do you want to do next? " + user_input = gets.chomp.downcase end puts "Thank you for using the Ada Slack CLI" + exit end main if __FILE__ == $PROGRAM_NAME \ No newline at end of file diff --git a/lib/user.rb b/lib/user.rb index cc26372f..7aacd505 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,16 +1,12 @@ require_relative 'recipient' -require 'dotenv' - -Dotenv.load -BOT_TOKEN = ENV["SLACK_BOT_TOKEN"] - -BASE_URL = "https://slack.com/api/users.list" +USER_BASE_URL = "https://slack.com/api/users.list" class User < Recipient attr_reader :real_name, :status_text, :status_emoji - def initialize(real_name, status_text, status_emoji) + def initialize(slack_id, name, real_name, status_text, status_emoji) + super(slack_id, name) @real_name = real_name @status_text = status_text @status_emoji = status_emoji @@ -21,16 +17,13 @@ def details end def self.list_all - response = self.get(BASE_URL, { token: BOT_TOKEN }) + response = self.get(USER_BASE_URL, { token: BOT_TOKEN }) - user_array = [] - response["members"].each do |members_hash| - user_array << User.new(members_hash["profile"]["real_name"], - members_hash["profile"]["status_text"], - members_hash["profile"]["status_emoji"]) + users_list = response["members"].map do |members_hash| + User.new(members_hash["id"], members_hash["name"], members_hash["profile"]["real_name"], members_hash["profile"]["status_text"], members_hash["profile"]["status_emoji"]) end - return user_array + return users_list end end \ No newline at end of file diff --git a/lib/workspace.rb b/lib/workspace.rb index a63baaff..1a6361f5 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -1,8 +1,22 @@ +require 'table_print' + +require_relative 'user' +require_relative 'channel' + class Workspace attr_reader :users, :channels def initialize - @users = [] - @channels = [] + @users = User.list_all + @channels = Channel.list_all + end + + def list_users + tp @users, "slack_id", "name", "real_name", "status_text", "status_emoji" end + + def list_channels + tp @channels, "slack_id", "name", "topic", "member_count" + end + end From 07f2d4116d874410aa571089eb02d67d77a9190b Mon Sep 17 00:00:00 2001 From: beauttie Date: Wed, 7 Oct 2020 12:18:20 -0700 Subject: [PATCH 03/25] Implement select_user and select_channel methods --- lib/channel.rb | 2 ++ lib/recipient.rb | 2 ++ lib/slack.rb | 16 +++++++++++++--- lib/user.rb | 4 +++- lib/workspace.rb | 13 +++++++++++++ test/test_helper.rb | 4 ++-- 6 files changed, 35 insertions(+), 6 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 5c9c6d1f..db0b6c4b 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -18,6 +18,8 @@ def details def self.list_all response = self.get(CHANNEL_BASE_URL, { token: BOT_TOKEN }) + raise SlackApiError, "API call failed with error: #{response["error"]}" if ! response["ok"] + channels_list = response["channels"].map do |channels_hash| Channel.new(channels_hash["id"], channels_hash["name"], channels_hash["topic"], channels_hash["num_members"]) end diff --git a/lib/recipient.rb b/lib/recipient.rb index 190857ef..c05c8277 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -5,6 +5,8 @@ BOT_TOKEN = ENV["SLACK_BOT_TOKEN"] class Recipient + class SlackApiError < Exception; end + attr_reader :slack_id, :name def initialize(slack_id, name) diff --git a/lib/slack.rb b/lib/slack.rb index 13faa6e9..5676d6c0 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -1,7 +1,5 @@ #!/usr/bin/env ruby require_relative 'workspace' -require_relative 'user' -require_relative 'channel' def main puts "Welcome to the Ada Slack CLI!" @@ -9,7 +7,7 @@ def main # TODO project puts "What do you want to do?" - puts "1. list users\n2. list channels\n3. quit" + puts "1. list users\n2. list channels\n3. select user\n4. select channel\n5. details\n6. quit" print ">> " user_input = gets.chomp.downcase @@ -20,6 +18,18 @@ def main workspace.list_users when "list channels" workspace.list_channels + when "select user" + print "Enter the user's name or Slack ID: " + user_input = gets.chomp + + puts workspace.select_user(user_input) + when "select channel" + print "Enter the channel's name or Slack ID: " + user_input = gets.chomp + + puts workspace.select_channel(user_input) + when "details" + else puts "Invalid input. Try again." end diff --git a/lib/user.rb b/lib/user.rb index 7aacd505..afcdf655 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -12,13 +12,15 @@ def initialize(slack_id, name, real_name, status_text, status_emoji) @status_emoji = status_emoji end - def details + def details(self) end def self.list_all response = self.get(USER_BASE_URL, { token: BOT_TOKEN }) + raise SlackApiError, "API call failed with error: #{response["error"]}" if ! response["ok"] + users_list = response["members"].map do |members_hash| User.new(members_hash["id"], members_hash["name"], members_hash["profile"]["real_name"], members_hash["profile"]["status_text"], members_hash["profile"]["status_emoji"]) end diff --git a/lib/workspace.rb b/lib/workspace.rb index 1a6361f5..9e4ece77 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -19,4 +19,17 @@ def list_channels tp @channels, "slack_id", "name", "topic", "member_count" end + def select_user(id_or_name) + return @users.select { |user| user.slack_id == id_or_name || user.name == id_or_name } + end + + def select_channel(id_or_name) + return @channels.select { |channel| channel.slack_id == id_or_name || channel.name == id_or_name } + end + + def show_details + # tp select_user(id_or_name), "slack_id", "name", "real_name", "status_text", "status_emoji" + # tp select_channel(id_or_name), "slack_id", "name", "topic", "member_count" + end + end diff --git a/test/test_helper.rb b/test/test_helper.rb index f0e3f366..7d6ed69c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -14,7 +14,7 @@ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new VCR.configure do |config| - config.cassette_library_dir = "test/cassettes" # folder where casettes will be located + config.cassette_library_dir = "test/cassettes" # folder where cassettes will be located config.hook_into :webmock # tie into this other tool called webmock config.default_cassette_options = { :record => :new_episodes, # record new data when we don't have it yet @@ -22,7 +22,7 @@ } # Don't leave our token lying around in a cassette file. - config.filter_sensitive_data("") do + config.filter_sensitive_data("") do ENV["SLACK_BOT_TOKEN"] end end From 9a43b8ae6b3576a2f75173ea60a978a8d09ffa86 Mon Sep 17 00:00:00 2001 From: beauttie Date: Wed, 7 Oct 2020 12:24:22 -0700 Subject: [PATCH 04/25] Brainstorm for show_details method --- lib/workspace.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index 9e4ece77..d1383ebb 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -4,11 +4,12 @@ require_relative 'channel' class Workspace - attr_reader :users, :channels + attr_reader :users, :channels, :selected - def initialize + def initialize(selected = nil) @users = User.list_all @channels = Channel.list_all + @selected = selected end def list_users @@ -20,14 +21,15 @@ def list_channels end def select_user(id_or_name) - return @users.select { |user| user.slack_id == id_or_name || user.name == id_or_name } + @selected = @users.select { |user| user.slack_id == id_or_name || user.name == id_or_name } end def select_channel(id_or_name) - return @channels.select { |channel| channel.slack_id == id_or_name || channel.name == id_or_name } + @selected = @channels.select { |channel| channel.slack_id == id_or_name || channel.name == id_or_name } end def show_details + # check value of @selected # tp select_user(id_or_name), "slack_id", "name", "real_name", "status_text", "status_emoji" # tp select_channel(id_or_name), "slack_id", "name", "topic", "member_count" end From aa1712d6c40f536b56bc3d9fe31db91556e8f4af Mon Sep 17 00:00:00 2001 From: OlgaSe Date: Wed, 7 Oct 2020 14:42:34 -0700 Subject: [PATCH 05/25] added details methods --- lib/slack.rb | 2 +- lib/user.rb | 4 ++-- lib/workspace.rb | 8 ++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/slack.rb b/lib/slack.rb index 5676d6c0..b61edbbb 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -29,7 +29,7 @@ def main puts workspace.select_channel(user_input) when "details" - + workspace.show_details else puts "Invalid input. Try again." end diff --git a/lib/user.rb b/lib/user.rb index afcdf655..f9a55613 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -12,8 +12,8 @@ def initialize(slack_id, name, real_name, status_text, status_emoji) @status_emoji = status_emoji end - def details(self) - + def details + "User: #{@slack_id}, Name: #{@name}, real name: #{@real_name}" end def self.list_all diff --git a/lib/workspace.rb b/lib/workspace.rb index d1383ebb..9d23c66b 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -20,15 +20,19 @@ def list_channels tp @channels, "slack_id", "name", "topic", "member_count" end + #replaced select by find, because it returned an array def select_user(id_or_name) - @selected = @users.select { |user| user.slack_id == id_or_name || user.name == id_or_name } + @selected = @users.find { |user| user.slack_id == id_or_name || user.name == id_or_name } end def select_channel(id_or_name) - @selected = @channels.select { |channel| channel.slack_id == id_or_name || channel.name == id_or_name } + @selected = @channels.find { |channel| channel.slack_id == id_or_name || channel.name == id_or_name } end def show_details + puts @selected.details + + # check value of @selected # tp select_user(id_or_name), "slack_id", "name", "real_name", "status_text", "status_emoji" # tp select_channel(id_or_name), "slack_id", "name", "topic", "member_count" From 00b808ae2db531699f0c477d35f1a128eb37a62d Mon Sep 17 00:00:00 2001 From: OlgaSe Date: Wed, 7 Oct 2020 15:51:27 -0700 Subject: [PATCH 06/25] added Argument Error check forselect_user and select_channel methods --- lib/channel.rb | 2 +- lib/workspace.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/channel.rb b/lib/channel.rb index db0b6c4b..af3f0fbd 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -12,7 +12,7 @@ def initialize(slack_id, name, topic, member_count) end def details - + "Channel name: #{@slack_id}, Name: #{@name}, Topic: #{@topic}, Member count: #{@member_count}" end def self.list_all diff --git a/lib/workspace.rb b/lib/workspace.rb index 9d23c66b..1ee7743e 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -23,10 +23,14 @@ def list_channels #replaced select by find, because it returned an array def select_user(id_or_name) @selected = @users.find { |user| user.slack_id == id_or_name || user.name == id_or_name } + + raise ArgumentError, "User with that name or Slack ID not found" if @selected.nil? end def select_channel(id_or_name) @selected = @channels.find { |channel| channel.slack_id == id_or_name || channel.name == id_or_name } + + raise ArgumentError, "Channel with that name or Slack ID not found" if @selected.nil? end def show_details From b104162af4dae6a1f2fc7a9a2b344424195b5974 Mon Sep 17 00:00:00 2001 From: beauttie Date: Wed, 7 Oct 2020 16:12:44 -0700 Subject: [PATCH 07/25] Move SlackApiError to parent class, modify details output for User and Channel classes, create test files --- lib/channel.rb | 4 +--- lib/recipient.rb | 5 ++++- lib/slack.rb | 6 ++++-- lib/user.rb | 4 +--- lib/workspace.rb | 9 ++------- test/channel_test.rb | 1 + test/user_test.rb | 1 + test/workspace_test.rb | 1 + 8 files changed, 15 insertions(+), 16 deletions(-) create mode 100644 test/channel_test.rb create mode 100644 test/user_test.rb create mode 100644 test/workspace_test.rb diff --git a/lib/channel.rb b/lib/channel.rb index af3f0fbd..1c81fc48 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -12,14 +12,12 @@ def initialize(slack_id, name, topic, member_count) end def details - "Channel name: #{@slack_id}, Name: #{@name}, Topic: #{@topic}, Member count: #{@member_count}" + "Channel details => ID: #{@slack_id}, Name: #{@name}, Topic: #{@topic}, Member Count: #{@member_count}" end def self.list_all response = self.get(CHANNEL_BASE_URL, { token: BOT_TOKEN }) - raise SlackApiError, "API call failed with error: #{response["error"]}" if ! response["ok"] - channels_list = response["channels"].map do |channels_hash| Channel.new(channels_hash["id"], channels_hash["name"], channels_hash["topic"], channels_hash["num_members"]) end diff --git a/lib/recipient.rb b/lib/recipient.rb index c05c8277..496f3516 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -19,7 +19,10 @@ def send_message(message) end def self.get(url, params) - return HTTParty.get(url, query: params) + response = HTTParty.get(url, query: params) + + raise SlackApiError, "API call failed with error: #{response["error"]}" if ! response["ok"] + return response end def details diff --git a/lib/slack.rb b/lib/slack.rb index b61edbbb..efc6afa1 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -7,7 +7,7 @@ def main # TODO project puts "What do you want to do?" - puts "1. list users\n2. list channels\n3. select user\n4. select channel\n5. details\n6. quit" + puts "1. list users\n2. list channels\n3. select user\n4. select channel\n5. details\n6. send message\n7. quit" print ">> " user_input = gets.chomp.downcase @@ -29,7 +29,9 @@ def main puts workspace.select_channel(user_input) when "details" - workspace.show_details + puts workspace.show_details + when "send message" + else puts "Invalid input. Try again." end diff --git a/lib/user.rb b/lib/user.rb index f9a55613..17c8cdd4 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -13,14 +13,12 @@ def initialize(slack_id, name, real_name, status_text, status_emoji) end def details - "User: #{@slack_id}, Name: #{@name}, real name: #{@real_name}" + "User details => ID: #{@slack_id}, Name: #{@name}, Real Name: #{@real_name}, Status Text: #{@status_text}, Status Emoji: #{@status_emoji}" end def self.list_all response = self.get(USER_BASE_URL, { token: BOT_TOKEN }) - raise SlackApiError, "API call failed with error: #{response["error"]}" if ! response["ok"] - users_list = response["members"].map do |members_hash| User.new(members_hash["id"], members_hash["name"], members_hash["profile"]["real_name"], members_hash["profile"]["status_text"], members_hash["profile"]["status_emoji"]) end diff --git a/lib/workspace.rb b/lib/workspace.rb index 1ee7743e..184ae431 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -20,7 +20,6 @@ def list_channels tp @channels, "slack_id", "name", "topic", "member_count" end - #replaced select by find, because it returned an array def select_user(id_or_name) @selected = @users.find { |user| user.slack_id == id_or_name || user.name == id_or_name } @@ -34,12 +33,8 @@ def select_channel(id_or_name) end def show_details - puts @selected.details - - - # check value of @selected - # tp select_user(id_or_name), "slack_id", "name", "real_name", "status_text", "status_emoji" - # tp select_channel(id_or_name), "slack_id", "name", "topic", "member_count" + raise NoMethodError, "No recipient is currently selected" if @selected.nil? + return @selected.details end end diff --git a/test/channel_test.rb b/test/channel_test.rb new file mode 100644 index 00000000..2bac53cd --- /dev/null +++ b/test/channel_test.rb @@ -0,0 +1 @@ +require_relative 'test_helper' \ No newline at end of file diff --git a/test/user_test.rb b/test/user_test.rb new file mode 100644 index 00000000..2bac53cd --- /dev/null +++ b/test/user_test.rb @@ -0,0 +1 @@ +require_relative 'test_helper' \ No newline at end of file diff --git a/test/workspace_test.rb b/test/workspace_test.rb new file mode 100644 index 00000000..2bac53cd --- /dev/null +++ b/test/workspace_test.rb @@ -0,0 +1 @@ +require_relative 'test_helper' \ No newline at end of file From a1cfe338c23ab91fa904cc368ea66e21907af9dd Mon Sep 17 00:00:00 2001 From: beauttie Date: Wed, 7 Oct 2020 18:02:31 -0700 Subject: [PATCH 08/25] Clean up code --- lib/channel.rb | 7 +++++-- lib/user.rb | 8 ++++++-- lib/workspace.rb | 14 +++++++++----- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/channel.rb b/lib/channel.rb index 1c81fc48..98ea9c21 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -12,14 +12,17 @@ def initialize(slack_id, name, topic, member_count) end def details - "Channel details => ID: #{@slack_id}, Name: #{@name}, Topic: #{@topic}, Member Count: #{@member_count}" + return "Channel #{@name}'s topic is #{@topic} and has #{@member_count} members. Its ID on Slack is #{@slack_id}." end def self.list_all response = self.get(CHANNEL_BASE_URL, { token: BOT_TOKEN }) channels_list = response["channels"].map do |channels_hash| - Channel.new(channels_hash["id"], channels_hash["name"], channels_hash["topic"], channels_hash["num_members"]) + self.new(channels_hash["id"], + channels_hash["name"], + channels_hash["topic"]["value"], + channels_hash["num_members"]) end return channels_list diff --git a/lib/user.rb b/lib/user.rb index 17c8cdd4..f808c44c 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -13,14 +13,18 @@ def initialize(slack_id, name, real_name, status_text, status_emoji) end def details - "User details => ID: #{@slack_id}, Name: #{@name}, Real Name: #{@real_name}, Status Text: #{@status_text}, Status Emoji: #{@status_emoji}" + return "User #{@name}'s real name is #{@real_name}, and their ID on Slack is #{@slack_id}. Their current status reads: #{@status_text} #{@status_emoji}." end def self.list_all response = self.get(USER_BASE_URL, { token: BOT_TOKEN }) users_list = response["members"].map do |members_hash| - User.new(members_hash["id"], members_hash["name"], members_hash["profile"]["real_name"], members_hash["profile"]["status_text"], members_hash["profile"]["status_emoji"]) + self.new(members_hash["id"], + members_hash["name"], + members_hash["profile"]["real_name"], + members_hash["profile"]["status_text"], + members_hash["profile"]["status_emoji"]) end return users_list diff --git a/lib/workspace.rb b/lib/workspace.rb index 184ae431..3572b6ae 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -6,10 +6,10 @@ class Workspace attr_reader :users, :channels, :selected - def initialize(selected = nil) + def initialize @users = User.list_all @channels = Channel.list_all - @selected = selected + @selected = nil end def list_users @@ -20,20 +20,24 @@ def list_channels tp @channels, "slack_id", "name", "topic", "member_count" end + def no_recipient + return @selected.nil? + end + def select_user(id_or_name) @selected = @users.find { |user| user.slack_id == id_or_name || user.name == id_or_name } - raise ArgumentError, "User with that name or Slack ID not found" if @selected.nil? + raise ArgumentError, "User with that name or Slack ID not found" if no_recipient end def select_channel(id_or_name) @selected = @channels.find { |channel| channel.slack_id == id_or_name || channel.name == id_or_name } - raise ArgumentError, "Channel with that name or Slack ID not found" if @selected.nil? + raise ArgumentError, "Channel with that name or Slack ID not found" if no_recipient end def show_details - raise NoMethodError, "No recipient is currently selected" if @selected.nil? + raise NoMethodError, "No recipient is currently selected" if no_recipient return @selected.details end From d3424589b09ea8a56f0926e631065d13fcfd1a96 Mon Sep 17 00:00:00 2001 From: OlgaSe Date: Wed, 7 Oct 2020 23:52:41 -0700 Subject: [PATCH 09/25] added tests for user's methods details and list_all --- test/cassettes/list_all.yml | 71 +++++++++++++++++++++++++++++++++++++ test/user_test.rb | 21 ++++++++++- 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 test/cassettes/list_all.yml diff --git a/test/cassettes/list_all.yml b/test/cassettes/list_all.yml new file mode 100644 index 00000000..4898c870 --- /dev/null +++ b/test/cassettes/list_all.yml @@ -0,0 +1,71 @@ +--- +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: + - Thu, 08 Oct 2020 06:30:23 GMT + Server: + - Apache + X-Slack-Req-Id: + - 26ffb3d3c78112f3ce4a9bde6697344e + X-Oauth-Scopes: + - chat:write,channels:read,users: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: + - 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: + - '1245' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-jtpc,haproxy-edge-pdx-uehx + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"U01CQMA06F2","team_id":"T01CQM3LG6L","name":"bak02013","deleted":false,"color":"4bbe2e","real_name":"Beauttie","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Beauttie","real_name_normalized":"Beauttie","display_name":"Beauttie","display_name_normalized":"Beauttie","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g51d0ec2dd94","image_24":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601958823},{"id":"U01CQMN9XR6","team_id":"T01CQM3LG6L","name":"beauttie_api_project","deleted":false,"color":"e7392d","real_name":"Earth + - Beauttie - API Project","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Earth + - Beauttie - API Project","real_name_normalized":"Earth - Beauttie - API Project","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g55b958146df","api_app_id":"A01BL47ENLX","always_active":false,"bot_id":"B01BU4SJZT8","first_name":"Earth","last_name":"- + Beauttie - API Project","image_24":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601961016}],"cache_ts":1602138624,"response_metadata":{"next_cursor":""}}' + recorded_at: Thu, 08 Oct 2020 06:30:24 GMT +recorded_with: VCR 6.0.0 diff --git a/test/user_test.rb b/test/user_test.rb index 2bac53cd..37ffcf12 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -1 +1,20 @@ -require_relative 'test_helper' \ No newline at end of file +require_relative 'test_helper' +require_relative '../lib/user' + +describe User do + + it "return a specific values for user's attributes" do + user = User.new("USLACKBOT", "slackbot", "Slackbot", "","") + expect(user.details).must_equal "User slackbot's real name is Slackbot, and their ID on Slack is USLACKBOT. Their current status reads: ." + end + + it "return an instance array class" do + VCR.use_cassette("list all") do + users = User.list_all + expect(users).must_be_kind_of Array + expect(users.length).must_equal 2 + # expect(users).must_equal [User.new("U01CQMA06F2", "bak02013", "Beauttie", '', ''), User.new("U01CQMN9XR6", "beauttie_api_project", "Earth - Beauttie - API Project", '', '' )] + end + end +end + From a74b1dbae9a9c1816e4235c8eca25afe882ff735 Mon Sep 17 00:00:00 2001 From: beauttie Date: Thu, 8 Oct 2020 00:45:41 -0700 Subject: [PATCH 10/25] Add test for Channel class --- lib/workspace.rb | 8 ++++--- test/channel_test.rb | 57 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index 3572b6ae..c0128ba5 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -27,17 +27,19 @@ def no_recipient def select_user(id_or_name) @selected = @users.find { |user| user.slack_id == id_or_name || user.name == id_or_name } - raise ArgumentError, "User with that name or Slack ID not found" if no_recipient + raise ArgumentError, "User with that name or Slack ID not found." if no_recipient + return "User selected." end def select_channel(id_or_name) @selected = @channels.find { |channel| channel.slack_id == id_or_name || channel.name == id_or_name } - raise ArgumentError, "Channel with that name or Slack ID not found" if no_recipient + raise ArgumentError, "Channel with that name or Slack ID not found." if no_recipient + return "Channel selected." end def show_details - raise NoMethodError, "No recipient is currently selected" if no_recipient + raise NoMethodError, "No recipient is currently selected." if no_recipient return @selected.details end diff --git a/test/channel_test.rb b/test/channel_test.rb index 2bac53cd..ce233208 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -1 +1,56 @@ -require_relative 'test_helper' \ No newline at end of file +require_relative 'test_helper' +require_relative '../lib/channel' + +describe "Channel class" do + describe "Channel instantiation" do + before do + @channel = Channel.new("1", "Test Channel", "Anything", 2) + end + + it "is an instance of Channel" do + expect(@channel).must_be_kind_of Channel + end + + it "is set up for specific attributes and data types" do + [:details, :list_all].each do |prop| + expect(@channel).must_respond_to prop + end + + expect(@channel.slack_id).must_be_kind_of String + expect(@channel.name).must_be_kind_of String + expect(@channel.topic).must_be_kind_of String + expect(@channel.status).must_be_kind_of Integer + end + end + + describe "list_all method" do + it "returns an Array of Channels" do + VCR.use_cassette("list_channels") do + channels_list = Channel.list_all + + expect(channels_list).must_be_kind_of Array + expect(channels_list.all?(Channel)).must_equal true + + expect(channels_list.length).must_equal 3 + end + end + end + + describe "details method" do + before do + @channel = Channel.new("1", "Test Channel", "Anything", 2) + end + + it "returns a String including specific attributes" do + channel_details = @channel.details + + expect(channel_details).must_be_kind_of String + + expect(channel_details).must_include @channel.slack_id + expect(channel_details).must_include @channel.name + expect(channel_details).must_include @channel.topic + expect(channel_details).must_include @channel.member_count + end + end + +end From a8eb562f3e6ad4db5a59108558f7b3f667a9cb58 Mon Sep 17 00:00:00 2001 From: beauttie Date: Thu, 8 Oct 2020 01:13:47 -0700 Subject: [PATCH 11/25] Add tests for Channel and Workspace classes --- test/channel_test.rb | 14 +++++++++++-- test/workspace_test.rb | 47 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/test/channel_test.rb b/test/channel_test.rb index ce233208..8a164e50 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -4,7 +4,7 @@ describe "Channel class" do describe "Channel instantiation" do before do - @channel = Channel.new("1", "Test Channel", "Anything", 2) + @channel = Channel.new("420", "weed", "the good kind of weed", 1) end it "is an instance of Channel" do @@ -34,11 +34,21 @@ expect(channels_list.length).must_equal 3 end end + + it "raises an error when token is not provided" do + VCR.use_cassette("list_channels") do + response = Channel.get(CHANNEL_BASE_URL) + + expect{ response }.must_raise SlackApiError + expect(response["ok"]).must_equal false + expect(response["error"]).must_equal "not_authed" + end + end end describe "details method" do before do - @channel = Channel.new("1", "Test Channel", "Anything", 2) + @channel = Channel.new("420", "weed", "the good kind of weed", 1) end it "returns a String including specific attributes" do diff --git a/test/workspace_test.rb b/test/workspace_test.rb index 2bac53cd..db380d88 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -1 +1,46 @@ -require_relative 'test_helper' \ No newline at end of file +require_relative 'test_helper' +require_relative '../lib/workspace' + +describe "Workspace class" do + describe "Workspace instantiation" do + before do + @workspace = Workspace.new + end + + it "is an instance of Workspace" do + expect(@workspace).must_be_kind_of Workspace + end + + it "is set up for specific attributes and data types" do + [:list_users, :list_channels, :no_recipient, :select_user, :select_channel, :show_details].each do |prop| + expect(@workspace).must_respond_to prop + end + + expect(@workspace.users).must_be_kind_of Array + expect(@workspace.users.all?(User)).must_equal true + expect(@workspace.channels).must_be_kind_of Array + expect(@workspace.users.all?(Channel)).must_equal true + expect(@workspace.selected).must_be_nil + end + end + + describe "no_recipient method" do + it "returns a Boolean" do + workspace = Workspace.new + + expect(workspace.no_recipient).must_be_kind_of Boolean + end + end + + describe "select_user method" do + + end + + describe "select_channel method" do + + end + + describe "show_details method" do + + end +end \ No newline at end of file From cfdd460a205e9cb0a0ec2999cedd3497ad5a9e64 Mon Sep 17 00:00:00 2001 From: beauttie Date: Thu, 8 Oct 2020 11:04:15 -0700 Subject: [PATCH 12/25] Fix tests for channel --- test/cassettes/list_channels.yml | 72 ++++++++++++++++++++++++++++++++ test/channel_test.rb | 31 +++++++------- test/workspace_test.rb | 2 +- 3 files changed, 88 insertions(+), 17 deletions(-) create mode 100644 test/cassettes/list_channels.yml diff --git a/test/cassettes/list_channels.yml b/test/cassettes/list_channels.yml new file mode 100644 index 00000000..712eded5 --- /dev/null +++ b/test/cassettes/list_channels.yml @@ -0,0 +1,72 @@ +--- +http_interactions: +- 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: + - Thu, 08 Oct 2020 18:01:53 GMT + Server: + - Apache + X-Slack-Req-Id: + - 9cf94a4b2747d11335e2b08365753855 + X-Oauth-Scopes: + - chat:write,channels:read,users:read,groups:read,im:read,mpim: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: + - 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: + - '638' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-xozz,haproxy-edge-iad-rwys + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"C01C0RQN3H8","name":"general","is_channel":true,"is_group":false,"is_im":false,"created":1601958469,"is_archived":false,"is_general":true,"unlinked":0,"name_normalized":"general","is_shared":false,"parent_conversation":null,"creator":"U01C12E4CF5","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"pending_shared":[],"pending_connected_team_ids":[],"is_pending_ext_shared":false,"is_member":false,"is_private":false,"is_mpim":false,"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"This + is the one channel that will always include everyone. It\u2019s a great spot + for announcements and team-wide conversations.","creator":"U01C12E4CF5","last_set":1601958469},"previous_names":[],"num_members":2},{"id":"C01CQM3LQ5N","name":"random","is_channel":true,"is_group":false,"is_im":false,"created":1601958469,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"random","is_shared":false,"parent_conversation":null,"creator":"U01C12E4CF5","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"pending_shared":[],"pending_connected_team_ids":[],"is_pending_ext_shared":false,"is_member":false,"is_private":false,"is_mpim":false,"topic":{"value":"","creator":"","last_set":0},"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":"U01C12E4CF5","last_set":1601958469},"previous_names":[],"num_members":2},{"id":"C01CQMA6E56","name":"testing","is_channel":true,"is_group":false,"is_im":false,"created":1601958837,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"testing","is_shared":false,"parent_conversation":null,"creator":"U01C12E4CF5","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"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":"U01C12E4CF5","last_set":1601958837},"previous_names":[],"num_members":3}],"response_metadata":{"next_cursor":""}}' + recorded_at: Thu, 08 Oct 2020 18:01:53 GMT +recorded_with: VCR 6.0.0 diff --git a/test/channel_test.rb b/test/channel_test.rb index 8a164e50..0607f9b8 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -12,18 +12,17 @@ end it "is set up for specific attributes and data types" do - [:details, :list_all].each do |prop| - expect(@channel).must_respond_to prop - end + expect(@channel).must_respond_to :details + expect(Channel).must_respond_to :list_all expect(@channel.slack_id).must_be_kind_of String expect(@channel.name).must_be_kind_of String expect(@channel.topic).must_be_kind_of String - expect(@channel.status).must_be_kind_of Integer + expect(@channel.member_count).must_be_kind_of Integer end end - describe "list_all method" do +describe "list_all method" do it "returns an Array of Channels" do VCR.use_cassette("list_channels") do channels_list = Channel.list_all @@ -35,15 +34,15 @@ end end - it "raises an error when token is not provided" do - VCR.use_cassette("list_channels") do - response = Channel.get(CHANNEL_BASE_URL) - - expect{ response }.must_raise SlackApiError - expect(response["ok"]).must_equal false - expect(response["error"]).must_equal "not_authed" - end - end + # it "raises an error when token is not provided" do + # VCR.use_cassette("list_channels") do + # response = Channel.get(CHANNEL_BASE_URL, { token: "" }) + # + # expect{ response }.must_raise SlackApiError + # expect(response["ok"]).must_equal false + # expect(response["error"]).must_equal "not_authed" + # end + # end end describe "details method" do @@ -59,8 +58,8 @@ expect(channel_details).must_include @channel.slack_id expect(channel_details).must_include @channel.name expect(channel_details).must_include @channel.topic - expect(channel_details).must_include @channel.member_count + expect(channel_details).must_include @channel.member_count.to_s end - end + end end diff --git a/test/workspace_test.rb b/test/workspace_test.rb index db380d88..87bf56d7 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -1,7 +1,7 @@ require_relative 'test_helper' require_relative '../lib/workspace' -describe "Workspace class" do +xdescribe "Workspace class" do describe "Workspace instantiation" do before do @workspace = Workspace.new From e38b4edd4b37aac516fc30200071e4d0dec6299d Mon Sep 17 00:00:00 2001 From: beauttie Date: Thu, 8 Oct 2020 12:09:16 -0700 Subject: [PATCH 13/25] Rescue errors, finish tests for Workspace class --- lib/slack.rb | 32 ++++--- test/cassettes/load_workspace.yml | 143 ++++++++++++++++++++++++++++++ test/workspace_test.rb | 57 ++++++++++-- 3 files changed, 214 insertions(+), 18 deletions(-) create mode 100644 test/cassettes/load_workspace.yml diff --git a/lib/slack.rb b/lib/slack.rb index efc6afa1..2ba600c9 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -12,25 +12,37 @@ def main user_input = gets.chomp.downcase - until user_input == "quit" + until user_input == "quit" || user_input == "7" case user_input - when "list users" + when "list users", "1" workspace.list_users - when "list channels" + when "list channels", "2" workspace.list_channels - when "select user" + when "select user", "3" print "Enter the user's name or Slack ID: " user_input = gets.chomp - puts workspace.select_user(user_input) - when "select channel" + begin + puts workspace.select_user(user_input) + rescue ArgumentError => exception + puts "#{exception}" + end + when "select channel", "4" print "Enter the channel's name or Slack ID: " user_input = gets.chomp - puts workspace.select_channel(user_input) - when "details" - puts workspace.show_details - when "send message" + begin + puts workspace.select_channel(user_input) + rescue ArgumentError => exception + puts "#{exception}" + end + when "details", "5" + begin + puts workspace.show_details + rescue NoMethodError => exception + puts "#{exception}" + end + when "send message", "6" else puts "Invalid input. Try again." diff --git a/test/cassettes/load_workspace.yml b/test/cassettes/load_workspace.yml new file mode 100644 index 00000000..75a99e3d --- /dev/null +++ b/test/cassettes/load_workspace.yml @@ -0,0 +1,143 @@ +--- +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: + - Thu, 08 Oct 2020 18:23:13 GMT + Server: + - Apache + X-Slack-Req-Id: + - 8aa7f5c2ec8a1332441489ded9f00847 + X-Oauth-Scopes: + - chat:write,channels:read,users:read,groups:read,im:read,mpim: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: + - 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: + - '1246' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-9rc7,haproxy-edge-iad-jeyo + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"T01CQM3LG6L","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":"T01CQM3LG6L"},"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":"U01BU4T45M4","team_id":"T01CQM3LG6L","name":"eartholgaslackcli","deleted":false,"color":"3c989f","real_name":"Earth-Olga-SlackCLI","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Earth-Olga-SlackCLI","real_name_normalized":"Earth-Olga-SlackCLI","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gbab7602ab3d","api_app_id":"A01C72A3R60","always_active":false,"bot_id":"B01CDFD9RED","image_24":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601959642},{"id":"U01C12E4CF5","team_id":"T01CQM3LG6L","name":"olga.tka4eva","deleted":false,"color":"9f69e7","real_name":"olga.tka4eva","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"olga.tka4eva","real_name_normalized":"olga.tka4eva","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"ga2ccc03ad6a","image_24":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601958469},{"id":"U01CQMA06F2","team_id":"T01CQM3LG6L","name":"bak02013","deleted":false,"color":"4bbe2e","real_name":"Beauttie","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Beauttie","real_name_normalized":"Beauttie","display_name":"Beauttie","display_name_normalized":"Beauttie","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g51d0ec2dd94","image_24":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601958823},{"id":"U01CQMN9XR6","team_id":"T01CQM3LG6L","name":"beauttie_api_project","deleted":false,"color":"e7392d","real_name":"Earth + - Beauttie - API Project","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Earth + - Beauttie - API Project","real_name_normalized":"Earth - Beauttie - API Project","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g55b958146df","api_app_id":"A01BL47ENLX","always_active":false,"bot_id":"B01BU4SJZT8","first_name":"Earth","last_name":"- + Beauttie - API Project","image_24":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601961016}],"cache_ts":1602181394,"response_metadata":{"next_cursor":""}}' + recorded_at: Thu, 08 Oct 2020 18:23:14 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: + - Thu, 08 Oct 2020 18:23:14 GMT + Server: + - Apache + X-Slack-Req-Id: + - ddf5673a91964e9043a12f5585e12af5 + X-Oauth-Scopes: + - chat:write,channels:read,users:read,groups:read,im:read,mpim: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: + - 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: + - '638' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-1obv,haproxy-edge-iad-788y + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"C01C0RQN3H8","name":"general","is_channel":true,"is_group":false,"is_im":false,"created":1601958469,"is_archived":false,"is_general":true,"unlinked":0,"name_normalized":"general","is_shared":false,"parent_conversation":null,"creator":"U01C12E4CF5","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"pending_shared":[],"pending_connected_team_ids":[],"is_pending_ext_shared":false,"is_member":false,"is_private":false,"is_mpim":false,"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"This + is the one channel that will always include everyone. It\u2019s a great spot + for announcements and team-wide conversations.","creator":"U01C12E4CF5","last_set":1601958469},"previous_names":[],"num_members":2},{"id":"C01CQM3LQ5N","name":"random","is_channel":true,"is_group":false,"is_im":false,"created":1601958469,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"random","is_shared":false,"parent_conversation":null,"creator":"U01C12E4CF5","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"pending_shared":[],"pending_connected_team_ids":[],"is_pending_ext_shared":false,"is_member":false,"is_private":false,"is_mpim":false,"topic":{"value":"","creator":"","last_set":0},"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":"U01C12E4CF5","last_set":1601958469},"previous_names":[],"num_members":2},{"id":"C01CQMA6E56","name":"testing","is_channel":true,"is_group":false,"is_im":false,"created":1601958837,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"testing","is_shared":false,"parent_conversation":null,"creator":"U01C12E4CF5","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"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":"U01C12E4CF5","last_set":1601958837},"previous_names":[],"num_members":3}],"response_metadata":{"next_cursor":""}}' + recorded_at: Thu, 08 Oct 2020 18:23:14 GMT +recorded_with: VCR 6.0.0 diff --git a/test/workspace_test.rb b/test/workspace_test.rb index 87bf56d7..d13c3976 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -1,14 +1,17 @@ require_relative 'test_helper' require_relative '../lib/workspace' -xdescribe "Workspace class" do - describe "Workspace instantiation" do - before do +describe "Workspace class" do + + before do + VCR.use_cassette("load workspace") do @workspace = Workspace.new end + end + describe "Workspace instantiation" do it "is an instance of Workspace" do - expect(@workspace).must_be_kind_of Workspace + expect(@workspace).must_be_kind_of Workspace end it "is set up for specific attributes and data types" do @@ -19,28 +22,66 @@ expect(@workspace.users).must_be_kind_of Array expect(@workspace.users.all?(User)).must_equal true expect(@workspace.channels).must_be_kind_of Array - expect(@workspace.users.all?(Channel)).must_equal true + expect(@workspace.channels.all?(Channel)).must_equal true expect(@workspace.selected).must_be_nil end end describe "no_recipient method" do it "returns a Boolean" do - workspace = Workspace.new - - expect(workspace.no_recipient).must_be_kind_of Boolean + expect(@workspace.no_recipient).must_be_kind_of ( TrueClass || FalseClass ) end end describe "select_user method" do + it "stores an instance of User" do + @workspace.select_user("slackbot") + expect(@workspace.selected).must_be_kind_of User + end + + it "raises an error when invalid user is entered" do + expect { + @workspace.select_user("beepbop") + }.must_raise ArgumentError + end end describe "select_channel method" do + it "stores an instance of Channel" do + @workspace.select_channel("general") + expect(@workspace.selected).must_be_kind_of Channel + end + + it "raises an error when invalid channel is entered" do + expect { + @workspace.select_channel("beepbop") + }.must_raise ArgumentError + end end describe "show_details method" do + it "returns a String when user is selected" do + @workspace.select_user("olga.tka4eva") + user_details = @workspace.show_details + + expect(user_details).must_be_kind_of String + expect(user_details).must_equal "User olga.tka4eva's real name is olga.tka4eva, and their ID on Slack is U01C12E4CF5. Their current status reads: ." + end + it "returns a String when user is selected" do + @workspace.select_channel("testing") + channel_details = @workspace.show_details + + expect(channel_details).must_be_kind_of String + expect(channel_details).must_equal "Channel testing's topic is and has 3 members. Its ID on Slack is C01CQMA6E56." + end + + it "raises an error when no recipient is selected" do + expect { + @workspace.show_details + }.must_raise NoMethodError + end end end \ No newline at end of file From 9b1d7d1a894880d2e59851475653024d89683344 Mon Sep 17 00:00:00 2001 From: OlgaSe Date: Thu, 8 Oct 2020 15:12:37 -0700 Subject: [PATCH 14/25] Added send_message method and test for it --- lib/recipient.rb | 11 +++ lib/slack.rb | 8 +- lib/workspace.rb | 5 ++ test/cassettes/negative-cases.yml | 134 ++++++++++++++++++++++++++++++ test/cassettes/send_message.yml | 69 +++++++++++++++ test/workspace_test.rb | 23 ++++- 6 files changed, 248 insertions(+), 2 deletions(-) create mode 100644 test/cassettes/negative-cases.yml create mode 100644 test/cassettes/send_message.yml diff --git a/lib/recipient.rb b/lib/recipient.rb index 496f3516..8cc2fb91 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -3,6 +3,7 @@ Dotenv.load BOT_TOKEN = ENV["SLACK_BOT_TOKEN"] +BASE_URL = "https://slack.com/api/" class Recipient class SlackApiError < Exception; end @@ -15,7 +16,17 @@ def initialize(slack_id, name) end def send_message(message) + url = "#{BASE_URL}chat.postMessage" + response = HTTParty.post(url, + headers: { 'Content-Type' => 'application/x-www-form-urlencoded' }, + body: { + token: BOT_TOKEN, + channel: self.slack_id, + text: message + }) + raise SlackApiError, "API call failed with error: #{response["error"]}" if ! response["ok"] + return response.code == 200 && response.parsed_response["ok"] end def self.get(url, params) diff --git a/lib/slack.rb b/lib/slack.rb index 2ba600c9..d6ae18cb 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -43,7 +43,13 @@ def main puts "#{exception}" end when "send message", "6" - + print "Enter a message here: >>" + user_input = gets.chomp + begin + puts workspace.send_message(user_input) + rescue NoMethodError => exception + puts "#{exception}" + end else puts "Invalid input. Try again." end diff --git a/lib/workspace.rb b/lib/workspace.rb index c0128ba5..764d724e 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -43,4 +43,9 @@ def show_details return @selected.details end + def send_message(message) + raise NoMethodError, "No recipient is currently selected." if no_recipient + @selected.send_message(message) + end + end diff --git a/test/cassettes/negative-cases.yml b/test/cassettes/negative-cases.yml new file mode 100644 index 00000000..1dfdd7de --- /dev/null +++ b/test/cassettes/negative-cases.yml @@ -0,0 +1,134 @@ +--- +http_interactions: +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=&text=weird%20message + 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: + - Thu, 08 Oct 2020 21:58:46 GMT + Server: + - Apache + X-Slack-Req-Id: + - e2b56b56623ae4ac2ca424d4e693a657 + 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: + - 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-x0c9,haproxy-edge-pdx-74gg + body: + encoding: ASCII-8BIT + string: '{"ok":false,"error":"channel_not_found"}' + recorded_at: Thu, 08 Oct 2020 21:58:46 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=U01C12E4CF5&text=weird%20message + 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: + - Thu, 08 Oct 2020 22:05:00 GMT + Server: + - Apache + X-Slack-Req-Id: + - 7d1b0db6e21812071104b10283609d61 + 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: + - 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: + - '327' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-mki5,haproxy-edge-pdx-4yzm + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channel":"D01C71YT34L","ts":"1602194700.000100","message":{"bot_id":"B01C00VN7L5","type":"message","text":"weird + message","user":"U01C12E4CF5","ts":"1602194700.000100","team":"T01CQM3LG6L","bot_profile":{"id":"B01C00VN7L5","deleted":false,"name":"Earth-Olga-SlackCLI","updated":1602017058,"app_id":"A01C72A3R60","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":"T01CQM3LG6L"}}}' + recorded_at: Thu, 08 Oct 2020 22:05:00 GMT +recorded_with: VCR 6.0.0 diff --git a/test/cassettes/send_message.yml b/test/cassettes/send_message.yml new file mode 100644 index 00000000..939a029f --- /dev/null +++ b/test/cassettes/send_message.yml @@ -0,0 +1,69 @@ +--- +http_interactions: +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=C01CQMA6E56&text=This%20is%20our%20first%20message + 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: + - Thu, 08 Oct 2020 21:54:35 GMT + Server: + - Apache + X-Slack-Req-Id: + - abffe2a63618eac66241b31492e4a839 + 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: + - 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: + - '332' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-fe3y,haproxy-edge-pdx-jpry + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channel":"C01CQMA6E56","ts":"1602194075.000200","message":{"bot_id":"B01C00VN7L5","type":"message","text":"This + is our first message","user":"U01C12E4CF5","ts":"1602194075.000200","team":"T01CQM3LG6L","bot_profile":{"id":"B01C00VN7L5","deleted":false,"name":"Earth-Olga-SlackCLI","updated":1602017058,"app_id":"A01C72A3R60","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":"T01CQM3LG6L"}}}' + recorded_at: Thu, 08 Oct 2020 21:54:35 GMT +recorded_with: VCR 6.0.0 diff --git a/test/workspace_test.rb b/test/workspace_test.rb index d13c3976..f96cbc24 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -1,5 +1,6 @@ require_relative 'test_helper' require_relative '../lib/workspace' +require_relative '../lib/recipient' describe "Workspace class" do @@ -15,7 +16,7 @@ end it "is set up for specific attributes and data types" do - [:list_users, :list_channels, :no_recipient, :select_user, :select_channel, :show_details].each do |prop| + [:list_users, :list_channels, :no_recipient, :select_user, :select_channel, :show_details, :send_message].each do |prop| expect(@workspace).must_respond_to prop end @@ -84,4 +85,24 @@ }.must_raise NoMethodError end end + + describe "send_message method" do + it "sends a message to the testing channel" do + VCR.use_cassette("send_message") do + @workspace.select_channel('testing') + response = @workspace.send_message('This is our first message') + + expect(response).must_equal true + end + end + + # it "returns false when channel doesn't exist" do + # VCR.use_cassette("negative-cases") do + # recipient = Recipient.new("", "") + # expect { + # recipient.send_message("weird message") + # }.must_raise SlackApiError + # end + # end + end end \ No newline at end of file From b3059c24c57886071f9873ddc26a315a53aaf56b Mon Sep 17 00:00:00 2001 From: beauttie Date: Thu, 8 Oct 2020 15:30:45 -0700 Subject: [PATCH 15/25] Refactor URL constant and parameters --- lib/channel.rb | 4 +- lib/recipient.rb | 7 +- lib/slack.rb | 3 +- lib/user.rb | 4 +- test/cassettes/list_all.yml | 71 --------------- test/cassettes/list_channels.yml | 71 +++++++++++++++ test/cassettes/list_users.yml | 75 ++++++++++++++++ test/cassettes/load_workspace.yml | 143 ++++++++++++++++++++++++++++++ test/cassettes/send_message.yml | 67 ++++++++++++++ test/channel_test.rb | 2 +- test/test_helper.rb | 4 +- test/user_test.rb | 4 +- test/workspace_test.rb | 4 +- 13 files changed, 370 insertions(+), 89 deletions(-) delete mode 100644 test/cassettes/list_all.yml create mode 100644 test/cassettes/list_users.yml diff --git a/lib/channel.rb b/lib/channel.rb index 98ea9c21..e34d0819 100644 --- a/lib/channel.rb +++ b/lib/channel.rb @@ -1,7 +1,5 @@ require_relative 'recipient' -CHANNEL_BASE_URL = "https://slack.com/api/conversations.list" - class Channel < Recipient attr_reader :topic, :member_count @@ -16,7 +14,7 @@ def details end def self.list_all - response = self.get(CHANNEL_BASE_URL, { token: BOT_TOKEN }) + response = self.get("#{BASE_URL}conversations.list", { token: SLACK_TOKEN }) channels_list = response["channels"].map do |channels_hash| self.new(channels_hash["id"], diff --git a/lib/recipient.rb b/lib/recipient.rb index 8cc2fb91..88493194 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -2,7 +2,7 @@ require 'dotenv' Dotenv.load -BOT_TOKEN = ENV["SLACK_BOT_TOKEN"] +SLACK_TOKEN = ENV["SLACK_TOKEN"] BASE_URL = "https://slack.com/api/" class Recipient @@ -16,11 +16,10 @@ def initialize(slack_id, name) end def send_message(message) - url = "#{BASE_URL}chat.postMessage" - response = HTTParty.post(url, + response = HTTParty.post("#{BASE_URL}chat.postMessage", headers: { 'Content-Type' => 'application/x-www-form-urlencoded' }, body: { - token: BOT_TOKEN, + token: SLACK_TOKEN, channel: self.slack_id, text: message }) diff --git a/lib/slack.rb b/lib/slack.rb index d6ae18cb..78a8b39e 100755 --- a/lib/slack.rb +++ b/lib/slack.rb @@ -43,8 +43,9 @@ def main puts "#{exception}" end when "send message", "6" - print "Enter a message here: >>" + print "Type out a message: " user_input = gets.chomp + begin puts workspace.send_message(user_input) rescue NoMethodError => exception diff --git a/lib/user.rb b/lib/user.rb index f808c44c..2544ec80 100644 --- a/lib/user.rb +++ b/lib/user.rb @@ -1,7 +1,5 @@ require_relative 'recipient' -USER_BASE_URL = "https://slack.com/api/users.list" - class User < Recipient attr_reader :real_name, :status_text, :status_emoji @@ -17,7 +15,7 @@ def details end def self.list_all - response = self.get(USER_BASE_URL, { token: BOT_TOKEN }) + response = self.get("#{BASE_URL}users.list", { token: SLACK_TOKEN }) users_list = response["members"].map do |members_hash| self.new(members_hash["id"], diff --git a/test/cassettes/list_all.yml b/test/cassettes/list_all.yml deleted file mode 100644 index 4898c870..00000000 --- a/test/cassettes/list_all.yml +++ /dev/null @@ -1,71 +0,0 @@ ---- -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: - - Thu, 08 Oct 2020 06:30:23 GMT - Server: - - Apache - X-Slack-Req-Id: - - 26ffb3d3c78112f3ce4a9bde6697344e - X-Oauth-Scopes: - - chat:write,channels:read,users: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: - - 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: - - '1245' - Content-Type: - - application/json; charset=utf-8 - X-Via: - - haproxy-www-jtpc,haproxy-edge-pdx-uehx - body: - encoding: ASCII-8BIT - string: '{"ok":true,"members":[{"id":"U01CQMA06F2","team_id":"T01CQM3LG6L","name":"bak02013","deleted":false,"color":"4bbe2e","real_name":"Beauttie","tz":"America\/Los_Angeles","tz_label":"Pacific - Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Beauttie","real_name_normalized":"Beauttie","display_name":"Beauttie","display_name_normalized":"Beauttie","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g51d0ec2dd94","image_24":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601958823},{"id":"U01CQMN9XR6","team_id":"T01CQM3LG6L","name":"beauttie_api_project","deleted":false,"color":"e7392d","real_name":"Earth - - Beauttie - API Project","tz":"America\/Los_Angeles","tz_label":"Pacific - Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Earth - - Beauttie - API Project","real_name_normalized":"Earth - Beauttie - API Project","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g55b958146df","api_app_id":"A01BL47ENLX","always_active":false,"bot_id":"B01BU4SJZT8","first_name":"Earth","last_name":"- - Beauttie - API Project","image_24":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601961016}],"cache_ts":1602138624,"response_metadata":{"next_cursor":""}}' - recorded_at: Thu, 08 Oct 2020 06:30:24 GMT -recorded_with: VCR 6.0.0 diff --git a/test/cassettes/list_channels.yml b/test/cassettes/list_channels.yml index 712eded5..6a0a4e46 100644 --- a/test/cassettes/list_channels.yml +++ b/test/cassettes/list_channels.yml @@ -69,4 +69,75 @@ http_interactions: *channel* is for working on a project. Hold meetings, share docs, and make decisions together with your team.","creator":"U01C12E4CF5","last_set":1601958837},"previous_names":[],"num_members":3}],"response_metadata":{"next_cursor":""}}' recorded_at: Thu, 08 Oct 2020 18:01:53 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: + - Thu, 08 Oct 2020 22:26:38 GMT + Server: + - Apache + X-Slack-Req-Id: + - be65460fbdaeb077228d10bee193ab34 + X-Oauth-Scopes: + - identify,channels:read,groups:read,im:read,mpim: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: + - '718' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-ttqe,haproxy-edge-iad-cnm4 + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"C01BTQN36CF","name":"sos","is_channel":true,"is_group":false,"is_im":false,"created":1602182145,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"sos","is_shared":false,"parent_conversation":null,"creator":"U01CQMA06F2","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"pending_shared":[],"pending_connected_team_ids":[],"is_pending_ext_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"topic":{"value":"help + me","creator":"U01CQMA06F2","last_set":1602182189},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2},{"id":"C01C0RQN3H8","name":"general","is_channel":true,"is_group":false,"is_im":false,"created":1601958469,"is_archived":false,"is_general":true,"unlinked":0,"name_normalized":"general","is_shared":false,"parent_conversation":null,"creator":"U01C12E4CF5","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"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 + is the one channel that will always include everyone. It\u2019s a great spot + for announcements and team-wide conversations.","creator":"U01C12E4CF5","last_set":1601958469},"previous_names":[],"num_members":2},{"id":"C01CQM3LQ5N","name":"random","is_channel":true,"is_group":false,"is_im":false,"created":1601958469,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"random","is_shared":false,"parent_conversation":null,"creator":"U01C12E4CF5","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"pending_shared":[],"pending_connected_team_ids":[],"is_pending_ext_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"topic":{"value":"anything + and everything","creator":"U01CQMA06F2","last_set":1602181915},"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":"U01C12E4CF5","last_set":1601958469},"previous_names":[],"num_members":2},{"id":"C01CQMA6E56","name":"testing","is_channel":true,"is_group":false,"is_im":false,"created":1601958837,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"testing","is_shared":false,"parent_conversation":null,"creator":"U01C12E4CF5","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"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":"U01C12E4CF5","last_set":1601958837},"previous_names":[],"num_members":3}],"response_metadata":{"next_cursor":""}}' + recorded_at: Thu, 08 Oct 2020 22:26:38 GMT recorded_with: VCR 6.0.0 diff --git a/test/cassettes/list_users.yml b/test/cassettes/list_users.yml new file mode 100644 index 00000000..df1eb585 --- /dev/null +++ b/test/cassettes/list_users.yml @@ -0,0 +1,75 @@ +--- +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: + - Thu, 08 Oct 2020 22:30:00 GMT + Server: + - Apache + X-Slack-Req-Id: + - a9dcae1673c6cf45daaff70170cab8ec + X-Oauth-Scopes: + - identify,channels:read,groups:read,im:read,mpim: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: + - '1314' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-49bf,haproxy-edge-iad-g0w5 + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"T01CQM3LG6L","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":"T01CQM3LG6L"},"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":"U01BU4T45M4","team_id":"T01CQM3LG6L","name":"eartholgaslackcli","deleted":false,"color":"3c989f","real_name":"Earth-Olga-SlackCLI","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Earth-Olga-SlackCLI","real_name_normalized":"Earth-Olga-SlackCLI","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gbab7602ab3d","api_app_id":"A01C72A3R60","always_active":false,"bot_id":"B01CDFD9RED","image_24":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601959642},{"id":"U01C12E4CF5","team_id":"T01CQM3LG6L","name":"olga.tka4eva","deleted":false,"color":"9f69e7","real_name":"olga.tka4eva","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"olga.tka4eva","real_name_normalized":"olga.tka4eva","display_name":"","display_name_normalized":"","fields":null,"status_text":"YAy!","status_emoji":":+1:","status_expiration":1602226799,"avatar_hash":"ga2ccc03ad6a","image_24":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1602181955},{"id":"U01CQMA06F2","team_id":"T01CQM3LG6L","name":"bak02013","deleted":false,"color":"4bbe2e","real_name":"Beauttie","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Beauttie","real_name_normalized":"Beauttie","display_name":"Beauttie","display_name_normalized":"Beauttie","fields":null,"status_text":"trying + to make my code work","status_emoji":":female-technologist:","status_expiration":1602226799,"avatar_hash":"g51d0ec2dd94","image_24":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1602181796,"has_2fa":false},{"id":"U01CQMN9XR6","team_id":"T01CQM3LG6L","name":"beauttie_api_project","deleted":false,"color":"e7392d","real_name":"Earth + - Beauttie - API Project","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Earth + - Beauttie - API Project","real_name_normalized":"Earth - Beauttie - API Project","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g55b958146df","api_app_id":"A01BL47ENLX","always_active":false,"bot_id":"B01BU4SJZT8","first_name":"Earth","last_name":"- + Beauttie - API Project","image_24":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601961016}],"cache_ts":1602196200,"response_metadata":{"next_cursor":""}}' + recorded_at: Thu, 08 Oct 2020 22:30:00 GMT +recorded_with: VCR 6.0.0 diff --git a/test/cassettes/load_workspace.yml b/test/cassettes/load_workspace.yml index 75a99e3d..4bdda761 100644 --- a/test/cassettes/load_workspace.yml +++ b/test/cassettes/load_workspace.yml @@ -140,4 +140,147 @@ http_interactions: *channel* is for working on a project. Hold meetings, share docs, and make decisions together with your team.","creator":"U01C12E4CF5","last_set":1601958837},"previous_names":[],"num_members":3}],"response_metadata":{"next_cursor":""}}' recorded_at: Thu, 08 Oct 2020 18:23:14 GMT +- 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: + - Thu, 08 Oct 2020 22:26:37 GMT + Server: + - Apache + X-Slack-Req-Id: + - 96df28e6db0f8c6d36534794e242ac18 + X-Oauth-Scopes: + - identify,channels:read,groups:read,im:read,mpim: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: + - '1316' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-jtpc,haproxy-edge-iad-ev82 + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"T01CQM3LG6L","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":"T01CQM3LG6L"},"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":"U01BU4T45M4","team_id":"T01CQM3LG6L","name":"eartholgaslackcli","deleted":false,"color":"3c989f","real_name":"Earth-Olga-SlackCLI","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Earth-Olga-SlackCLI","real_name_normalized":"Earth-Olga-SlackCLI","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gbab7602ab3d","api_app_id":"A01C72A3R60","always_active":false,"bot_id":"B01CDFD9RED","image_24":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601959642},{"id":"U01C12E4CF5","team_id":"T01CQM3LG6L","name":"olga.tka4eva","deleted":false,"color":"9f69e7","real_name":"olga.tka4eva","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"olga.tka4eva","real_name_normalized":"olga.tka4eva","display_name":"","display_name_normalized":"","fields":null,"status_text":"YAy!","status_emoji":":+1:","status_expiration":1602226799,"avatar_hash":"ga2ccc03ad6a","image_24":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1602181955},{"id":"U01CQMA06F2","team_id":"T01CQM3LG6L","name":"bak02013","deleted":false,"color":"4bbe2e","real_name":"Beauttie","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Beauttie","real_name_normalized":"Beauttie","display_name":"Beauttie","display_name_normalized":"Beauttie","fields":null,"status_text":"trying + to make my code work","status_emoji":":female-technologist:","status_expiration":1602226799,"avatar_hash":"g51d0ec2dd94","image_24":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1602181796,"has_2fa":false},{"id":"U01CQMN9XR6","team_id":"T01CQM3LG6L","name":"beauttie_api_project","deleted":false,"color":"e7392d","real_name":"Earth + - Beauttie - API Project","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Earth + - Beauttie - API Project","real_name_normalized":"Earth - Beauttie - API Project","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g55b958146df","api_app_id":"A01BL47ENLX","always_active":false,"bot_id":"B01BU4SJZT8","first_name":"Earth","last_name":"- + Beauttie - API Project","image_24":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601961016}],"cache_ts":1602195997,"response_metadata":{"next_cursor":""}}' + recorded_at: Thu, 08 Oct 2020 22:26:37 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: + - Thu, 08 Oct 2020 22:26:37 GMT + Server: + - Apache + X-Slack-Req-Id: + - 9874cd9fbab071835f279b5fed3b88ff + X-Oauth-Scopes: + - identify,channels:read,groups:read,im:read,mpim: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: + - '718' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-7pax,haproxy-edge-iad-8zmh + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channels":[{"id":"C01BTQN36CF","name":"sos","is_channel":true,"is_group":false,"is_im":false,"created":1602182145,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"sos","is_shared":false,"parent_conversation":null,"creator":"U01CQMA06F2","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"pending_shared":[],"pending_connected_team_ids":[],"is_pending_ext_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"topic":{"value":"help + me","creator":"U01CQMA06F2","last_set":1602182189},"purpose":{"value":"","creator":"","last_set":0},"previous_names":[],"num_members":2},{"id":"C01C0RQN3H8","name":"general","is_channel":true,"is_group":false,"is_im":false,"created":1601958469,"is_archived":false,"is_general":true,"unlinked":0,"name_normalized":"general","is_shared":false,"parent_conversation":null,"creator":"U01C12E4CF5","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"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 + is the one channel that will always include everyone. It\u2019s a great spot + for announcements and team-wide conversations.","creator":"U01C12E4CF5","last_set":1601958469},"previous_names":[],"num_members":2},{"id":"C01CQM3LQ5N","name":"random","is_channel":true,"is_group":false,"is_im":false,"created":1601958469,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"random","is_shared":false,"parent_conversation":null,"creator":"U01C12E4CF5","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"pending_shared":[],"pending_connected_team_ids":[],"is_pending_ext_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"topic":{"value":"anything + and everything","creator":"U01CQMA06F2","last_set":1602181915},"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":"U01C12E4CF5","last_set":1601958469},"previous_names":[],"num_members":2},{"id":"C01CQMA6E56","name":"testing","is_channel":true,"is_group":false,"is_im":false,"created":1601958837,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"testing","is_shared":false,"parent_conversation":null,"creator":"U01C12E4CF5","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"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":"U01C12E4CF5","last_set":1601958837},"previous_names":[],"num_members":3}],"response_metadata":{"next_cursor":""}}' + recorded_at: Thu, 08 Oct 2020 22:26:37 GMT recorded_with: VCR 6.0.0 diff --git a/test/cassettes/send_message.yml b/test/cassettes/send_message.yml index 939a029f..6d3216ef 100644 --- a/test/cassettes/send_message.yml +++ b/test/cassettes/send_message.yml @@ -66,4 +66,71 @@ http_interactions: string: '{"ok":true,"channel":"C01CQMA6E56","ts":"1602194075.000200","message":{"bot_id":"B01C00VN7L5","type":"message","text":"This is our first message","user":"U01C12E4CF5","ts":"1602194075.000200","team":"T01CQM3LG6L","bot_profile":{"id":"B01C00VN7L5","deleted":false,"name":"Earth-Olga-SlackCLI","updated":1602017058,"app_id":"A01C72A3R60","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":"T01CQM3LG6L"}}}' recorded_at: Thu, 08 Oct 2020 21:54:35 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=C01CQMA6E56&text=This%20is%20our%20first%20message + 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: + - Thu, 08 Oct 2020 22:26:38 GMT + Server: + - Apache + X-Slack-Req-Id: + - cf630531cc97d42e9889507832b256f0 + X-Oauth-Scopes: + - identify,channels:read,groups:read,im:read,mpim: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: + - 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: + - '345' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-edfp,haproxy-edge-iad-psc9 + body: + encoding: ASCII-8BIT + string: '{"ok":true,"channel":"C01CQMA6E56","ts":"1602195998.000400","message":{"bot_id":"B01BL5M2VT9","type":"message","text":"This + is our first message","user":"U01CQMA06F2","ts":"1602195998.000400","team":"T01CQM3LG6L","bot_profile":{"id":"B01BL5M2VT9","deleted":false,"name":"Earth + - Beauttie - API Project","updated":1601961796,"app_id":"A01BL47ENLX","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":"T01CQM3LG6L"}}}' + recorded_at: Thu, 08 Oct 2020 22:26:38 GMT recorded_with: VCR 6.0.0 diff --git a/test/channel_test.rb b/test/channel_test.rb index 0607f9b8..eff07160 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -30,7 +30,7 @@ expect(channels_list).must_be_kind_of Array expect(channels_list.all?(Channel)).must_equal true - expect(channels_list.length).must_equal 3 + expect(channels_list.length).must_equal 4 end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 7d6ed69c..ea79be3e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -22,7 +22,7 @@ } # Don't leave our token lying around in a cassette file. - config.filter_sensitive_data("") do - ENV["SLACK_BOT_TOKEN"] + config.filter_sensitive_data("") do + ENV["SLACK_TOKEN"] end end diff --git a/test/user_test.rb b/test/user_test.rb index 37ffcf12..0657a675 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -9,10 +9,10 @@ end it "return an instance array class" do - VCR.use_cassette("list all") do + VCR.use_cassette("list users") do users = User.list_all expect(users).must_be_kind_of Array - expect(users.length).must_equal 2 + expect(users.length).must_equal 5 # expect(users).must_equal [User.new("U01CQMA06F2", "bak02013", "Beauttie", '', ''), User.new("U01CQMN9XR6", "beauttie_api_project", "Earth - Beauttie - API Project", '', '' )] end end diff --git a/test/workspace_test.rb b/test/workspace_test.rb index f96cbc24..f11f83c6 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -12,7 +12,7 @@ describe "Workspace instantiation" do it "is an instance of Workspace" do - expect(@workspace).must_be_kind_of Workspace + expect(@workspace).must_be_kind_of Workspace end it "is set up for specific attributes and data types" do @@ -68,7 +68,7 @@ user_details = @workspace.show_details expect(user_details).must_be_kind_of String - expect(user_details).must_equal "User olga.tka4eva's real name is olga.tka4eva, and their ID on Slack is U01C12E4CF5. Their current status reads: ." + expect(user_details).must_equal "User olga.tka4eva's real name is olga.tka4eva, and their ID on Slack is U01C12E4CF5. Their current status reads: YAy! :+1:." end it "returns a String when user is selected" do From ef55a29f824cec21935670c08fad5aa7cb471dca Mon Sep 17 00:00:00 2001 From: beauttie Date: Thu, 8 Oct 2020 15:54:43 -0700 Subject: [PATCH 16/25] Fix test for edge case in workspace_test --- lib/recipient.rb | 3 +- lib/slack_api_error.rb | 1 + lib/workspace.rb | 2 +- test/cassettes/list_channels.yml | 55 ++++++++++++++++++++++++++ test/cassettes/negative-cases.yml | 65 +++++++++++++++++++++++++++++++ test/channel_test.rb | 2 +- test/workspace_test.rb | 16 ++++---- 7 files changed, 133 insertions(+), 11 deletions(-) create mode 100644 lib/slack_api_error.rb diff --git a/lib/recipient.rb b/lib/recipient.rb index 88493194..e3833a2c 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -1,12 +1,13 @@ require 'httparty' require 'dotenv' +require_relative 'slack_api_error' + Dotenv.load SLACK_TOKEN = ENV["SLACK_TOKEN"] BASE_URL = "https://slack.com/api/" class Recipient - class SlackApiError < Exception; end attr_reader :slack_id, :name diff --git a/lib/slack_api_error.rb b/lib/slack_api_error.rb new file mode 100644 index 00000000..5a82c3d9 --- /dev/null +++ b/lib/slack_api_error.rb @@ -0,0 +1 @@ +class SlackApiError < Exception; end diff --git a/lib/workspace.rb b/lib/workspace.rb index 764d724e..5bca27ca 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -44,7 +44,7 @@ def show_details end def send_message(message) - raise NoMethodError, "No recipient is currently selected." if no_recipient + raise NoMethodError, "No recipient is currently selected." if no_recipient @selected.send_message(message) end diff --git a/test/cassettes/list_channels.yml b/test/cassettes/list_channels.yml index 6a0a4e46..e26c1284 100644 --- a/test/cassettes/list_channels.yml +++ b/test/cassettes/list_channels.yml @@ -140,4 +140,59 @@ http_interactions: *channel* is for working on a project. Hold meetings, share docs, and make decisions together with your team.","creator":"U01C12E4CF5","last_set":1601958837},"previous_names":[],"num_members":3}],"response_metadata":{"next_cursor":""}}' recorded_at: Thu, 08 Oct 2020 22:26:38 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: + - Thu, 08 Oct 2020 22:40:58 GMT + Server: + - Apache + X-Xss-Protection: + - '0' + Referrer-Policy: + - no-referrer + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + 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 + X-Accepted-Oauth-Scopes: + - conversations:read + X-Slack-Req-Id: + - 64a81352029771245d3ce8a67cee6f25 + X-Slack-Backend: + - r + Access-Control-Allow-Origin: + - "*" + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Content-Type-Options: + - nosniff + Content-Length: + - '53' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-pqd0,haproxy-edge-iad-fenm + body: + encoding: ASCII-8BIT + string: '{"ok":false,"error":"not_authed"}' + recorded_at: Thu, 08 Oct 2020 22:40:59 GMT recorded_with: VCR 6.0.0 diff --git a/test/cassettes/negative-cases.yml b/test/cassettes/negative-cases.yml index 1dfdd7de..f16f8749 100644 --- a/test/cassettes/negative-cases.yml +++ b/test/cassettes/negative-cases.yml @@ -131,4 +131,69 @@ http_interactions: string: '{"ok":true,"channel":"D01C71YT34L","ts":"1602194700.000100","message":{"bot_id":"B01C00VN7L5","type":"message","text":"weird message","user":"U01C12E4CF5","ts":"1602194700.000100","team":"T01CQM3LG6L","bot_profile":{"id":"B01C00VN7L5","deleted":false,"name":"Earth-Olga-SlackCLI","updated":1602017058,"app_id":"A01C72A3R60","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":"T01CQM3LG6L"}}}' recorded_at: Thu, 08 Oct 2020 22:05:00 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=&text=weird%20message + 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: + - Thu, 08 Oct 2020 22:45:12 GMT + Server: + - Apache + X-Slack-Req-Id: + - 2140e1b2ce7de863240d4145ae6775fc + X-Oauth-Scopes: + - identify,channels:read,groups:read,im:read,mpim: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: + - 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-07yl,haproxy-edge-iad-9739 + body: + encoding: ASCII-8BIT + string: '{"ok":false,"error":"channel_not_found"}' + recorded_at: Thu, 08 Oct 2020 22:45:12 GMT recorded_with: VCR 6.0.0 diff --git a/test/channel_test.rb b/test/channel_test.rb index eff07160..911a9cee 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -36,7 +36,7 @@ # it "raises an error when token is not provided" do # VCR.use_cassette("list_channels") do - # response = Channel.get(CHANNEL_BASE_URL, { token: "" }) + # response = Channel.get("#{BASE_URL}conversations.list", { token: "" }) # # expect{ response }.must_raise SlackApiError # expect(response["ok"]).must_equal false diff --git a/test/workspace_test.rb b/test/workspace_test.rb index f11f83c6..f55daccb 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -96,13 +96,13 @@ end end - # it "returns false when channel doesn't exist" do - # VCR.use_cassette("negative-cases") do - # recipient = Recipient.new("", "") - # expect { - # recipient.send_message("weird message") - # }.must_raise SlackApiError - # end - # end + it "returns false when channel doesn't exist" do + VCR.use_cassette("negative-cases") do + recipient = Recipient.new("", "") + expect { + recipient.send_message("weird message") + }.must_raise SlackApiError + end + end end end \ No newline at end of file From 0eb2dcff2567925c46b4fd794a569549a03b5668 Mon Sep 17 00:00:00 2001 From: OlgaSe Date: Thu, 8 Oct 2020 18:09:31 -0700 Subject: [PATCH 17/25] Empty message case test for send_message method is fixed --- test/cassettes/negative-cases.yml | 65 +++++++++++++++++++++++++++++++ test/channel_test.rb | 14 +++---- test/workspace_test.rb | 13 ++++++- 3 files changed, 82 insertions(+), 10 deletions(-) diff --git a/test/cassettes/negative-cases.yml b/test/cassettes/negative-cases.yml index f16f8749..b6f435ee 100644 --- a/test/cassettes/negative-cases.yml +++ b/test/cassettes/negative-cases.yml @@ -196,4 +196,69 @@ http_interactions: encoding: ASCII-8BIT string: '{"ok":false,"error":"channel_not_found"}' recorded_at: Thu, 08 Oct 2020 22:45:12 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=USLACKBOT&text= + 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: + - Thu, 08 Oct 2020 23:18:29 GMT + Server: + - Apache + X-Slack-Req-Id: + - a164ce5e2a3ba9a60bc5c0294b3971bd + 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: + - 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: + - '50' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-pqib,haproxy-edge-pdx-8ea4 + body: + encoding: ASCII-8BIT + string: '{"ok":false,"error":"no_text"}' + recorded_at: Thu, 08 Oct 2020 23:18:29 GMT recorded_with: VCR 6.0.0 diff --git a/test/channel_test.rb b/test/channel_test.rb index 911a9cee..875e1731 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -34,15 +34,11 @@ end end - # it "raises an error when token is not provided" do - # VCR.use_cassette("list_channels") do - # response = Channel.get("#{BASE_URL}conversations.list", { token: "" }) - # - # expect{ response }.must_raise SlackApiError - # expect(response["ok"]).must_equal false - # expect(response["error"]).must_equal "not_authed" - # end - # end + it "raises an error when token is not provided" do + VCR.use_cassette("list_channels") do + expect{ Channel.get("#{BASE_URL}conversations.list", { token: "" }) }.must_raise SlackApiError + end + end end describe "details method" do diff --git a/test/workspace_test.rb b/test/workspace_test.rb index f55daccb..5d4f9418 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -96,7 +96,7 @@ end end - it "returns false when channel doesn't exist" do + it "raises an error when recipient doesn't exist" do VCR.use_cassette("negative-cases") do recipient = Recipient.new("", "") expect { @@ -104,5 +104,16 @@ }.must_raise SlackApiError end end + + it "raises an error when the message is empty" do + VCR.use_cassette("negative-cases") do + @workspace.select_user("slackbot") + recipient = @workspace.selected + expect { + recipient.send_message("") + }.must_raise SlackApiError + + end + end end end \ No newline at end of file From 3a6fced5b97b2f12218e2f8a58f521357004d4ea Mon Sep 17 00:00:00 2001 From: OlgaSe Date: Thu, 8 Oct 2020 19:04:31 -0700 Subject: [PATCH 18/25] Added all testes for the user class --- test/user_test.rb | 64 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/test/user_test.rb b/test/user_test.rb index 0657a675..9fbd3b4c 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -1,19 +1,73 @@ require_relative 'test_helper' require_relative '../lib/user' -describe User do +describe "User class" do + before do + @user = User.new("USLACKBOT", "slackbot", "Slackbot", "away", "happy") + end + + it "is an instance of User" do + expect(@user).must_be_kind_of User + end + + it "is set up for specific attributes and data types" do + expect(@user).must_respond_to :details + expect(User).must_respond_to :list_all + + expect(@user.slack_id).must_be_kind_of String + expect(@user.name).must_be_kind_of String + expect(@user.real_name).must_be_kind_of String + expect(@user.status_text).must_be_kind_of String + expect(@user.status_emoji).must_be_kind_of String + end it "return a specific values for user's attributes" do - user = User.new("USLACKBOT", "slackbot", "Slackbot", "","") - expect(user.details).must_equal "User slackbot's real name is Slackbot, and their ID on Slack is USLACKBOT. Their current status reads: ." + expect(@user.details).must_equal "User slackbot's real name is Slackbot, and their ID on Slack is USLACKBOT. Their current status reads: away happy." end - it "return an instance array class" do + it "initialized properly sets all properties" do + expect(@user.slack_id).must_equal "USLACKBOT" + expect(@user.name).must_equal "slackbot" + expect(@user.status_text).must_equal "away" + expect(@user.status_emoji).must_equal "happy" + end +end + +describe "list_all method" do + it "returns an Array of users" do VCR.use_cassette("list users") do users = User.list_all + expect(users).must_be_kind_of Array + expect(users.all?(User)).must_equal true + expect(users.length).must_equal 5 - # expect(users).must_equal [User.new("U01CQMA06F2", "bak02013", "Beauttie", '', ''), User.new("U01CQMN9XR6", "beauttie_api_project", "Earth - Beauttie - API Project", '', '' )] + users_details = users.map { |user| user.details } + expected_details = ["User slackbot's real name is Slackbot, and their ID on Slack is USLACKBOT. Their current status reads: .", + "User eartholgaslackcli's real name is Earth-Olga-SlackCLI, and their ID on Slack is U01BU4T45M4. Their current status reads: .", + "User olga.tka4eva's real name is olga.tka4eva, and their ID on Slack is U01C12E4CF5. Their current status reads: YAy! :+1:.", + "User bak02013's real name is Beauttie, and their ID on Slack is U01CQMA06F2. Their current status reads: trying to make my code work :female-technologist:.", + "User beauttie_api_project's real name is Earth - Beauttie - API Project, and their ID on Slack is U01CQMN9XR6. Their current status reads: ."] + expect(users_details).must_equal expected_details + end + end + + + describe "details method" do + before do + @user = User.new("USLACKBOT", "slackbot", "Slackbot", "away", "happy") + end + + it "returns a String including specific attributes" do + user_details = @user.details + + expect(user_details).must_be_kind_of String + + expect(user_details).must_include @user.slack_id + expect(user_details).must_include @user.name + expect(user_details).must_include @user.real_name + expect(user_details).must_include @user.status_text + expect(user_details).must_include @user.status_emoji end end end From 2df5a045710d4d60b125c7a1e9bd6ef1c3866bdb Mon Sep 17 00:00:00 2001 From: beauttie Date: Thu, 8 Oct 2020 21:04:32 -0700 Subject: [PATCH 19/25] Handle errors with unless clause in Recipient class --- lib/recipient.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/recipient.rb b/lib/recipient.rb index e3833a2c..b42787ee 100644 --- a/lib/recipient.rb +++ b/lib/recipient.rb @@ -5,10 +5,10 @@ Dotenv.load SLACK_TOKEN = ENV["SLACK_TOKEN"] + BASE_URL = "https://slack.com/api/" class Recipient - attr_reader :slack_id, :name def initialize(slack_id, name) @@ -24,15 +24,21 @@ def send_message(message) channel: self.slack_id, text: message }) - raise SlackApiError, "API call failed with error: #{response["error"]}" if ! response["ok"] - return response.code == 200 && response.parsed_response["ok"] + unless response.code == 200 && response["ok"] + raise SlackApiError, "API call failed with error: #{response["error"]}" + end + + return true end def self.get(url, params) response = HTTParty.get(url, query: params) - raise SlackApiError, "API call failed with error: #{response["error"]}" if ! response["ok"] + unless response.code == 200 && response["ok"] + raise SlackApiError, "API call failed with error: #{response["error"]}" + end + return response end From 099fd466faed2447f7389c59bd55f55945f31c4b Mon Sep 17 00:00:00 2001 From: beauttie Date: Thu, 8 Oct 2020 21:08:40 -0700 Subject: [PATCH 20/25] Modify output of select methods to include Slack ID or name --- lib/workspace.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index 5bca27ca..b63394f7 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -28,14 +28,14 @@ def select_user(id_or_name) @selected = @users.find { |user| user.slack_id == id_or_name || user.name == id_or_name } raise ArgumentError, "User with that name or Slack ID not found." if no_recipient - return "User selected." + return "User #{id_or_name} selected." end def select_channel(id_or_name) @selected = @channels.find { |channel| channel.slack_id == id_or_name || channel.name == id_or_name } raise ArgumentError, "Channel with that name or Slack ID not found." if no_recipient - return "Channel selected." + return "Channel #{id_or_name} selected." end def show_details From 707ca767b42fcb3b00c03cbb25e1ef4f41c6061a Mon Sep 17 00:00:00 2001 From: beauttie Date: Thu, 8 Oct 2020 21:46:32 -0700 Subject: [PATCH 21/25] Reorganize tests for User class --- test/cassettes/list_users.yml | 67 +++++++++++++++-- test/cassettes/users_details.yml | 75 +++++++++++++++++++ test/channel_test.rb | 8 +- test/user_test.rb | 123 ++++++++++++++++++------------- 4 files changed, 213 insertions(+), 60 deletions(-) create mode 100644 test/cassettes/users_details.yml diff --git a/test/cassettes/list_users.yml b/test/cassettes/list_users.yml index df1eb585..9517683f 100644 --- a/test/cassettes/list_users.yml +++ b/test/cassettes/list_users.yml @@ -19,11 +19,11 @@ http_interactions: message: OK headers: Date: - - Thu, 08 Oct 2020 22:30:00 GMT + - Fri, 09 Oct 2020 04:39:45 GMT Server: - Apache X-Slack-Req-Id: - - a9dcae1673c6cf45daaff70170cab8ec + - 1e7ed38b160b0fa8573c046abfa79387 X-Oauth-Scopes: - identify,channels:read,groups:read,im:read,mpim:read,users:read,chat:write Access-Control-Expose-Headers: @@ -54,11 +54,11 @@ http_interactions: Referrer-Policy: - no-referrer Content-Length: - - '1314' + - '1316' Content-Type: - application/json; charset=utf-8 X-Via: - - haproxy-www-49bf,haproxy-edge-iad-g0w5 + - haproxy-www-7tp5,haproxy-edge-iad-w3jt body: encoding: ASCII-8BIT string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"T01CQM3LG6L","name":"slackbot","deleted":false,"color":"757575","real_name":"Slackbot","tz":"America\/Los_Angeles","tz_label":"Pacific @@ -70,6 +70,61 @@ http_interactions: - Beauttie - API Project","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Earth - Beauttie - API Project","real_name_normalized":"Earth - Beauttie - API Project","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g55b958146df","api_app_id":"A01BL47ENLX","always_active":false,"bot_id":"B01BU4SJZT8","first_name":"Earth","last_name":"- - Beauttie - API Project","image_24":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601961016}],"cache_ts":1602196200,"response_metadata":{"next_cursor":""}}' - recorded_at: Thu, 08 Oct 2020 22:30:00 GMT + Beauttie - API Project","image_24":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601961016}],"cache_ts":1602218385,"response_metadata":{"next_cursor":""}}' + recorded_at: Fri, 09 Oct 2020 04:39:45 GMT +- 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 04:39:45 GMT + Server: + - Apache + X-Xss-Protection: + - '0' + Referrer-Policy: + - no-referrer + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + 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 + X-Accepted-Oauth-Scopes: + - users:read + X-Slack-Req-Id: + - 66cc01cd54470bce1da3bfb45b4cec7e + X-Slack-Backend: + - r + Access-Control-Allow-Origin: + - "*" + Access-Control-Expose-Headers: + - x-slack-req-id, retry-after + X-Content-Type-Options: + - nosniff + Content-Length: + - '53' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-wsih,haproxy-edge-iad-r943 + body: + encoding: ASCII-8BIT + string: '{"ok":false,"error":"not_authed"}' + recorded_at: Fri, 09 Oct 2020 04:39:45 GMT recorded_with: VCR 6.0.0 diff --git a/test/cassettes/users_details.yml b/test/cassettes/users_details.yml new file mode 100644 index 00000000..4406478e --- /dev/null +++ b/test/cassettes/users_details.yml @@ -0,0 +1,75 @@ +--- +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 04:39:45 GMT + Server: + - Apache + X-Slack-Req-Id: + - b66e8cf6da56461a8a8803179155cba9 + X-Oauth-Scopes: + - identify,channels:read,groups:read,im:read,mpim: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: + - '1316' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-xfba,haproxy-edge-iad-rxcd + body: + encoding: ASCII-8BIT + string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"T01CQM3LG6L","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":"T01CQM3LG6L"},"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":"U01BU4T45M4","team_id":"T01CQM3LG6L","name":"eartholgaslackcli","deleted":false,"color":"3c989f","real_name":"Earth-Olga-SlackCLI","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Earth-Olga-SlackCLI","real_name_normalized":"Earth-Olga-SlackCLI","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gbab7602ab3d","api_app_id":"A01C72A3R60","always_active":false,"bot_id":"B01CDFD9RED","image_24":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601959642},{"id":"U01C12E4CF5","team_id":"T01CQM3LG6L","name":"olga.tka4eva","deleted":false,"color":"9f69e7","real_name":"olga.tka4eva","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"olga.tka4eva","real_name_normalized":"olga.tka4eva","display_name":"","display_name_normalized":"","fields":null,"status_text":"YAy!","status_emoji":":+1:","status_expiration":1602226799,"avatar_hash":"ga2ccc03ad6a","image_24":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1602181955},{"id":"U01CQMA06F2","team_id":"T01CQM3LG6L","name":"bak02013","deleted":false,"color":"4bbe2e","real_name":"Beauttie","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Beauttie","real_name_normalized":"Beauttie","display_name":"Beauttie","display_name_normalized":"Beauttie","fields":null,"status_text":"trying + to make my code work","status_emoji":":female-technologist:","status_expiration":1602226799,"avatar_hash":"g51d0ec2dd94","image_24":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1602181796,"has_2fa":false},{"id":"U01CQMN9XR6","team_id":"T01CQM3LG6L","name":"beauttie_api_project","deleted":false,"color":"e7392d","real_name":"Earth + - Beauttie - API Project","tz":"America\/Los_Angeles","tz_label":"Pacific + Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Earth + - Beauttie - API Project","real_name_normalized":"Earth - Beauttie - API Project","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g55b958146df","api_app_id":"A01BL47ENLX","always_active":false,"bot_id":"B01BU4SJZT8","first_name":"Earth","last_name":"- + Beauttie - API Project","image_24":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601961016}],"cache_ts":1602218385,"response_metadata":{"next_cursor":""}}' + recorded_at: Fri, 09 Oct 2020 04:39:45 GMT +recorded_with: VCR 6.0.0 diff --git a/test/channel_test.rb b/test/channel_test.rb index 875e1731..5f65ced1 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -4,7 +4,7 @@ describe "Channel class" do describe "Channel instantiation" do before do - @channel = Channel.new("420", "weed", "the good kind of weed", 1) + @channel = Channel.new("C14", "earth-adies", "collaborative space for the Earth classroom", 2) end it "is an instance of Channel" do @@ -12,8 +12,8 @@ end it "is set up for specific attributes and data types" do - expect(@channel).must_respond_to :details - expect(Channel).must_respond_to :list_all + expect(@channel).must_respond_to :details + expect(Channel).must_respond_to :list_all expect(@channel.slack_id).must_be_kind_of String expect(@channel.name).must_be_kind_of String @@ -43,7 +43,7 @@ describe "details method" do before do - @channel = Channel.new("420", "weed", "the good kind of weed", 1) + @channel = Channel.new("C14", "earth-adies", "collaborative space for the Earth classroom", 2) end it "returns a String including specific attributes" do diff --git a/test/user_test.rb b/test/user_test.rb index 9fbd3b4c..81831619 100644 --- a/test/user_test.rb +++ b/test/user_test.rb @@ -2,73 +2,96 @@ require_relative '../lib/user' describe "User class" do - before do - @user = User.new("USLACKBOT", "slackbot", "Slackbot", "away", "happy") - end + describe "User instantiation" do + before do + @user = User.new("USLACKBOT", "slackbot", "Slackbot", "away", ":robot_face:") + end - it "is an instance of User" do - expect(@user).must_be_kind_of User - end + it "is an instance of User" do + expect(@user).must_be_kind_of User + end - it "is set up for specific attributes and data types" do - expect(@user).must_respond_to :details - expect(User).must_respond_to :list_all + it "is set up for specific attributes and data types" do + expect(@user).must_respond_to :details + expect(User).must_respond_to :list_all - expect(@user.slack_id).must_be_kind_of String - expect(@user.name).must_be_kind_of String - expect(@user.real_name).must_be_kind_of String - expect(@user.status_text).must_be_kind_of String - expect(@user.status_emoji).must_be_kind_of String - end + expect(@user.slack_id).must_be_kind_of String + expect(@user.name).must_be_kind_of String + expect(@user.real_name).must_be_kind_of String + expect(@user.status_text).must_be_kind_of String + expect(@user.status_emoji).must_be_kind_of String + end - it "return a specific values for user's attributes" do - expect(@user.details).must_equal "User slackbot's real name is Slackbot, and their ID on Slack is USLACKBOT. Their current status reads: away happy." + it "initialized properly sets all properties" do + expect(@user.slack_id).must_equal "USLACKBOT" + expect(@user.name).must_equal "slackbot" + expect(@user.status_text).must_equal "away" + expect(@user.status_emoji).must_equal ":robot_face:" + end end - it "initialized properly sets all properties" do - expect(@user.slack_id).must_equal "USLACKBOT" - expect(@user.name).must_equal "slackbot" - expect(@user.status_text).must_equal "away" - expect(@user.status_emoji).must_equal "happy" - end -end + describe "list_all method" do + it "returns an Array of Users" do + VCR.use_cassette("list_users") do + users_list = User.list_all + + expect(users_list).must_be_kind_of Array + expect(users_list.all?(User)).must_equal true -describe "list_all method" do - it "returns an Array of users" do - VCR.use_cassette("list users") do - users = User.list_all - - expect(users).must_be_kind_of Array - expect(users.all?(User)).must_equal true - - expect(users.length).must_equal 5 - users_details = users.map { |user| user.details } - expected_details = ["User slackbot's real name is Slackbot, and their ID on Slack is USLACKBOT. Their current status reads: .", - "User eartholgaslackcli's real name is Earth-Olga-SlackCLI, and their ID on Slack is U01BU4T45M4. Their current status reads: .", - "User olga.tka4eva's real name is olga.tka4eva, and their ID on Slack is U01C12E4CF5. Their current status reads: YAy! :+1:.", - "User bak02013's real name is Beauttie, and their ID on Slack is U01CQMA06F2. Their current status reads: trying to make my code work :female-technologist:.", - "User beauttie_api_project's real name is Earth - Beauttie - API Project, and their ID on Slack is U01CQMN9XR6. Their current status reads: ."] - expect(users_details).must_equal expected_details + expect(users_list.length).must_equal 5 + end end - end + it "raises an error when token is not provided" do + VCR.use_cassette("list_users") do + expect{ + User.get("#{BASE_URL}users.list", { token: "" }) + }.must_raise SlackApiError + end + end + end describe "details method" do - before do - @user = User.new("USLACKBOT", "slackbot", "Slackbot", "away", "happy") - end + let (:user) { + User.new( + "USLACKBOT", + "slackbot", + "Slackbot", + "away", + ":robot_face:" + ) + } it "returns a String including specific attributes" do - user_details = @user.details + user_details = user.details expect(user_details).must_be_kind_of String - expect(user_details).must_include @user.slack_id - expect(user_details).must_include @user.name - expect(user_details).must_include @user.real_name - expect(user_details).must_include @user.status_text - expect(user_details).must_include @user.status_emoji + expect(user_details).must_include user.slack_id + expect(user_details).must_include user.name + expect(user_details).must_include user.real_name + expect(user_details).must_include user.status_text + expect(user_details).must_include user.status_emoji + end + + it "returns correct details based on user's attributes" do + expect(user.details).must_equal "User slackbot's real name is Slackbot, and their ID on Slack is USLACKBOT. Their current status reads: away :robot_face:." + end + + it "returns correct details for current list of users" do + VCR.use_cassette("users_details") do + users_list = User.list_all + users_details = users_list.map { |user| user.details } + expected_details = ["User slackbot's real name is Slackbot, and their ID on Slack is USLACKBOT. Their current status reads: .", + "User eartholgaslackcli's real name is Earth-Olga-SlackCLI, and their ID on Slack is U01BU4T45M4. Their current status reads: .", + "User olga.tka4eva's real name is olga.tka4eva, and their ID on Slack is U01C12E4CF5. Their current status reads: YAy! :+1:.", + "User bak02013's real name is Beauttie, and their ID on Slack is U01CQMA06F2. Their current status reads: trying to make my code work :female-technologist:.", + "User beauttie_api_project's real name is Earth - Beauttie - API Project, and their ID on Slack is U01CQMN9XR6. Their current status reads: ."] + + expect(users_details).must_equal expected_details + end end end + end From 9c1fb945cebdfa8f60d893f22b7726ab417c470a Mon Sep 17 00:00:00 2001 From: beauttie Date: Thu, 8 Oct 2020 21:57:03 -0700 Subject: [PATCH 22/25] Clean up format of Channel tests --- test/cassettes/list_channels.yml | 85 +++----------------------------- test/channel_test.rb | 6 ++- 2 files changed, 12 insertions(+), 79 deletions(-) diff --git a/test/cassettes/list_channels.yml b/test/cassettes/list_channels.yml index e26c1284..0736b784 100644 --- a/test/cassettes/list_channels.yml +++ b/test/cassettes/list_channels.yml @@ -1,74 +1,5 @@ --- http_interactions: -- 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: - - Thu, 08 Oct 2020 18:01:53 GMT - Server: - - Apache - X-Slack-Req-Id: - - 9cf94a4b2747d11335e2b08365753855 - X-Oauth-Scopes: - - chat:write,channels:read,users:read,groups:read,im:read,mpim: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: - - 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: - - '638' - Content-Type: - - application/json; charset=utf-8 - X-Via: - - haproxy-www-xozz,haproxy-edge-iad-rwys - body: - encoding: ASCII-8BIT - string: '{"ok":true,"channels":[{"id":"C01C0RQN3H8","name":"general","is_channel":true,"is_group":false,"is_im":false,"created":1601958469,"is_archived":false,"is_general":true,"unlinked":0,"name_normalized":"general","is_shared":false,"parent_conversation":null,"creator":"U01C12E4CF5","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"pending_shared":[],"pending_connected_team_ids":[],"is_pending_ext_shared":false,"is_member":false,"is_private":false,"is_mpim":false,"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"This - is the one channel that will always include everyone. It\u2019s a great spot - for announcements and team-wide conversations.","creator":"U01C12E4CF5","last_set":1601958469},"previous_names":[],"num_members":2},{"id":"C01CQM3LQ5N","name":"random","is_channel":true,"is_group":false,"is_im":false,"created":1601958469,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"random","is_shared":false,"parent_conversation":null,"creator":"U01C12E4CF5","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"pending_shared":[],"pending_connected_team_ids":[],"is_pending_ext_shared":false,"is_member":false,"is_private":false,"is_mpim":false,"topic":{"value":"","creator":"","last_set":0},"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":"U01C12E4CF5","last_set":1601958469},"previous_names":[],"num_members":2},{"id":"C01CQMA6E56","name":"testing","is_channel":true,"is_group":false,"is_im":false,"created":1601958837,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"testing","is_shared":false,"parent_conversation":null,"creator":"U01C12E4CF5","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"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":"U01C12E4CF5","last_set":1601958837},"previous_names":[],"num_members":3}],"response_metadata":{"next_cursor":""}}' - recorded_at: Thu, 08 Oct 2020 18:01:53 GMT - request: method: get uri: https://slack.com/api/conversations.list?token= @@ -88,11 +19,11 @@ http_interactions: message: OK headers: Date: - - Thu, 08 Oct 2020 22:26:38 GMT + - Fri, 09 Oct 2020 04:55:52 GMT Server: - Apache X-Slack-Req-Id: - - be65460fbdaeb077228d10bee193ab34 + - c5f7e044380cb70134e01fae37fa0d39 X-Oauth-Scopes: - identify,channels:read,groups:read,im:read,mpim:read,users:read,chat:write Access-Control-Expose-Headers: @@ -127,7 +58,7 @@ http_interactions: Content-Type: - application/json; charset=utf-8 X-Via: - - haproxy-www-ttqe,haproxy-edge-iad-cnm4 + - haproxy-www-y70x,haproxy-edge-iad-t0k4 body: encoding: ASCII-8BIT string: '{"ok":true,"channels":[{"id":"C01BTQN36CF","name":"sos","is_channel":true,"is_group":false,"is_im":false,"created":1602182145,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"sos","is_shared":false,"parent_conversation":null,"creator":"U01CQMA06F2","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"pending_shared":[],"pending_connected_team_ids":[],"is_pending_ext_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"topic":{"value":"help @@ -139,7 +70,7 @@ http_interactions: spur-of-the-moment ideas, and funny GIFs. Go wild!","creator":"U01C12E4CF5","last_set":1601958469},"previous_names":[],"num_members":2},{"id":"C01CQMA6E56","name":"testing","is_channel":true,"is_group":false,"is_im":false,"created":1601958837,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"testing","is_shared":false,"parent_conversation":null,"creator":"U01C12E4CF5","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"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":"U01C12E4CF5","last_set":1601958837},"previous_names":[],"num_members":3}],"response_metadata":{"next_cursor":""}}' - recorded_at: Thu, 08 Oct 2020 22:26:38 GMT + recorded_at: Fri, 09 Oct 2020 04:55:52 GMT - request: method: get uri: https://slack.com/api/conversations.list?token= @@ -159,7 +90,7 @@ http_interactions: message: OK headers: Date: - - Thu, 08 Oct 2020 22:40:58 GMT + - Fri, 09 Oct 2020 04:55:52 GMT Server: - Apache X-Xss-Protection: @@ -176,7 +107,7 @@ http_interactions: X-Accepted-Oauth-Scopes: - conversations:read X-Slack-Req-Id: - - 64a81352029771245d3ce8a67cee6f25 + - 55bd84baa387ec8373aa2f6bd10cb87d X-Slack-Backend: - r Access-Control-Allow-Origin: @@ -190,9 +121,9 @@ http_interactions: Content-Type: - application/json; charset=utf-8 X-Via: - - haproxy-www-pqd0,haproxy-edge-iad-fenm + - haproxy-www-572o,haproxy-edge-iad-w3jt body: encoding: ASCII-8BIT string: '{"ok":false,"error":"not_authed"}' - recorded_at: Thu, 08 Oct 2020 22:40:59 GMT + recorded_at: Fri, 09 Oct 2020 04:55:52 GMT recorded_with: VCR 6.0.0 diff --git a/test/channel_test.rb b/test/channel_test.rb index 5f65ced1..510c1c6e 100644 --- a/test/channel_test.rb +++ b/test/channel_test.rb @@ -22,7 +22,7 @@ end end -describe "list_all method" do + describe "list_all method" do it "returns an Array of Channels" do VCR.use_cassette("list_channels") do channels_list = Channel.list_all @@ -36,7 +36,9 @@ it "raises an error when token is not provided" do VCR.use_cassette("list_channels") do - expect{ Channel.get("#{BASE_URL}conversations.list", { token: "" }) }.must_raise SlackApiError + expect{ + Channel.get("#{BASE_URL}conversations.list", { token: "" }) + }.must_raise SlackApiError end end end From 331919aa369304f8f195280c3f5fb992d7892bb6 Mon Sep 17 00:00:00 2001 From: beauttie Date: Thu, 8 Oct 2020 22:20:11 -0700 Subject: [PATCH 23/25] Add tests for Workspace class --- test/cassettes/bad_post_request.yml | 133 ++++++++++++++ test/cassettes/load_workspace.yml | 158 +---------------- test/cassettes/negative-cases.yml | 264 ---------------------------- test/cassettes/send_message.yml | 35 ++-- test/workspace_test.rb | 37 ++-- 5 files changed, 184 insertions(+), 443 deletions(-) create mode 100644 test/cassettes/bad_post_request.yml delete mode 100644 test/cassettes/negative-cases.yml diff --git a/test/cassettes/bad_post_request.yml b/test/cassettes/bad_post_request.yml new file mode 100644 index 00000000..349bb326 --- /dev/null +++ b/test/cassettes/bad_post_request.yml @@ -0,0 +1,133 @@ +--- +http_interactions: +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=&text=u%20can%27t%20read%20me%20%3Asob%3A + 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 05:18:58 GMT + Server: + - Apache + X-Slack-Req-Id: + - 769ecbe9f8661ddbaaead934518a2273 + X-Oauth-Scopes: + - identify,channels:read,groups:read,im:read,mpim: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: + - 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-n4uf,haproxy-edge-iad-fc1p + body: + encoding: ASCII-8BIT + string: '{"ok":false,"error":"channel_not_found"}' + recorded_at: Fri, 09 Oct 2020 05:18:58 GMT +- request: + method: post + uri: https://slack.com/api/chat.postMessage + body: + encoding: UTF-8 + string: token=&channel=U01CQMA06F2&text= + 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 05:18:59 GMT + Server: + - Apache + X-Slack-Req-Id: + - 2a56ed3322e4a884d5fdaf9f11293850 + X-Oauth-Scopes: + - identify,channels:read,groups:read,im:read,mpim: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: + - 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: + - '50' + Content-Type: + - application/json; charset=utf-8 + X-Via: + - haproxy-www-hhav,haproxy-edge-iad-g302 + body: + encoding: ASCII-8BIT + string: '{"ok":false,"error":"no_text"}' + recorded_at: Fri, 09 Oct 2020 05:18:59 GMT +recorded_with: VCR 6.0.0 diff --git a/test/cassettes/load_workspace.yml b/test/cassettes/load_workspace.yml index 4bdda761..b235aa54 100644 --- a/test/cassettes/load_workspace.yml +++ b/test/cassettes/load_workspace.yml @@ -1,145 +1,5 @@ --- 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: - - Thu, 08 Oct 2020 18:23:13 GMT - Server: - - Apache - X-Slack-Req-Id: - - 8aa7f5c2ec8a1332441489ded9f00847 - X-Oauth-Scopes: - - chat:write,channels:read,users:read,groups:read,im:read,mpim: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: - - 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: - - '1246' - Content-Type: - - application/json; charset=utf-8 - X-Via: - - haproxy-www-9rc7,haproxy-edge-iad-jeyo - body: - encoding: ASCII-8BIT - string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"T01CQM3LG6L","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":"T01CQM3LG6L"},"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":"U01BU4T45M4","team_id":"T01CQM3LG6L","name":"eartholgaslackcli","deleted":false,"color":"3c989f","real_name":"Earth-Olga-SlackCLI","tz":"America\/Los_Angeles","tz_label":"Pacific - Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Earth-Olga-SlackCLI","real_name_normalized":"Earth-Olga-SlackCLI","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"gbab7602ab3d","api_app_id":"A01C72A3R60","always_active":false,"bot_id":"B01CDFD9RED","image_24":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/bab7602ab3d9731903ea0f8322150e35.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0022-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601959642},{"id":"U01C12E4CF5","team_id":"T01CQM3LG6L","name":"olga.tka4eva","deleted":false,"color":"9f69e7","real_name":"olga.tka4eva","tz":"America\/Los_Angeles","tz_label":"Pacific - Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"olga.tka4eva","real_name_normalized":"olga.tka4eva","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"ga2ccc03ad6a","image_24":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/a2ccc03ad6a78c01a9496acde6b590d8.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0015-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601958469},{"id":"U01CQMA06F2","team_id":"T01CQM3LG6L","name":"bak02013","deleted":false,"color":"4bbe2e","real_name":"Beauttie","tz":"America\/Los_Angeles","tz_label":"Pacific - Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Beauttie","real_name_normalized":"Beauttie","display_name":"Beauttie","display_name_normalized":"Beauttie","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g51d0ec2dd94","image_24":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/51d0ec2dd944e58eba412486ed4e2400.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601958823},{"id":"U01CQMN9XR6","team_id":"T01CQM3LG6L","name":"beauttie_api_project","deleted":false,"color":"e7392d","real_name":"Earth - - Beauttie - API Project","tz":"America\/Los_Angeles","tz_label":"Pacific - Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Earth - - Beauttie - API Project","real_name_normalized":"Earth - Beauttie - API Project","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g55b958146df","api_app_id":"A01BL47ENLX","always_active":false,"bot_id":"B01BU4SJZT8","first_name":"Earth","last_name":"- - Beauttie - API Project","image_24":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601961016}],"cache_ts":1602181394,"response_metadata":{"next_cursor":""}}' - recorded_at: Thu, 08 Oct 2020 18:23:14 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: - - Thu, 08 Oct 2020 18:23:14 GMT - Server: - - Apache - X-Slack-Req-Id: - - ddf5673a91964e9043a12f5585e12af5 - X-Oauth-Scopes: - - chat:write,channels:read,users:read,groups:read,im:read,mpim: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: - - 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: - - '638' - Content-Type: - - application/json; charset=utf-8 - X-Via: - - haproxy-www-1obv,haproxy-edge-iad-788y - body: - encoding: ASCII-8BIT - string: '{"ok":true,"channels":[{"id":"C01C0RQN3H8","name":"general","is_channel":true,"is_group":false,"is_im":false,"created":1601958469,"is_archived":false,"is_general":true,"unlinked":0,"name_normalized":"general","is_shared":false,"parent_conversation":null,"creator":"U01C12E4CF5","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"pending_shared":[],"pending_connected_team_ids":[],"is_pending_ext_shared":false,"is_member":false,"is_private":false,"is_mpim":false,"topic":{"value":"","creator":"","last_set":0},"purpose":{"value":"This - is the one channel that will always include everyone. It\u2019s a great spot - for announcements and team-wide conversations.","creator":"U01C12E4CF5","last_set":1601958469},"previous_names":[],"num_members":2},{"id":"C01CQM3LQ5N","name":"random","is_channel":true,"is_group":false,"is_im":false,"created":1601958469,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"random","is_shared":false,"parent_conversation":null,"creator":"U01C12E4CF5","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"pending_shared":[],"pending_connected_team_ids":[],"is_pending_ext_shared":false,"is_member":false,"is_private":false,"is_mpim":false,"topic":{"value":"","creator":"","last_set":0},"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":"U01C12E4CF5","last_set":1601958469},"previous_names":[],"num_members":2},{"id":"C01CQMA6E56","name":"testing","is_channel":true,"is_group":false,"is_im":false,"created":1601958837,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"testing","is_shared":false,"parent_conversation":null,"creator":"U01C12E4CF5","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"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":"U01C12E4CF5","last_set":1601958837},"previous_names":[],"num_members":3}],"response_metadata":{"next_cursor":""}}' - recorded_at: Thu, 08 Oct 2020 18:23:14 GMT - request: method: get uri: https://slack.com/api/users.list?token= @@ -159,11 +19,11 @@ http_interactions: message: OK headers: Date: - - Thu, 08 Oct 2020 22:26:37 GMT + - Fri, 09 Oct 2020 05:15:39 GMT Server: - Apache X-Slack-Req-Id: - - 96df28e6db0f8c6d36534794e242ac18 + - 745964ff0b2bb1be995851218cc18d58 X-Oauth-Scopes: - identify,channels:read,groups:read,im:read,mpim:read,users:read,chat:write Access-Control-Expose-Headers: @@ -198,7 +58,7 @@ http_interactions: Content-Type: - application/json; charset=utf-8 X-Via: - - haproxy-www-jtpc,haproxy-edge-iad-ev82 + - haproxy-www-xysk,haproxy-edge-pdx-5vxz body: encoding: ASCII-8BIT string: '{"ok":true,"members":[{"id":"USLACKBOT","team_id":"T01CQM3LG6L","name":"slackbot","deleted":false,"color":"757575","real_name":"Slackbot","tz":"America\/Los_Angeles","tz_label":"Pacific @@ -210,8 +70,8 @@ http_interactions: - Beauttie - API Project","tz":"America\/Los_Angeles","tz_label":"Pacific Daylight Time","tz_offset":-25200,"profile":{"title":"","phone":"","skype":"","real_name":"Earth - Beauttie - API Project","real_name_normalized":"Earth - Beauttie - API Project","display_name":"","display_name_normalized":"","fields":null,"status_text":"","status_emoji":"","status_expiration":0,"avatar_hash":"g55b958146df","api_app_id":"A01BL47ENLX","always_active":false,"bot_id":"B01BU4SJZT8","first_name":"Earth","last_name":"- - Beauttie - API Project","image_24":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601961016}],"cache_ts":1602195997,"response_metadata":{"next_cursor":""}}' - recorded_at: Thu, 08 Oct 2020 22:26:37 GMT + Beauttie - API Project","image_24":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=24&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=32&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=72&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=192&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-192.png","image_512":"https:\/\/secure.gravatar.com\/avatar\/55b958146dffe9b57f5f4ee786e5b408.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0005-512.png","status_text_canonical":"","team":"T01CQM3LG6L"},"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":1601961016}],"cache_ts":1602220539,"response_metadata":{"next_cursor":""}}' + recorded_at: Fri, 09 Oct 2020 05:15:39 GMT - request: method: get uri: https://slack.com/api/conversations.list?token= @@ -231,11 +91,11 @@ http_interactions: message: OK headers: Date: - - Thu, 08 Oct 2020 22:26:37 GMT + - Fri, 09 Oct 2020 05:15:39 GMT Server: - Apache X-Slack-Req-Id: - - 9874cd9fbab071835f279b5fed3b88ff + - a1bc8562fd69e42756e1df2fa1fa6efd X-Oauth-Scopes: - identify,channels:read,groups:read,im:read,mpim:read,users:read,chat:write Access-Control-Expose-Headers: @@ -270,7 +130,7 @@ http_interactions: Content-Type: - application/json; charset=utf-8 X-Via: - - haproxy-www-7pax,haproxy-edge-iad-8zmh + - haproxy-www-104q,haproxy-edge-pdx-f5k6 body: encoding: ASCII-8BIT string: '{"ok":true,"channels":[{"id":"C01BTQN36CF","name":"sos","is_channel":true,"is_group":false,"is_im":false,"created":1602182145,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"sos","is_shared":false,"parent_conversation":null,"creator":"U01CQMA06F2","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"pending_shared":[],"pending_connected_team_ids":[],"is_pending_ext_shared":false,"is_member":true,"is_private":false,"is_mpim":false,"topic":{"value":"help @@ -282,5 +142,5 @@ http_interactions: spur-of-the-moment ideas, and funny GIFs. Go wild!","creator":"U01C12E4CF5","last_set":1601958469},"previous_names":[],"num_members":2},{"id":"C01CQMA6E56","name":"testing","is_channel":true,"is_group":false,"is_im":false,"created":1601958837,"is_archived":false,"is_general":false,"unlinked":0,"name_normalized":"testing","is_shared":false,"parent_conversation":null,"creator":"U01C12E4CF5","is_ext_shared":false,"is_org_shared":false,"shared_team_ids":["T01CQM3LG6L"],"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":"U01C12E4CF5","last_set":1601958837},"previous_names":[],"num_members":3}],"response_metadata":{"next_cursor":""}}' - recorded_at: Thu, 08 Oct 2020 22:26:37 GMT + recorded_at: Fri, 09 Oct 2020 05:15:39 GMT recorded_with: VCR 6.0.0 diff --git a/test/cassettes/negative-cases.yml b/test/cassettes/negative-cases.yml deleted file mode 100644 index b6f435ee..00000000 --- a/test/cassettes/negative-cases.yml +++ /dev/null @@ -1,264 +0,0 @@ ---- -http_interactions: -- request: - method: post - uri: https://slack.com/api/chat.postMessage - body: - encoding: UTF-8 - string: token=&channel=&text=weird%20message - 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: - - Thu, 08 Oct 2020 21:58:46 GMT - Server: - - Apache - X-Slack-Req-Id: - - e2b56b56623ae4ac2ca424d4e693a657 - 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: - - 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-x0c9,haproxy-edge-pdx-74gg - body: - encoding: ASCII-8BIT - string: '{"ok":false,"error":"channel_not_found"}' - recorded_at: Thu, 08 Oct 2020 21:58:46 GMT -- request: - method: post - uri: https://slack.com/api/chat.postMessage - body: - encoding: UTF-8 - string: token=&channel=U01C12E4CF5&text=weird%20message - 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: - - Thu, 08 Oct 2020 22:05:00 GMT - Server: - - Apache - X-Slack-Req-Id: - - 7d1b0db6e21812071104b10283609d61 - 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: - - 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: - - '327' - Content-Type: - - application/json; charset=utf-8 - X-Via: - - haproxy-www-mki5,haproxy-edge-pdx-4yzm - body: - encoding: ASCII-8BIT - string: '{"ok":true,"channel":"D01C71YT34L","ts":"1602194700.000100","message":{"bot_id":"B01C00VN7L5","type":"message","text":"weird - message","user":"U01C12E4CF5","ts":"1602194700.000100","team":"T01CQM3LG6L","bot_profile":{"id":"B01C00VN7L5","deleted":false,"name":"Earth-Olga-SlackCLI","updated":1602017058,"app_id":"A01C72A3R60","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":"T01CQM3LG6L"}}}' - recorded_at: Thu, 08 Oct 2020 22:05:00 GMT -- request: - method: post - uri: https://slack.com/api/chat.postMessage - body: - encoding: UTF-8 - string: token=&channel=&text=weird%20message - 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: - - Thu, 08 Oct 2020 22:45:12 GMT - Server: - - Apache - X-Slack-Req-Id: - - 2140e1b2ce7de863240d4145ae6775fc - X-Oauth-Scopes: - - identify,channels:read,groups:read,im:read,mpim: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: - - 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-07yl,haproxy-edge-iad-9739 - body: - encoding: ASCII-8BIT - string: '{"ok":false,"error":"channel_not_found"}' - recorded_at: Thu, 08 Oct 2020 22:45:12 GMT -- request: - method: post - uri: https://slack.com/api/chat.postMessage - body: - encoding: UTF-8 - string: token=&channel=USLACKBOT&text= - 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: - - Thu, 08 Oct 2020 23:18:29 GMT - Server: - - Apache - X-Slack-Req-Id: - - a164ce5e2a3ba9a60bc5c0294b3971bd - 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: - - 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: - - '50' - Content-Type: - - application/json; charset=utf-8 - X-Via: - - haproxy-www-pqib,haproxy-edge-pdx-8ea4 - body: - encoding: ASCII-8BIT - string: '{"ok":false,"error":"no_text"}' - recorded_at: Thu, 08 Oct 2020 23:18:29 GMT -recorded_with: VCR 6.0.0 diff --git a/test/cassettes/send_message.yml b/test/cassettes/send_message.yml index 6d3216ef..1e50df0d 100644 --- a/test/cassettes/send_message.yml +++ b/test/cassettes/send_message.yml @@ -5,7 +5,7 @@ http_interactions: uri: https://slack.com/api/chat.postMessage body: encoding: UTF-8 - string: token=&channel=C01CQMA6E56&text=This%20is%20our%20first%20message + string: token=&channel=C01CQMA6E56&text=This%20is%20our%20first%20message%21 headers: Content-Type: - application/x-www-form-urlencoded @@ -21,13 +21,13 @@ http_interactions: message: OK headers: Date: - - Thu, 08 Oct 2020 21:54:35 GMT + - Fri, 09 Oct 2020 05:18:58 GMT Server: - Apache X-Slack-Req-Id: - - abffe2a63618eac66241b31492e4a839 + - 6e95f1f8c25566d082d60f122042c27e X-Oauth-Scopes: - - identify,channels:read,users:read,chat:write + - identify,channels:read,groups:read,im:read,mpim:read,users:read,chat:write Access-Control-Expose-Headers: - x-slack-req-id, retry-after Access-Control-Allow-Origin: @@ -56,22 +56,23 @@ http_interactions: Referrer-Policy: - no-referrer Content-Length: - - '332' + - '348' Content-Type: - application/json; charset=utf-8 X-Via: - - haproxy-www-fe3y,haproxy-edge-pdx-jpry + - haproxy-www-5geu,haproxy-edge-iad-32jr body: encoding: ASCII-8BIT - string: '{"ok":true,"channel":"C01CQMA6E56","ts":"1602194075.000200","message":{"bot_id":"B01C00VN7L5","type":"message","text":"This - is our first message","user":"U01C12E4CF5","ts":"1602194075.000200","team":"T01CQM3LG6L","bot_profile":{"id":"B01C00VN7L5","deleted":false,"name":"Earth-Olga-SlackCLI","updated":1602017058,"app_id":"A01C72A3R60","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":"T01CQM3LG6L"}}}' - recorded_at: Thu, 08 Oct 2020 21:54:35 GMT + string: '{"ok":true,"channel":"C01CQMA6E56","ts":"1602220738.000200","message":{"bot_id":"B01BL5M2VT9","type":"message","text":"This + is our first message!","user":"U01CQMA06F2","ts":"1602220738.000200","team":"T01CQM3LG6L","bot_profile":{"id":"B01BL5M2VT9","deleted":false,"name":"Earth + - Beauttie - API Project","updated":1601961796,"app_id":"A01BL47ENLX","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":"T01CQM3LG6L"}}}' + recorded_at: Fri, 09 Oct 2020 05:18:58 GMT - request: method: post uri: https://slack.com/api/chat.postMessage body: encoding: UTF-8 - string: token=&channel=C01CQMA6E56&text=This%20is%20our%20first%20message + string: token=&channel=U01CQMA06F2&text=can%20u%20not%20be%20such%20a%20perfectionist%3F headers: Content-Type: - application/x-www-form-urlencoded @@ -87,11 +88,11 @@ http_interactions: message: OK headers: Date: - - Thu, 08 Oct 2020 22:26:38 GMT + - Fri, 09 Oct 2020 05:18:59 GMT Server: - Apache X-Slack-Req-Id: - - cf630531cc97d42e9889507832b256f0 + - bf5263d0a44653271ca79cd53c7a0e45 X-Oauth-Scopes: - identify,channels:read,groups:read,im:read,mpim:read,users:read,chat:write Access-Control-Expose-Headers: @@ -122,15 +123,15 @@ http_interactions: Referrer-Policy: - no-referrer Content-Length: - - '345' + - '359' Content-Type: - application/json; charset=utf-8 X-Via: - - haproxy-www-edfp,haproxy-edge-iad-psc9 + - haproxy-www-g9kt,haproxy-edge-iad-1g3v body: encoding: ASCII-8BIT - string: '{"ok":true,"channel":"C01CQMA6E56","ts":"1602195998.000400","message":{"bot_id":"B01BL5M2VT9","type":"message","text":"This - is our first message","user":"U01CQMA06F2","ts":"1602195998.000400","team":"T01CQM3LG6L","bot_profile":{"id":"B01BL5M2VT9","deleted":false,"name":"Earth + string: '{"ok":true,"channel":"D01C0RX1T50","ts":"1602220739.000300","message":{"bot_id":"B01BL5M2VT9","type":"message","text":"can + u not be such a perfectionist?","user":"U01CQMA06F2","ts":"1602220739.000300","team":"T01CQM3LG6L","bot_profile":{"id":"B01BL5M2VT9","deleted":false,"name":"Earth - Beauttie - API Project","updated":1601961796,"app_id":"A01BL47ENLX","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":"T01CQM3LG6L"}}}' - recorded_at: Thu, 08 Oct 2020 22:26:38 GMT + recorded_at: Fri, 09 Oct 2020 05:18:59 GMT recorded_with: VCR 6.0.0 diff --git a/test/workspace_test.rb b/test/workspace_test.rb index 5d4f9418..9a1bc39e 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -5,7 +5,7 @@ describe "Workspace class" do before do - VCR.use_cassette("load workspace") do + VCR.use_cassette("load_workspace") do @workspace = Workspace.new end end @@ -43,7 +43,7 @@ it "raises an error when invalid user is entered" do expect { - @workspace.select_user("beepbop") + @workspace.select_user("troll") }.must_raise ArgumentError end end @@ -57,7 +57,7 @@ it "raises an error when invalid channel is entered" do expect { - @workspace.select_channel("beepbop") + @workspace.select_channel("trolling") }.must_raise ArgumentError end end @@ -72,11 +72,11 @@ end it "returns a String when user is selected" do - @workspace.select_channel("testing") + @workspace.select_channel("random") channel_details = @workspace.show_details expect(channel_details).must_be_kind_of String - expect(channel_details).must_equal "Channel testing's topic is and has 3 members. Its ID on Slack is C01CQMA6E56." + expect(channel_details).must_equal "Channel random's topic is anything and everything and has 2 members. Its ID on Slack is C01CQM3LQ5N." end it "raises an error when no recipient is selected" do @@ -87,33 +87,44 @@ end describe "send_message method" do - it "sends a message to the testing channel" do + it "can send a message to a valid channel" do VCR.use_cassette("send_message") do - @workspace.select_channel('testing') - response = @workspace.send_message('This is our first message') + @workspace.select_channel("testing") + response = @workspace.send_message("This is our first message!") + + expect(response).must_equal true + end + end + + it "can send a message to a valid user" do + VCR.use_cassette("send_message") do + @workspace.select_user("bak02013") + response = @workspace.send_message("can u not be such a perfectionist?") expect(response).must_equal true end end it "raises an error when recipient doesn't exist" do - VCR.use_cassette("negative-cases") do + VCR.use_cassette("bad_post_request") do recipient = Recipient.new("", "") + expect { - recipient.send_message("weird message") + recipient.send_message("u can't read me :sob:") }.must_raise SlackApiError end end it "raises an error when the message is empty" do - VCR.use_cassette("negative-cases") do - @workspace.select_user("slackbot") + VCR.use_cassette("bad_post_request") do + @workspace.select_user("bak02013") recipient = @workspace.selected + expect { recipient.send_message("") }.must_raise SlackApiError - end end end + end \ No newline at end of file From 20980161eaf2694cfdf6a4d62dcb4e17d8e5259e Mon Sep 17 00:00:00 2001 From: beauttie Date: Thu, 8 Oct 2020 23:00:52 -0700 Subject: [PATCH 24/25] Fix output from CLI when sending message --- lib/workspace.rb | 2 +- test/cassettes/send_message.yml | 24 ++++++++++++------------ test/workspace_test.rb | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/workspace.rb b/lib/workspace.rb index b63394f7..9b60d13d 100644 --- a/lib/workspace.rb +++ b/lib/workspace.rb @@ -45,7 +45,7 @@ def show_details def send_message(message) raise NoMethodError, "No recipient is currently selected." if no_recipient - @selected.send_message(message) + return "Message sent to #{@selected.class} #{@selected.name}!" if @selected.send_message(message) end end diff --git a/test/cassettes/send_message.yml b/test/cassettes/send_message.yml index 1e50df0d..fd046d9a 100644 --- a/test/cassettes/send_message.yml +++ b/test/cassettes/send_message.yml @@ -21,11 +21,11 @@ http_interactions: message: OK headers: Date: - - Fri, 09 Oct 2020 05:18:58 GMT + - Fri, 09 Oct 2020 06:00:05 GMT Server: - Apache X-Slack-Req-Id: - - 6e95f1f8c25566d082d60f122042c27e + - d2297e55216ae57df10a1c483870cc25 X-Oauth-Scopes: - identify,channels:read,groups:read,im:read,mpim:read,users:read,chat:write Access-Control-Expose-Headers: @@ -60,13 +60,13 @@ http_interactions: Content-Type: - application/json; charset=utf-8 X-Via: - - haproxy-www-5geu,haproxy-edge-iad-32jr + - haproxy-www-qbdl,haproxy-edge-pdx-mprq body: encoding: ASCII-8BIT - string: '{"ok":true,"channel":"C01CQMA6E56","ts":"1602220738.000200","message":{"bot_id":"B01BL5M2VT9","type":"message","text":"This - is our first message!","user":"U01CQMA06F2","ts":"1602220738.000200","team":"T01CQM3LG6L","bot_profile":{"id":"B01BL5M2VT9","deleted":false,"name":"Earth + string: '{"ok":true,"channel":"C01CQMA6E56","ts":"1602223205.000600","message":{"bot_id":"B01BL5M2VT9","type":"message","text":"This + is our first message!","user":"U01CQMA06F2","ts":"1602223205.000600","team":"T01CQM3LG6L","bot_profile":{"id":"B01BL5M2VT9","deleted":false,"name":"Earth - Beauttie - API Project","updated":1601961796,"app_id":"A01BL47ENLX","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":"T01CQM3LG6L"}}}' - recorded_at: Fri, 09 Oct 2020 05:18:58 GMT + recorded_at: Fri, 09 Oct 2020 06:00:05 GMT - request: method: post uri: https://slack.com/api/chat.postMessage @@ -88,11 +88,11 @@ http_interactions: message: OK headers: Date: - - Fri, 09 Oct 2020 05:18:59 GMT + - Fri, 09 Oct 2020 06:00:05 GMT Server: - Apache X-Slack-Req-Id: - - bf5263d0a44653271ca79cd53c7a0e45 + - a55e7c98bd55edfe81461425768d300e X-Oauth-Scopes: - identify,channels:read,groups:read,im:read,mpim:read,users:read,chat:write Access-Control-Expose-Headers: @@ -127,11 +127,11 @@ http_interactions: Content-Type: - application/json; charset=utf-8 X-Via: - - haproxy-www-g9kt,haproxy-edge-iad-1g3v + - haproxy-www-cv6x,haproxy-edge-pdx-uln4 body: encoding: ASCII-8BIT - string: '{"ok":true,"channel":"D01C0RX1T50","ts":"1602220739.000300","message":{"bot_id":"B01BL5M2VT9","type":"message","text":"can - u not be such a perfectionist?","user":"U01CQMA06F2","ts":"1602220739.000300","team":"T01CQM3LG6L","bot_profile":{"id":"B01BL5M2VT9","deleted":false,"name":"Earth + string: '{"ok":true,"channel":"D01C0RX1T50","ts":"1602223205.000800","message":{"bot_id":"B01BL5M2VT9","type":"message","text":"can + u not be such a perfectionist?","user":"U01CQMA06F2","ts":"1602223205.000800","team":"T01CQM3LG6L","bot_profile":{"id":"B01BL5M2VT9","deleted":false,"name":"Earth - Beauttie - API Project","updated":1601961796,"app_id":"A01BL47ENLX","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":"T01CQM3LG6L"}}}' - recorded_at: Fri, 09 Oct 2020 05:18:59 GMT + recorded_at: Fri, 09 Oct 2020 06:00:05 GMT recorded_with: VCR 6.0.0 diff --git a/test/workspace_test.rb b/test/workspace_test.rb index 9a1bc39e..d4c2da68 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -92,7 +92,7 @@ @workspace.select_channel("testing") response = @workspace.send_message("This is our first message!") - expect(response).must_equal true + expect(response).must_equal "Message sent to Channel testing!" end end @@ -101,7 +101,7 @@ @workspace.select_user("bak02013") response = @workspace.send_message("can u not be such a perfectionist?") - expect(response).must_equal true + expect(response).must_equal "Message sent to User bak02013!" end end From dbd35c645e560d14307306f9e7fc4489b290fd83 Mon Sep 17 00:00:00 2001 From: beauttie Date: Sat, 10 Oct 2020 16:41:58 -0700 Subject: [PATCH 25/25] Fix name of test --- test/workspace_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/workspace_test.rb b/test/workspace_test.rb index d4c2da68..d232a1c1 100644 --- a/test/workspace_test.rb +++ b/test/workspace_test.rb @@ -71,7 +71,7 @@ expect(user_details).must_equal "User olga.tka4eva's real name is olga.tka4eva, and their ID on Slack is U01C12E4CF5. Their current status reads: YAy! :+1:." end - it "returns a String when user is selected" do + it "returns a String when channel is selected" do @workspace.select_channel("random") channel_details = @workspace.show_details