-
Notifications
You must be signed in to change notification settings - Fork 3
/
lob_test.go
194 lines (163 loc) · 5.02 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package lob
import (
"os"
"testing"
)
const testUserAgent = "Test/1.0"
var testAPIKey = os.Getenv("TEST_LOB_API_KEY")
var testAddress = &Address{
Name: nullString("Lobster Test"),
Email: nullString("[email protected]"),
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 TestAddresses(t *testing.T) {
lob := NewLob(BaseAPI, testAPIKey, testUserAgent)
verify, err := lob.VerifyUSAddress(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)
if err != nil {
t.Errorf("Could not list addresses: %s", err.Error())
}
t.Logf("Address list = %+v", addresses)
err = lob.DeleteAddress(address.ID)
if err != nil {
t.Errorf("Error deleting address: %s", err.Error())
}
}
func TestAddressError(t *testing.T) {
lob := NewLob(BaseAPI, testAPIKey, testUserAgent)
address, err := lob.CreateAddress(&Address{
Name: nullString("Name that is way too long to be printed on the check so that it will error."),
Email: nullString("[email protected]"),
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"),
})
if err == nil {
t.Error("error should not have been nil")
}
if address.Error.Message == "" {
t.Error("Expected human readable error message")
}
if address.Error.StatusCode != 422 {
t.Error("Expected status code to be 422")
}
}
func TestBankAccounts(t *testing.T) {
lob := NewLob(BaseAPI, testAPIKey, testUserAgent)
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",
AccountType: "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)
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())
}
err = lob.DeleteAddress(address.ID)
if err != nil {
t.Errorf("Error deleting address: %s", err.Error())
}
}
func TestChecks(t *testing.T) {
lob := NewLob(BaseAPI, testAPIKey, testUserAgent)
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",
AccountType: "company",
})
if err != nil {
t.Fatalf("Could not create bank account: %s", err.Error())
}
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)
if err != nil {
t.Errorf("Could not list checks: %s", err.Error())
}
t.Logf("List checks = %+v", resp)
err = lob.DeleteAddress(address.ID)
if err != nil {
t.Errorf("Error deleting address: %s", err.Error())
}
}
func TestGetStates(t *testing.T) {
lob := NewLob(BaseAPI, testAPIKey, testUserAgent)
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(BaseAPI, testAPIKey, testUserAgent)
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))
}
}