-
Notifications
You must be signed in to change notification settings - Fork 462
/
account_test.go
77 lines (65 loc) · 1.91 KB
/
account_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
package stripe
import (
"encoding/json"
"testing"
assert "github.com/stretchr/testify/require"
"github.com/stripe/stripe-go/form"
)
func TestAccountExternalAccountParams_AppendTo(t *testing.T) {
{
params := &AccountExternalAccountParams{}
body := &form.Values{}
form.AppendTo(body, params)
t.Logf("body = %+v", body)
assert.Equal(t, []string{"bank_account"}, body.Get("object"))
}
{
params := &AccountExternalAccountParams{Token: String("tok_123")}
body := &form.Values{}
// 0-length keyParts are not allowed, so call AppendTo directly (as
// opposed to through the form package) and inject a realistic set
params.AppendTo(body, []string{"external_account"})
t.Logf("body = %+v", body)
assert.Equal(t, []string{"tok_123"}, body.Get("external_account"))
}
}
func TestAccountUnmarshal(t *testing.T) {
accountData := map[string]interface{}{
"id": "acct_123",
"external_accounts": map[string]interface{}{
"object": "list",
"has_more": true,
"data": []map[string]interface{}{
{
"object": "bank_account",
"id": "ba_123",
},
{
"object": "card",
"id": "card_123",
},
},
},
"type": "custom",
}
bytes, err := json.Marshal(&accountData)
assert.NoError(t, err)
var account Account
err = json.Unmarshal(bytes, &account)
assert.NoError(t, err)
assert.Equal(t, AccountTypeCustom, account.Type)
assert.Equal(t, "acct_123", account.ID)
assert.Equal(t, true, account.ExternalAccounts.HasMore)
assert.Equal(t, 2, len(account.ExternalAccounts.Data))
assert.Equal(t, "ba_123", account.ExternalAccounts.Data[0].ID)
assert.Equal(t, "card_123", account.ExternalAccounts.Data[1].ID)
}
func TestPayoutScheduleParams_AppendTo(t *testing.T) {
{
params := &PayoutScheduleParams{DelayDaysMinimum: Bool(true)}
body := &form.Values{}
form.AppendTo(body, params)
t.Logf("body = %+v", body)
assert.Equal(t, []string{"minimum"}, body.Get("delay_days"))
}
}