-
Notifications
You must be signed in to change notification settings - Fork 3
/
post_test.go
91 lines (79 loc) · 2.32 KB
/
post_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
package patreon
import (
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/require"
)
func TestFetchPost(t *testing.T) {
setup()
defer teardown()
postID := "71427881"
mux.HandleFunc(fmt.Sprintf("/api/oauth2/v2/posts/%s", postID), func(writer http.ResponseWriter, request *http.Request) {
fmt.Fprint(writer, fetchPostResp)
})
resp, err := client.FetchCampaignPost(postID)
if err != nil {
panic(err)
}
require.NoError(t, err)
require.Equal(t, "post", resp.Data.Type)
require.Equal(t, postID, resp.Data.ID)
// Attributes
attrs := resp.Data.Attributes
require.Equal(t, 123, attrs.AppID)
require.NotEmpty(t, attrs.AppStatus)
require.NotEmpty(t, attrs.Content)
require.Empty(t, attrs.EmbedData)
require.Equal(t, "someurl.com", attrs.EmbedURL)
require.False(t, attrs.IsPaid)
require.False(t, attrs.IsPublic)
require.NotEmpty(t, attrs.PublishedAt)
require.NotEmpty(t, attrs.Title)
require.NotEmpty(t, attrs.URL)
// Relationships
user := resp.Data.Relationships.User
require.NotNil(t, user)
require.Equal(t, "234234234", user.Data.ID)
require.Equal(t, "user", user.Data.Type)
require.Equal(t, "https://www.patreon.com/api/oauth2/v2/user/234234234", user.Links.Related)
}
const fetchPostResp = `
{
"data": {
"attributes": {
"app_id": 123,
"app_status": "active",
"content": "<p>Would you like to see the video walkthrough of creating this Django REST API?</p>",
"embed_data": null,
"embed_url": "someurl.com",
"is_paid": false,
"is_public": false,
"published_at": "2022-09-02T17:36:41.000+00:00",
"title": "Django REST API (Source Code)",
"url": "/posts/django-rest-api-71427881"
},
"id": "71427881",
"relationships": {
"campaign": {
"data": { "id": "8636299", "type": "campaign" },
"links": {
"related": "https://www.patreon.com/api/oauth2/v2/campaigns/8636299"
}
},
"user": {
"data": { "id": "234234234", "type": "user" },
"links": {
"related": "https://www.patreon.com/api/oauth2/v2/user/234234234"
}
}
},
"type": "post"
},
"included": [
{ "attributes": {}, "id": "234234234", "type": "user" },
{ "attributes": {}, "id": "8636299", "type": "campaign" }
],
"links": { "self": "https://www.patreon.com/api/oauth2/v2/posts/71427881" }
}
`