1
+ # This file is auto-generated from the same code that generates
2
+ # https://docs.patreon.com. Community pull requests against this
3
+ # file may not be accepted.
4
+
1
5
require 'json'
2
6
3
7
describe Patreon ::API do
4
8
before do
5
9
@api = Patreon ::API . new ( "some token" )
6
10
end
7
11
8
- describe "Patreon::API#fetch_user " do
12
+ describe "Patreon::API" do
9
13
before ( :all ) do
10
14
@response = File . read ( File . expand_path ( "fixtures/current_user.json" , __dir__ ) )
11
15
end
12
16
13
- it "should get current_user " do
14
- @api . expects ( :get_json ) . with ( "current_user " ) . returns ( @response )
15
- response = @api . fetch_user
17
+ it "should parse data " do
18
+ @api . expects ( :get_json ) . with ( "identity " ) . returns ( @response )
19
+ response = @api . get_identity
16
20
assert_equal response . data . pledges . count , 5
17
21
assert_equal response . data . vanity , "corgi"
18
22
assert_equal response . data . first_name , "Corgi"
19
23
end
20
24
21
- it "should get current_user and the user should be mutable" do
22
- @api . expects ( :get_json ) . with ( "current_user" ) . returns ( @response )
23
- response = @api . fetch_user
24
- assert_equal response . data . pledges . count , 5
25
- assert_equal response . data . vanity , "corgi"
25
+ it "should allow mutating data" do
26
+ @api . expects ( :get_json ) . with ( "identity" ) . returns ( @response )
27
+ response = @api . get_identity
26
28
assert_equal response . data . first_name , "Corgi"
27
29
response . data . first_name = "Jack"
28
30
assert_equal response . data . first_name , "Jack"
29
31
end
30
32
31
- it "should get current_user correctly if field is nil " do
33
+ it "should support nill value " do
32
34
munged_response = JSON . parse ( @response )
33
35
munged_response [ 'data' ] [ 'attributes' ] [ 'first_name' ] = nil
34
- @api . expects ( :get_json ) . with ( "current_user" ) . returns ( munged_response . to_json )
35
- response = @api . fetch_user
36
- assert_equal response . data . pledges . count , 5
37
- assert_equal response . data . vanity , "corgi"
36
+ @api . expects ( :get_json ) . with ( "identity" ) . returns ( munged_response . to_json )
37
+ response = @api . get_identity
38
38
assert_nil response . data . first_name
39
39
end
40
+ end
40
41
41
- it "should get current_user with includes " do
42
- @api . expects ( :get_json ) . with ( "current_user?include=hello" ) . returns ( @response )
43
- @api . fetch_user ( includes : "hello" )
42
+ describe "Patreon::API#get_campaigns " do
43
+ before ( :all ) do
44
+ @response = File . read ( File . expand_path ( "fixtures/current_user.json" , __dir__ ) )
44
45
end
45
46
46
- it "should get current_user with fields" do
47
- @api . expects ( :get_json ) . with ( "current_user?fields%5Bhello%5D=there" ) . returns ( @response )
48
- @api . fetch_user ( fields : { hello : "there" } )
47
+ it "should return data" do
48
+ resource_id = "32187"
49
+ expected_url = "campaigns"
50
+ expected_url += "?page%5Bcount%5D=10"
51
+ @api . expects ( :get_json ) . with ( expected_url ) . returns ( @response )
52
+ response = @api . get_campaigns ( )
53
+ assert_equal response . data . id , resource_id
49
54
end
50
55
end
51
56
52
- describe "Patreon::API#fetch_campaign " do
57
+ describe "Patreon::API#get_identity " do
53
58
before ( :all ) do
54
- @response = File . read ( File . expand_path ( "fixtures/fetch_campaign .json" , __dir__ ) )
59
+ @response = File . read ( File . expand_path ( "fixtures/current_user .json" , __dir__ ) )
55
60
end
56
61
57
- it "should get fetch_campaign" do
58
- @api . expects ( :get_json ) . with ( "current_user/campaigns" ) . returns ( @response )
59
- response = @api . fetch_campaign
60
- assert_equal response . data . count , 1
61
- assert_equal response . data [ 0 ] . creation_name , "an unforgettable high school experience"
62
+ it "should return data" do
63
+ resource_id = "32187"
64
+ expected_url = "identity"
65
+ @api . expects ( :get_json ) . with ( expected_url ) . returns ( @response )
66
+ response = @api . get_identity ( )
67
+ assert_equal response . data . id , resource_id
62
68
end
69
+ end
63
70
64
- it "should get fetch_campaign with includes " do
65
- @api . expects ( :get_json ) . with ( "current_user/campaigns?include=hello" ) . returns ( @response )
66
- @api . fetch_campaign ( includes : "hello" )
71
+ describe "Patreon::API#get_webhooks " do
72
+ before ( :all ) do
73
+ @response = File . read ( File . expand_path ( "fixtures/current_user.json" , __dir__ ) )
67
74
end
68
75
69
- it "should get fetch_campaign with fields" do
70
- @api . expects ( :get_json ) . with ( "current_user/campaigns?fields%5Bhello%5D=there" ) . returns ( @response )
71
- @api . fetch_campaign ( fields : { hello : "there" } )
76
+ it "should return data" do
77
+ resource_id = "32187"
78
+ expected_url = "webhooks"
79
+ expected_url += "?page%5Bcount%5D=10"
80
+ @api . expects ( :get_json ) . with ( expected_url ) . returns ( @response )
81
+ response = @api . get_webhooks ( )
82
+ assert_equal response . data . id , resource_id
72
83
end
73
84
end
74
85
75
- describe "Patreon::API#fetch_campaign_and_patrons " do
86
+ describe "Patreon::API#get_campaigns_by_id_members " do
76
87
before ( :all ) do
77
- @response = File . read ( File . expand_path ( "fixtures/fetch_campaign .json" , __dir__ ) )
88
+ @response = File . read ( File . expand_path ( "fixtures/current_user .json" , __dir__ ) )
78
89
end
79
90
80
- it "should get fetch_campaign_and_patrons" do
81
- @api . expects ( :get_json ) . with ( "current_user/campaigns?include=rewards%2Ccreator%2Cgoals%2Cpledges" ) . returns ( @response )
82
- @api . fetch_campaign_and_patrons
91
+ it "should return data" do
92
+ resource_id = "32187"
93
+ expected_url = "campaigns/{}/members" . gsub ( '{}' , resource_id )
94
+ expected_url += "?page%5Bcount%5D=10"
95
+ @api . expects ( :get_json ) . with ( expected_url ) . returns ( @response )
96
+ response = @api . get_campaigns_by_id_members ( resource_id )
97
+ assert_equal response . data . id , resource_id
83
98
end
99
+ end
84
100
85
- it "should get fetch_campaign_and_patrons with more includes" do
86
- @api . expects ( :get_json ) . with ( "current_user/campaigns?include=doohickey%2Crewards%2Ccreator%2Cgoals%2Cpledges" ) . returns ( @response )
87
- @api . fetch_campaign_and_patrons ( includes : "doohickey" )
101
+ describe "Patreon::API#get_campaigns_by_id" do
102
+ before ( :all ) do
103
+ @response = File . read ( File . expand_path ( "fixtures/current_user.json" , __dir__ ) )
104
+ end
105
+
106
+ it "should return data" do
107
+ resource_id = "32187"
108
+ expected_url = "campaigns/{}" . gsub ( '{}' , resource_id )
109
+ @api . expects ( :get_json ) . with ( expected_url ) . returns ( @response )
110
+ response = @api . get_campaigns_by_id ( resource_id )
111
+ assert_equal response . data . id , resource_id
88
112
end
89
113
end
90
114
91
- describe "Patreon::API#fetch_page_of_pledges " do
115
+ describe "Patreon::API#get_webhooks_by_id " do
92
116
before ( :all ) do
93
- @response = File . read ( File . expand_path ( "fixtures/fetch_campaign .json" , __dir__ ) )
117
+ @response = File . read ( File . expand_path ( "fixtures/current_user .json" , __dir__ ) )
94
118
end
95
119
96
- it "should get fetch_page_of_pledges" do
97
- @api . expects ( :get_json ) . with ( "campaigns/123/pledges?page%5Bcount%5D=10" ) . returns ( @response )
98
- @api . fetch_page_of_pledges ( 123 )
120
+ it "should return data" do
121
+ resource_id = "32187"
122
+ expected_url = "webhooks/{}" . gsub ( '{}' , resource_id )
123
+ @api . expects ( :get_json ) . with ( expected_url ) . returns ( @response )
124
+ response = @api . get_webhooks_by_id ( resource_id )
125
+ assert_equal response . data . id , resource_id
99
126
end
100
127
end
101
- end
128
+
129
+ describe "Patreon::API#get_members_by_id" do
130
+ before ( :all ) do
131
+ @response = File . read ( File . expand_path ( "fixtures/current_user.json" , __dir__ ) )
132
+ end
133
+
134
+ it "should return data" do
135
+ resource_id = "32187"
136
+ expected_url = "members/{}" . gsub ( '{}' , resource_id )
137
+ @api . expects ( :get_json ) . with ( expected_url ) . returns ( @response )
138
+ response = @api . get_members_by_id ( resource_id )
139
+ assert_equal response . data . id , resource_id
140
+ end
141
+ end
142
+
143
+ end
0 commit comments