forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plan_test.go
71 lines (65 loc) · 1.9 KB
/
plan_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
package stripe
import (
"strconv"
"testing"
assert "github.com/stretchr/testify/require"
"github.com/stripe/stripe-go/form"
)
func TestPlanListParams_AppendTo(t *testing.T) {
testCases := []struct {
field string
params *PlanListParams
want interface{}
}{
{"created", &PlanListParams{Created: 123}, strconv.FormatInt(123, 10)},
{
"created[gt]",
&PlanListParams{CreatedRange: &RangeQueryParams{GreaterThan: 123}},
strconv.FormatInt(123, 10),
},
}
for _, tc := range testCases {
t.Run(tc.field, func(t *testing.T) {
body := &form.Values{}
form.AppendTo(body, tc.params)
values := body.ToValues()
assert.Equal(t, tc.want, values.Get(tc.field))
})
}
}
func TestPlanListParams_AppendTo_Empty(t *testing.T) {
body := &form.Values{}
params := &PlanListParams{}
form.AppendTo(body, params)
assert.True(t, body.Empty())
}
func TestPlanParams_AppendTo(t *testing.T) {
testCases := []struct {
field string
params *PlanParams
want interface{}
}{
{"amount", &PlanParams{Amount: 123}, strconv.FormatUint(123, 10)},
{"currency", &PlanParams{Currency: "USD"}, "USD"},
{"id", &PlanParams{ID: "sapphire-elite"}, "sapphire-elite"},
{"interval", &PlanParams{Interval: "month"}, "month"},
{"interval_count", &PlanParams{IntervalCount: 3}, strconv.FormatUint(3, 10)},
{"name", &PlanParams{Name: "Sapphire Elite"}, "Sapphire Elite"},
{"statement_descriptor", &PlanParams{Statement: "Sapphire Elite"}, "Sapphire Elite"},
{"trial_period_days", &PlanParams{TrialPeriod: 123}, strconv.FormatUint(123, 10)},
}
for _, tc := range testCases {
t.Run(tc.field, func(t *testing.T) {
body := &form.Values{}
form.AppendTo(body, tc.params)
values := body.ToValues()
assert.Equal(t, tc.want, values.Get(tc.field))
})
}
}
func TestPlanParams_AppendTo_Empty(t *testing.T) {
body := &form.Values{}
params := &PlanParams{}
form.AppendTo(body, params)
assert.True(t, body.Empty())
}