|
1 | 1 | require_relative '../spec_helper' |
2 | 2 |
|
3 | 3 | describe Tweetkit::Client::Tweets do |
4 | | - before(:each) do |
5 | | - @client = Tweetkit::Client.new(bearer_token: ENV['BEARER_TOKEN']) |
6 | | - end |
| 4 | + client_types = { |
| 5 | + bearer_token: Tweetkit::Client.new(bearer_token: ENV['BEARER_TOKEN']), |
| 6 | + access_token: Tweetkit::Client.new( |
| 7 | + consumer_key: ENV['CONSUMER_KEY'], |
| 8 | + consumer_secret: ENV['CONSUMER_SECRET'], |
| 9 | + access_token: ENV['ACCESS_TOKEN'], |
| 10 | + access_token_secret: ENV['ACCESS_TOKEN_SECRET'], |
| 11 | + ), |
| 12 | + } |
| 13 | + |
| 14 | + client_types.each do |client_type, client| |
| 15 | + context "with #{client_type} client" do |
| 16 | + describe '.tweet' do |
| 17 | + it 'accepts an ID and gets a tweet' do |
| 18 | + response = client.tweet(1228393702244134912) |
| 19 | + |
| 20 | + expect(response.tweet.text).not_to be_empty |
| 21 | + end |
| 22 | + end |
| 23 | + |
| 24 | + describe '.tweets' do |
| 25 | + it 'accepts an array of IDs and gets the tweets' do |
| 26 | + response = client.tweets([1228393702244134912, 1227640996038684673]) |
| 27 | + |
| 28 | + expect(response.tweets.size).to eq(2) |
| 29 | + expect(response.tweets.first.text).not_to be_empty |
| 30 | + end |
7 | 31 |
|
8 | | - describe '.tweet' do |
9 | | - it 'accepts an ID and gets a tweet' do |
10 | | - response = @client.tweet(1228393702244134912) |
| 32 | + it 'accepts comma-separated string of IDs and gets the tweets' do |
| 33 | + response = client.tweets([1228393702244134912, 1227640996038684673]) |
11 | 34 |
|
12 | | - expect(response.tweet.text).not_to be_empty |
| 35 | + expect(response.tweets.size).to eq(2) |
| 36 | + expect(response.tweets.first.text).not_to be_empty |
| 37 | + end |
| 38 | + end |
13 | 39 | end |
14 | 40 | end |
15 | 41 |
|
16 | | - describe '.tweets' do |
17 | | - it 'accepts an array of IDs and gets the tweets' do |
18 | | - response = @client.tweets([1228393702244134912, 1227640996038684673]) |
| 42 | + context 'when user context is required' do |
| 43 | + let(:client) { client_types[:access_token] } |
19 | 44 |
|
20 | | - expect(response.tweets.size).to eq(2) |
21 | | - expect(response.tweets.first.text).not_to be_empty |
| 45 | + describe '.post_tweet' do |
| 46 | + it 'posts text' do |
| 47 | + response = client.post_tweet(text: 'Hello world') |
| 48 | + expect(response.tweet.text).not_to be_empty |
| 49 | + end |
22 | 50 | end |
23 | 51 |
|
24 | | - it 'accepts comma-separated string of IDs and gets the tweets' do |
25 | | - response = @client.tweets([1228393702244134912, 1227640996038684673]) |
| 52 | + describe '.delete_tweet' do |
| 53 | + it 'deletes a tweet' do |
| 54 | + create_response = client.post_tweet(text: 'Hello world') |
| 55 | + tweet_id = create_response.tweet.id.to_i |
| 56 | + delete_response = client.delete_tweet(tweet_id) |
26 | 57 |
|
27 | | - expect(response.tweets.size).to eq(2) |
28 | | - expect(response.tweets.first.text).not_to be_empty |
| 58 | + expect(delete_response.response.dig('data', 'deleted')).to be(true) |
| 59 | + end |
29 | 60 | end |
30 | 61 | end |
31 | 62 | end |
0 commit comments