-
Notifications
You must be signed in to change notification settings - Fork 3
/
member_test.go
101 lines (87 loc) · 2.26 KB
/
member_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
package patreon
import (
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/require"
)
func TestFetchMember(t *testing.T) {
setup()
defer teardown()
memberID := "123-456-789"
mux.HandleFunc(fmt.Sprintf("/api/oauth2/v2/members/%s", memberID), func(writer http.ResponseWriter, request *http.Request) {
fmt.Fprint(writer, fetchMemberResp)
})
resp, err := client.FetchCampaignMember(memberID)
if err != nil {
panic(err)
}
require.NoError(t, err)
require.Equal(t, "member", resp.Data.Type)
require.Equal(t, memberID, resp.Data.ID)
// Attributes
attrs := resp.Data.Attributes
require.Equal(t, "first last", attrs.FullName)
// require.NotEmpty(t, attrs.ImageSmallURL)
require.NotEmpty(t, attrs.LastChargeDate)
require.False(t, attrs.IsFollower)
// require.Equal(t, 123121, attrs.PatronCount)
// require.Equal(t, "month", attrs.PayPerName)
// require.NotEmpty(t, attrs.Summary)
// require.NotEmpty(t, attrs.PledgeURL)
// require.NotEmpty(t, attrs.ThanksMsg)
// Relationships
address := resp.Data.Relationships.Address
require.NotNil(t, address)
require.Equal(t, "123", address.Data.ID)
require.Equal(t, "address", address.Data.Type)
require.Equal(t, "https://www.patreon.com/api/oauth2/v2/address/123", address.Links.Related)
}
const fetchMemberResp = `
{
"data": {
"attributes": {
"full_name": "first last",
"is_follower": false,
"last_charge_date": "2020-10-01T11:18:36.000+00:00"
},
"id": "123-456-789",
"relationships": {
"address": {
"data": {
"id": "123",
"type": "address"
},
"links": {
"related": "https://www.patreon.com/api/oauth2/v2/address/123"
}
},
"user": {
"data": {
"id": "123",
"type": "user"
},
"links": {
"related": "https://www.patreon.com/api/oauth2/v2/user/123"
}
}
},
"type": "member"
},
"included": [
{
"attributes": {},
"id": "123",
"type": "address"
},
{
"attributes": {},
"id": "123",
"type": "user"
}
],
"links": {
"self": "https://www.patreon.com/api/oauth2/v2/members/123-456-789"
}
}
`