-
Notifications
You must be signed in to change notification settings - Fork 463
/
Copy pathtransfer_test.go
54 lines (45 loc) · 1.14 KB
/
transfer_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
package stripe
import (
"encoding/json"
"testing"
assert "github.com/stretchr/testify/require"
)
func TestTransfer_UnmarshalJSON(t *testing.T) {
// Unmarshals from a JSON string
{
var v Transfer
err := json.Unmarshal([]byte(`"tr_123"`), &v)
assert.NoError(t, err)
assert.Equal(t, "tr_123", v.ID)
}
// Unmarshals from a JSON object
{
v := Transfer{ID: "tr_123"}
data, err := json.Marshal(&v)
assert.NoError(t, err)
err = json.Unmarshal(data, &v)
assert.NoError(t, err)
assert.Equal(t, "tr_123", v.ID)
}
}
func TestTransferDestination_UnmarshalJSON(t *testing.T) {
// Unmarshals from a JSON string
{
var v TransferDestination
err := json.Unmarshal([]byte(`"acct_123"`), &v)
assert.NoError(t, err)
assert.Equal(t, "acct_123", v.ID)
}
// Unmarshals from a JSON object
{
v := TransferDestination{ID: "acct_123"}
data, err := json.Marshal(&v)
assert.NoError(t, err)
err = json.Unmarshal(data, &v)
assert.NoError(t, err)
assert.Equal(t, "acct_123", v.ID)
// The child Account field should also be expanded. For legacy reasons
// it's a different object.
assert.Equal(t, "acct_123", v.Account.ID)
}
}