-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaddress_test.go
103 lines (92 loc) · 2.3 KB
/
address_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
package patreon
import (
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/require"
)
func TestFetchAddress(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, fetchMemberAddressInclResp)
})
resp, err := client.FetchCampaignMember(memberID)
require.NoError(t, err)
require.Equal(t, "member", resp.Data.Type)
require.Equal(t, memberID, resp.Data.ID)
// Includes
address, ok := resp.Included.Items[0].(*Address)
require.True(t, ok)
attr := address.Attributes
require.Equal(t, "123", address.ID)
require.Equal(t, "address", address.Type)
require.Equal(t, "address", attr.Addressee)
require.Equal(t, "city", attr.City)
require.Equal(t, "USA", attr.Country)
require.NotNil(t, attr.CreatedAt)
require.Equal(t, "line 1", attr.Line1)
require.Equal(t, "Apt. 101", attr.Line2)
require.Equal(t, "555-555-5555", attr.PhoneNumber)
require.Equal(t, "123", attr.PostalCode)
require.Equal(t, "AZ", attr.State)
}
const fetchMemberAddressInclResp = `
{
"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": {
"addressee": "address",
"city": "city",
"country": "USA",
"created_at": "2022-05-05T18:33:45.000+00:00",
"line_1": "line 1",
"line_2": "Apt. 101",
"phone_number": "555-555-5555",
"postal_code": "123",
"state": "AZ"
},
"id": "123",
"type": "address"
},
{
"attributes": {},
"id": "123",
"type": "user"
}
],
"links": {
"self": "https://www.patreon.com/api/oauth2/v2/members/123-456-789"
}
}
`