forked from seedco/go-lob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlob_test.go
174 lines (145 loc) · 4.42 KB
/
lob_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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package lob
import (
"os"
"testing"
)
var testAPIKey = os.Getenv("TEST_LOB_API_KEY")
var testAddress = &Address{
Name: nullString("Lobster Test"),
Email: nullString("lobtest@example.com"),
Phone: nullString("5555555555"),
AddressLine1: "1005 W Burnside St", // Powell's City of Books, the best book store in the world.
AddressCity: nullString("Portland"),
AddressState: nullString("OR"),
AddressZip: nullString("97209"),
AddressCountry: nullString("US"),
}
func nullString(s string) *string {
return &s
}
func TestLobAPI(t *testing.T) {
lob := NewLob(testAPIKey)
verify, err := lob.VerifyAddress(testAddress)
if err != nil {
t.Errorf("Error verifying address: %s", err.Error())
}
t.Logf("Verification = %+v", verify)
address, err := lob.CreateAddress(testAddress)
if err != nil {
t.Fatalf("Could not create address: %s", err.Error())
}
address, err = lob.GetAddress(address.ID)
if err != nil {
t.Errorf("Could not get address: %s", err.Error())
}
addresses, err := lob.ListAddresses(-1, -1)
if err != nil {
t.Errorf("Could not list addresses: %s", err.Error())
}
t.Logf("Address list = %+v", addresses)
message, err := lob.DeleteAddress(address.ID)
t.Logf("Message from delete = %s", message)
if err != nil {
t.Errorf("Error deleting address: %s", err.Error())
}
}
func TestBankAccounts(t *testing.T) {
lob := NewLob(testAPIKey)
address, err := lob.CreateAddress(testAddress)
if err != nil {
t.Fatalf("Could not create address: %s", err.Error())
}
bankAccount, err := lob.CreateBankAccount(&CreateBankAccountRequest{
RoutingNumber: "255077370",
AccountNumber: "1234",
Signatory: "Lobster Test",
Type: "company",
})
if err != nil {
t.Fatalf("Could not create bank account: %s", err.Error())
}
t.Logf("Bank account = %+v", bankAccount)
bankAccount, err = lob.GetBankAccount(bankAccount.ID)
if err != nil {
t.Errorf("Error retrieving bank account")
}
t.Logf("Bank account = %+v", bankAccount)
resp, err := lob.ListBankAccounts(-1, -1)
if err != nil {
t.Errorf("Could not list bank accounts: %s", err.Error())
}
t.Logf("Bank accounts = %+v", resp)
if err != nil {
t.Fatalf("Could not create bank account: %s", err.Error())
}
message, err := lob.DeleteAddress(address.ID)
t.Logf("Message from delete = %s", message)
if err != nil {
t.Errorf("Error deleting address: %s", err.Error())
}
}
func TestChecks(t *testing.T) {
lob := NewLob(testAPIKey)
address, err := lob.CreateAddress(testAddress)
if err != nil {
t.Fatalf("Could not create address: %s", err.Error())
}
_, err = lob.CreateBankAccount(&CreateBankAccountRequest{
RoutingNumber: "255077370",
AccountNumber: "1234",
Signatory: "Lobster Test",
Type: "company",
})
if err != nil {
t.Fatalf("Could not create bank account: %s", err.Error())
}
// DISABLING CHECKS UNTIL VERIFICATION FIXED
// TODO: Enable verification of bank accounts - struggled with the array of 'amounts' on that endpoint
// check, err := lob.CreateCheck(&CreateCheckRequest{
// CheckNumber: nullString("12345"),
// BankAccountID: bankAccount.ID,
// FromAddressID: address.ID,
// ToAddressID: address.ID,
// Amount: 987.65,
// Message: nullString("Some message"),
// Memo: nullString("A memo"),
// })
// if err != nil {
// t.Fatalf("Could not create check: %s", err.Error())
// }
// t.Logf("Check = %+v", check)
// _, err = lob.GetCheck(check.ID)
// if err != nil {
// t.Errorf("Could not get check: %s", err.Error())
// }
// resp, err := lob.ListChecks(-1, -1)
// if err != nil {
// t.Errorf("Could not list checks: %s", err.Error())
// }
// t.Logf("List checks = %+v", resp)
message, err := lob.DeleteAddress(address.ID)
t.Logf("Message from delete = %s", message)
if err != nil {
t.Errorf("Error deleting address: %s", err.Error())
}
}
func TestGetStates(t *testing.T) {
lob := NewLob(testAPIKey)
list, err := lob.GetStates()
if err != nil {
t.Fatalf("Error retrieving state list: %s", err.Error())
}
if len(list.Data) < 50 || len(list.Data) > 80 {
t.Errorf("Expected at least 50 US states, got %d", len(list.Data))
}
}
func TestGetCountries(t *testing.T) {
lob := NewLob(testAPIKey)
list, err := lob.GetCountries()
if err != nil {
t.Fatalf("Error retrieving countries list: %s", err.Error())
}
if len(list.Data) < 200 || len(list.Data) > 400 {
t.Errorf("Expected at least 200 countries, got %d", len(list.Data))
}
}