Skip to content

Commit

Permalink
Fix slack tests to work with new post_to_slack method
Browse files Browse the repository at this point in the history
  • Loading branch information
KatieShipley committed Oct 12, 2021
1 parent 79a7f02 commit 179d87d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
4 changes: 1 addition & 3 deletions lib/cdo/slack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ def self.update_topic(channel_name, new_topic, use_channel_map = false)
url = "https://slack.com/api/conversations.setTopic"
payload = {"channel" => channel_id, "topic" => new_topic}
result = post_to_slack(url, payload)

raise "Failed to update topic in #{channel_name}" unless result
return true
return !!result
end

def self.replace_user_links(message)
Expand Down
26 changes: 12 additions & 14 deletions lib/test/cdo/test_slack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,37 @@ def setup
end

def test_get_topic
Slack.expects(:open).returns(
stub(
read: {
'ok' => true,
'channel' => {
'topic' => {
'value' => FAKE_TOPIC
}
Slack.expects(:post_to_slack).returns(
{
'ok' => true,
'channel' => {
'topic' => {
'value' => FAKE_TOPIC
}
}.to_json
)
}
}
)
actual_topic = Slack.get_topic FAKE_CHANNEL
assert_equal FAKE_TOPIC, actual_topic
end

def test_get_topic_with_error_response
Slack.expects(:open).returns(stub(read: {'ok' => false}.to_json))
Slack.stubs(:post_to_slack).returns(false)
assert_nil Slack.get_topic FAKE_CHANNEL
end

def test_update_topic
Slack.expects(:open).returns(stub(read: {'ok' => true}.to_json))
Slack.stubs(:post_to_slack).returns({'ok' => true})
assert Slack.update_topic(FAKE_CHANNEL, FAKE_TOPIC)
end

def test_join_room
Slack.expects(:open).returns(stub(read: {'ok' => true}.to_json))
Slack.stubs(:post_to_slack).returns({'ok' => true})
assert Slack.join_room(FAKE_CHANNEL)
end

def test_update_topic_with_error_response
Slack.expects(:open).returns(stub(read: {'ok' => false}.to_json))
Slack.stubs(:post_to_slack).returns(false)
refute Slack.update_topic(FAKE_CHANNEL, FAKE_TOPIC)
end

Expand Down

0 comments on commit 179d87d

Please sign in to comment.