Skip to content

Commit 95f9f1f

Browse files
committed
Reorganized test structure
1 parent 6f65d68 commit 95f9f1f

7 files changed

Lines changed: 46 additions & 4 deletions

File tree

lib/tweetkit/request.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ def request(method, endpoint, data, **options)
113113
def format_error_message(error)
114114
error_obj = JSON.parse(error.response_body)
115115

116-
<<-ERR
117-
Error: #{error_obj.dig("title")} (#{error_obj.dig("status")})
116+
<<~ERR
117+
#{error_obj.dig("title")} (#{error_obj.dig("status")})
118118
Description: #{error_obj.dig("detail")}
119119
Error Info: #{error_obj.dig("errors", 0, "message")}
120120
Error Link: #{error_obj.dig("type")}
File renamed without changes.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,49 @@ def test_tweets_from_string_of_ids
3737
assert_equal 2, tweets.count
3838
end
3939

40+
def test_tweet_fails_with_invalid_id_args
41+
assert_raises(Tweetkit::Error::ClientError) do
42+
@bearer_token_client.tweet("fail")
43+
end
44+
end
45+
46+
def test_tweet_fails_with_invalid_options
47+
assert_raises(Tweetkit::Error::ClientError) do
48+
@bearer_token_client.tweet(TEST_TWEET_ID_1, fail: true)
49+
end
50+
end
51+
52+
def test_tweets_fails_with_invalid_id_args
53+
assert_raises(Tweetkit::Error::ClientError) do
54+
@bearer_token_client.tweets("fail")
55+
end
56+
57+
assert_raises(Tweetkit::Error::ClientError) do
58+
@bearer_token_client.tweets(["fail"])
59+
end
60+
end
61+
62+
def test_tweets_fails_with_invalid_options
63+
assert_raises(Tweetkit::Error::ClientError) do
64+
@bearer_token_client.tweets([TEST_TWEET_ID_1], fail: true)
65+
end
66+
end
67+
4068
def test_post_tweet
4169
text = random_text
4270
tweet = @access_token_client.post_tweet(text: text)
4371

4472
assert_equal text, tweet.text
4573
end
4674

75+
def test_post_tweet_fails_with_invalid_options
76+
text = random_text
77+
78+
assert_raises(Tweetkit::Error::ClientError) do
79+
@access_token_client.post_tweet(text: text, fail: true)
80+
end
81+
end
82+
4783
def test_delete_tweet
4884
text = random_text
4985
tweet = @access_token_client.post_tweet(text: text)
@@ -53,6 +89,12 @@ def test_delete_tweet
5389
assert_equal true, deleted
5490
end
5591

92+
def test_delete_tweet_fails_for_other_users_tweets
93+
assert_raises(Tweetkit::Error::ClientError) do
94+
@access_token_client.delete_tweet(TEST_TWEET_ID_1)
95+
end
96+
end
97+
5698
private
5799

58100
def random_text
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "test_helper"
22

3-
class ClientTest < Minitest::Test
3+
class Tweetkit::ClientTest < Minitest::Test
44
def test_new_client
55
client = Tweetkit::Client.new(
66
access_token: ENV["ACCESS_TOKEN"],
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "test_helper"
22

3-
class Tweetkit::Client::TweetTest < Minitest::Test
3+
class Tweetkit::Response::TweetTest < Minitest::Test
44
attr_accessor :client
55

66
TWEET_ID = 1212092628029698048

0 commit comments

Comments
 (0)