forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bankaccount_test.go
105 lines (92 loc) · 2.83 KB
/
bankaccount_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
package stripe
import (
"encoding/json"
"testing"
assert "github.com/stretchr/testify/require"
"github.com/stripe/stripe-go/v72/form"
)
func TestBankAccount_UnmarshalJSON(t *testing.T) {
// Unmarshals from a JSON string
{
var v BankAccount
err := json.Unmarshal([]byte(`"ba_123"`), &v)
assert.NoError(t, err)
assert.Equal(t, "ba_123", v.ID)
}
// Unmarshals from a JSON object
{
v := BankAccount{ID: "ba_123"}
data, err := json.Marshal(&v)
assert.NoError(t, err)
err = json.Unmarshal(data, &v)
assert.NoError(t, err)
assert.Equal(t, "ba_123", v.ID)
}
}
func TestBankAccountListParams_AppendTo(t *testing.T) {
// Adds `object` for account (this will hit the customer sources endpoint)
{
params := &BankAccountListParams{Account: String("acct_123")}
body := &form.Values{}
form.AppendTo(body, params)
t.Logf("body = %+v", body)
assert.Equal(t, []string{"bank_account"}, body.Get("object"))
}
// Adds `object` for customer (this will hit the external accounts endpoint)
{
params := &BankAccountListParams{Customer: String("cus_123")}
body := &form.Values{}
form.AppendTo(body, params)
t.Logf("body = %+v", body)
assert.Equal(t, []string{"bank_account"}, body.Get("object"))
}
}
func TestBankAccountParams_AppendToAsSourceOrExternalAccount(t *testing.T) {
// We should add more tests for all the various corner cases here ...
// Includes account_holder_name
{
params := &BankAccountParams{AccountHolderName: String("Tyrion")}
body := &form.Values{}
params.AppendToAsSourceOrExternalAccount(body)
t.Logf("body = %+v", body)
assert.Equal(t, []string{"Tyrion"}, body.Get("external_account[account_holder_name]"))
}
// Does not include account_holder_name if empty
{
params := &BankAccountParams{}
body := &form.Values{}
params.AppendToAsSourceOrExternalAccount(body)
t.Logf("body = %+v", body)
assert.Equal(t, []string(nil), body.Get("external_account[account_holder_name]"))
}
// Includes account_holder_name
{
params := &BankAccountParams{AccountHolderType: String(string(BankAccountAccountHolderTypeIndividual))}
body := &form.Values{}
params.AppendToAsSourceOrExternalAccount(body)
t.Logf("body = %+v", body)
assert.Equal(t, []string{"individual"}, body.Get("external_account[account_holder_type]"))
}
// Includes Params
{
params := &BankAccountParams{
Params: Params{
Metadata: map[string]string{
"foo": "bar",
},
},
}
body := &form.Values{}
params.AppendToAsSourceOrExternalAccount(body)
t.Logf("body = %+v", body)
assert.Equal(t, []string{"bar"}, body.Get("metadata[foo]"))
}
// Does not include account_holder_name if empty
{
params := &BankAccountParams{}
body := &form.Values{}
params.AppendToAsSourceOrExternalAccount(body)
t.Logf("body = %+v", body)
assert.Equal(t, []string(nil), body.Get("external_account[account_holder_type]"))
}
}