forked from stripe/stripe-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount_test.go
103 lines (87 loc) · 2.5 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
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
package stripe
import (
"encoding/json"
"testing"
)
func TestAccountUnmarshal(t *testing.T) {
accountData := map[string]interface{}{
"id": "acct_1234",
"external_accounts": map[string]interface{}{
"object": "list",
"has_more": true,
"data": []map[string]interface{}{
{
"object": "bank_account",
"id": "ba_1234",
},
{
"object": "card",
"id": "card_1234",
},
},
},
}
bytes, err := json.Marshal(&accountData)
if err != nil {
t.Error(err)
}
var account Account
err = json.Unmarshal(bytes, &account)
if err != nil {
t.Error(err)
}
if account.ID != "acct_1234" {
t.Errorf("Problem deserializing account, got ID %v", account.ID)
}
if !account.ExternalAccounts.More {
t.Errorf("Problem deserializing account, wrong value for list More")
}
if len(account.ExternalAccounts.Values) != 2 {
t.Errorf("Problem deserializing account, got wrong number of external accounts")
}
bankAccount := account.ExternalAccounts.Values[0]
if bankAccount == nil {
t.Errorf("Problem deserializing account, didn't get a bank account")
}
if "ba_1234" != bankAccount.ID {
t.Errorf("Problem deserializing account, got bank account ID %v", bankAccount.ID)
}
card := account.ExternalAccounts.Values[1]
if card == nil {
t.Errorf("Problem deserializing account, didn't get a card")
}
if "card_1234" != card.ID {
t.Errorf("Problem deserializing account, got card ID %v", card.ID)
}
}
func TestAddressAppendDetails(t *testing.T) {
actual := &RequestValues{}
expected := &RequestValues{}
address := &Address{}
address.AppendDetails(actual, "test_address")
// First test the empty case. All empty fields should be respected while
// encoding.
if expected.Encode() != actual.Encode() {
t.Errorf("Problem encoding address, got: %v", actual.Encode())
}
address = &Address{
Line1: "test_line1",
Line2: "test_line2",
City: "test_city",
State: "test_state",
Zip: "test_zip",
Country: "test_country",
Town: "test_town",
}
address.AppendDetails(actual, "test_address")
expected.Add("test_address[line1]", "test_line1")
expected.Add("test_address[line2]", "test_line2")
expected.Add("test_address[city]", "test_city")
expected.Add("test_address[state]", "test_state")
expected.Add("test_address[postal_code]", "test_zip")
expected.Add("test_address[country]", "test_country")
expected.Add("test_address[town]", "test_town")
if expected.Encode() != actual.Encode() {
t.Errorf("Problem encoding address, got: %v", actual.Encode())
}
}