-
Notifications
You must be signed in to change notification settings - Fork 3
/
goal_test.go
72 lines (61 loc) · 1.67 KB
/
goal_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
package patreon
import (
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/require"
)
func TestFetchGoal(t *testing.T) {
setup()
defer teardown()
campaignID := "999999"
mux.HandleFunc(fmt.Sprintf("/api/oauth2/v2/campaigns/%s", campaignID), func(writer http.ResponseWriter, request *http.Request) {
fmt.Fprint(writer, fetchCampaignIncludeGoalResp)
})
resp, err := client.FetchCampaign(campaignID)
if err != nil {
panic(err)
}
require.NoError(t, err)
require.Equal(t, "campaign", resp.Data.Type)
require.Equal(t, "999999", resp.Data.ID)
// Includes
goal := resp.Included.Items[0].(*Goal)
require.Equal(t, "1874109", goal.ID)
require.Equal(t, "goal", goal.Type)
require.Equal(t, 50000, goal.Attributes.AmountCents)
require.Equal(t, 200, goal.Attributes.CompletedPercentage)
require.NotEmpty(t, goal.Attributes.CreatedAt)
require.NotEmpty(t, goal.Attributes.Description)
require.Empty(t, goal.Attributes.ReachedAt)
require.Empty(t, goal.Attributes.Title)
}
const fetchCampaignIncludeGoalResp = `
{
"data": {
"attributes": {
"url": "https://www.patreon.com/austinhub"
},
"id": "999999",
"relationships": {
"goals": { "data": [{ "id": "1874109", "type": "goal" }] }
},
"type": "campaign"
},
"included": [
{
"attributes": {
"amount_cents": 50000,
"completed_percentage": 200,
"created_at": "2022-09-02T21:15:47.000+00:00",
"description": "When I reach $500 per month, that'd be crazy.",
"reached_at": null,
"title": ""
},
"id": "1874109",
"type": "goal"
}
],
"links": { "self": "https://www.patreon.com/api/oauth2/v2/campaigns/8636299" }
}
`