-
Notifications
You must be signed in to change notification settings - Fork 3
/
includes_test.go
108 lines (97 loc) · 2.05 KB
/
includes_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
package patreon
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
)
func TestParseIncludes(t *testing.T) {
includes := Includes{}
err := json.Unmarshal([]byte(includesJson), &includes)
require.NoError(t, err)
require.Len(t, includes.Items, 5)
user, ok := includes.Items[0].(*User)
require.True(t, ok)
require.Equal(t, "2822191", user.ID)
require.Equal(t, "user", user.Type)
require.Equal(t, "austinhub", user.Attributes.Vanity)
goal, ok := includes.Items[1].(*Goal)
require.True(t, ok)
require.Equal(t, "2131231", goal.ID)
require.Equal(t, "goal", goal.Type)
campaign, ok := includes.Items[2].(*Campaign)
require.True(t, ok)
require.Equal(t, "12312321", campaign.ID)
require.Equal(t, "campaign", campaign.Type)
tier, ok := includes.Items[3].(*Tier)
require.True(t, ok)
require.Equal(t, "15161351", tier.ID)
require.Equal(t, "tier", tier.Type)
require.True(t, tier.Attributes.Published)
benefit, ok := includes.Items[4].(*Benefit)
require.True(t, ok)
require.Equal(t, "10456319", benefit.ID)
require.Equal(t, "benefit", benefit.Type)
require.Equal(t, "custom", benefit.Attributes.BenefitType)
}
func TestParseUnsupportedInclude(t *testing.T) {
includes := Includes{}
err := json.Unmarshal([]byte(unknownIncludeJson), &includes)
require.Error(t, err)
require.Equal(t, "unsupported type 'unknown'", err.Error())
}
const includesJson = `
[
{
"attributes": {
"vanity": "austinhub"
},
"id": "2822191",
"relationships": {},
"type": "user"
},
{
"attributes": {
"amount": 1000
},
"id": "2131231",
"type": "goal"
},
{
"attributes": {},
"id": "12312321",
"type": "campaign"
},
{
"attributes": {
"published": true
},
"id": "15161351",
"type": "tier"
},
{
"attributes": {
"benefit_type": "custom"
},
"id": "10456319",
"type": "benefit"
}
]
`
const unknownIncludeJson = `
[
{
"attributes": {
"vanity": "austinhub"
},
"id": "2822191",
"relationships": {},
"type": "user"
},
{
"attributes": {},
"id": "12312312",
"relationships": {},
"type": "unknown"
}
]
`