/
onepost_social_post_test.rb
96 lines (88 loc) · 2.62 KB
/
onepost_social_post_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
require "test_helper"
class OnepostSocialPostTest < Minitest::Test
def setup
@client = Onepost::Client.new(
rapid_api_key: "12345",
secret_key: "67890"
)
end
def test_can_fetch_all_social_posts
stub_request(:get, "https://onepost1.p.rapidapi.com/api/v1/social_posts?secret_key=67890")
.with(
body: "{}",
headers: {
'Accept'=>'*/*',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby',
'X-Rapidapi-Host'=>'onepost1.p.rapidapi.com',
'X-Rapidapi-Key'=>'12345'
}
)
.to_return(status: 200, body: example_social_posts_data.to_json, headers: {})
data = @client.get_social_posts
assert_equal 2, data["collection"].count
end
def test_can_fetch_a_social_post
stub_request(:get, "https://onepost1.p.rapidapi.com/api/v1/social_posts/2?secret_key=67890")
.with(
body: "{}",
headers: {
'Accept'=>'*/*',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Content-Type'=>'application/json',
'User-Agent'=>'Ruby',
'X-Rapidapi-Host'=>'onepost1.p.rapidapi.com',
'X-Rapidapi-Key'=>'12345'
}
)
.to_return(status: 200, body: example_social_post_data.to_json, headers: {})
data = @client.get_social_post(2)
assert_equal 2, data["id"]
end
private
def example_social_posts_data
{
"current_page"=>1,
"per_page"=>30,
"total_entries"=>2,
"collection"=>[
{
"id"=>2,
"post_id"=>2,
"created_at"=>"2021-02-12T13:19:38.771-05:00",
"updated_at"=>"2021-02-12T13:19:49.642-05:00",
"type"=>"SocialPosts::Facebook",
"state"=>"sent",
"authorized_page_id"=>2,
"service_data"=>nil,
"service_data_updated_at"=>nil
},
{
"id"=>3,
"post_id"=>3,
"created_at"=>"2021-02-12T13:20:56.454-05:00",
"updated_at"=>"2021-02-12T13:21:20.939-05:00",
"type"=>"SocialPosts::Instagram",
"state"=>"sent",
"authorized_page_id"=>3,
"service_data"=>nil,
"service_data_updated_at"=>nil
}
]
}
end
def example_social_post_data
{
"id"=>2,
"post_id"=>2,
"created_at"=>"2021-02-12T13:19:38.771-05:00",
"updated_at"=>"2021-02-12T13:19:49.642-05:00",
"type"=>"SocialPosts::Facebook",
"state"=>"sent",
"authorized_page_id"=>2,
"service_data"=>nil,
"service_data_updated_at"=>nil
}
end
end