-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcampaign_test.go
160 lines (144 loc) · 5.86 KB
/
campaign_test.go
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package patreon
import (
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/require"
)
func TestFetchCampaign(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/oauth2/api/current_user/campaigns", func(writer http.ResponseWriter, request *http.Request) {
fmt.Fprint(writer, fetchCampaignResp)
})
resp, err := client.FetchCampaign()
require.NoError(t, err)
require.Equal(t, 1, len(resp.Data))
require.Equal(t, "campaign", resp.Data[0].Type)
require.Equal(t, "278915", resp.Data[0].ID)
require.Equal(t, "new podcasting experience - Podsync", resp.Data[0].Attributes.CreationName)
// Attributes
attrs := resp.Data[0].Attributes
require.Equal(t, 8, attrs.CreationCount)
require.True(t, attrs.DisplayPatronGoals)
require.NotEmpty(t, attrs.ImageSmallURL)
require.NotEmpty(t, attrs.ImageURL)
require.True(t, attrs.IsChargedImmediately)
require.True(t, attrs.IsMonthly)
require.True(t, attrs.IsNsfw)
require.True(t, attrs.IsPlural)
require.Equal(t, 123121, attrs.PatronCount)
require.Equal(t, "month", attrs.PayPerName)
require.Equal(t, 12321312, attrs.PledgeSum)
require.NotEmpty(t, attrs.Summary)
require.NotEmpty(t, attrs.PledgeURL)
require.NotEmpty(t, attrs.ThanksMsg)
// Relationships
creator := resp.Data[0].Relationships.Creator
require.NotNil(t, creator)
require.Equal(t, "2343242423", creator.Data.ID)
require.Equal(t, "user", creator.Data.Type)
require.Equal(t, "https://www.patreon.com/api/user/2343242423", creator.Links.Related)
categories := resp.Data[0].Relationships.Categories
require.NotNil(t, categories)
require.Equal(t, 1, len(categories.Data))
require.Equal(t, "7", categories.Data[0].ID)
require.Equal(t, "category", categories.Data[0].Type)
// Includes
user, ok := resp.Included.Items[0].(*User)
require.True(t, ok)
require.Equal(t, "2822191", user.ID)
require.Equal(t, "user", user.Type)
require.Equal(t, "podsync", user.Attributes.Vanity)
reward, ok := resp.Included.Items[1].(*Reward)
require.True(t, ok)
require.Equal(t, "12312312", reward.ID)
require.Equal(t, "reward", reward.Type)
require.Equal(t, 100, reward.Attributes.Amount)
goal, ok := resp.Included.Items[2].(*Goal)
require.True(t, ok)
require.Equal(t, "2131231", goal.ID)
require.Equal(t, "goal", goal.Type)
require.Equal(t, 1000, goal.Attributes.Amount)
}
const fetchCampaignResp = `
{
"data": [
{
"attributes": {
"created_at": "2016-02-02T19:58:18+00:00",
"creation_count": 8,
"creation_name": "new podcasting experience - Podsync",
"discord_server_id": null,
"display_patron_goals": true,
"earnings_visibility": null,
"image_small_url": "https://c10.patreon.com/3/eyJoIjoxMjgwLCJ3IjoxMjgwfQ%3D%3D/patreon-user/AS2N2NrZauWDuhVcuua87P7QtSOdCtPWiazP99SpvJWWHn8d4GvZI56AHqTn94g2_large_2.png?token-time=2145916800&token-hash=VNcCmkq6bOjbjizpwNHePu3aNqujVMKJYdfaPxoz3_c%3D",
"image_url": "https://c10.patreon.com/3/eyJ3IjoxOTIwfQ%3D%3D/patreon-user/AS2N2NrZauWDuhVcuua87P7QtSOdCtPWiazP99SpvJWWHn8d4GvZI56AHqTn94g2_large_2.png?token-time=2145916800&token-hash=4KxOxPVCtGwPskLYr8BZGyZW94VwAKbD7j9RDHcvf0E%3D",
"is_charged_immediately": true,
"is_monthly": true,
"is_nsfw": true,
"is_plural": true,
"main_video_embed": "",
"main_video_url": "",
"one_liner": null,
"outstanding_payment_amount_cents": 0,
"patron_count": 123121,
"pay_per_name": "month",
"pledge_sum": 12321312,
"pledge_url": "/bePatron?c=278915",
"published_at": "2016-02-02T20:11:19+00:00",
"summary": "<a href=\"http://podsync.net/\" rel=\"nofollow\">Podsync</a> - is a simple, free service that lets you listen to any YouTube / Vimeo channels, playlists or user videos in podcast format.<br><br><strong>Idea:</strong><br>Podcast applications have a rich functionality for content delivery - automatic download of new episodes, remembering last played position, sync between devices and offline listening. This functionality is not available on YouTube and Vimeo. So the aim of\u00a0<a href=\"http://podsync.net/\" rel=\"nofollow\">Podsync</a> is to make your life easier and enable you to view/listen to content on any device in podcast client.<br><br>It's my hobby project, so to continue to support and improve it, I need your help. Your money will go into paying my server bills and adding new features.<br><br>",
"thanks_embed": "",
"thanks_msg": "You are awesome!",
"thanks_video_url": null
},
"id": "278915",
"type": "campaign",
"relationships": {
"categories": {
"data": [
{
"id": "7",
"type": "category"
}
]
},
"creator": {
"data": {
"id": "2343242423",
"type": "user"
},
"links": {
"related": "https://www.patreon.com/api/user/2343242423"
}
}
}
}
],
"included": [
{
"attributes": {
"vanity": "podsync"
},
"id": "2822191",
"relationships": {},
"type": "user"
},
{
"attributes": {
"amount": 100
},
"id": "12312312",
"relationships": {},
"type": "reward"
},
{
"attributes": {
"amount": 1000
},
"id": "2131231",
"type": "goal"
}
]
}
`