-
Notifications
You must be signed in to change notification settings - Fork 463
/
Copy pathsub_test.go
56 lines (48 loc) · 1.29 KB
/
sub_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
package stripe
import (
"encoding/json"
"testing"
assert "github.com/stretchr/testify/require"
"github.com/stripe/stripe-go/v72/form"
)
func TestSubscriptionParams_AppendTo(t *testing.T) {
{
params := &SubscriptionParams{BillingCycleAnchorNow: Bool(true)}
body := &form.Values{}
form.AppendTo(body, params)
t.Logf("body = %+v", body)
assert.Equal(t, []string{"now"}, body.Get("billing_cycle_anchor"))
}
{
params := &SubscriptionParams{BillingCycleAnchorUnchanged: Bool(true)}
body := &form.Values{}
form.AppendTo(body, params)
t.Logf("body = %+v", body)
assert.Equal(t, []string{"unchanged"}, body.Get("billing_cycle_anchor"))
}
{
params := &SubscriptionParams{TrialEndNow: Bool(true)}
body := &form.Values{}
form.AppendTo(body, params)
t.Logf("body = %+v", body)
assert.Equal(t, []string{"now"}, body.Get("trial_end"))
}
}
func TestSubscription_UnmarshalJSON(t *testing.T) {
// Unmarshals from a JSON string
{
var v Subscription
err := json.Unmarshal([]byte(`"sub_123"`), &v)
assert.NoError(t, err)
assert.Equal(t, "sub_123", v.ID)
}
// Unmarshals from a JSON object
{
v := Subscription{ID: "sub_123"}
data, err := json.Marshal(&v)
assert.NoError(t, err)
err = json.Unmarshal(data, &v)
assert.NoError(t, err)
assert.Equal(t, "sub_123", v.ID)
}
}