-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocessout_test.go
More file actions
200 lines (173 loc) · 4.72 KB
/
Copy pathprocessout_test.go
File metadata and controls
200 lines (173 loc) · 4.72 KB
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
195
196
197
198
199
200
package processout
import (
"bytes"
"net/http"
"testing"
)
func getClient() *ProcessOut {
return New("test-proj_gAO1Uu0ysZJvDuUpOGPkUBeE3pGalk3x",
"key_sandbox_mah31RDFqcDxmaS7MvhDbJfDJvjtsFTB")
}
func TestNew(t *testing.T) {
p := New("project-id", "project-secret")
if p.APIVersion != RequestAPIVersion {
t.Errorf("Wrong API version")
}
if p.projectID != "project-id" {
t.Errorf("Wrong project ID")
}
if p.projectSecret != "project-secret" {
t.Errorf("Wrong project secret")
}
}
func TestCreateFetchInvoice(t *testing.T) {
p := getClient()
iv, err := p.NewInvoice(&Invoice{
Name: String("test invoice"),
Amount: String("9.99"),
Currency: String("EUR"),
}).Create()
if err != nil {
t.Errorf("The invoice could not be created: %s", err.Error())
}
if iv.ID == nil || *iv.ID == "" {
t.Errorf("The created invoice ID was empty")
}
iv2, err := p.NewInvoice().Find(*iv.ID)
if err != nil {
t.Errorf("The invoice could not be fetched: %s", err.Error())
}
if *iv.ID != *iv2.ID {
t.Errorf("The invoice IDs did not match")
}
}
func TestCaptureInvoice(t *testing.T) {
t.Skip("Sandbox gateway does not support capturing invoices with gateway requests")
p := getClient()
iv, err := p.NewInvoice(&Invoice{
Name: String("test invoice"),
Amount: String("9.99"),
Currency: String("EUR"),
}).Create()
if err != nil {
t.Errorf("The invoice could not be created: %s", err.Error())
}
req, _ := http.NewRequest("POST", "https://processout.com?token=test-valid", bytes.NewReader([]byte(`{}`)))
req.Header.Set("Content-Type", "application/json")
gr := NewGatewayRequest("gway_conf_44ae90db0a62f819a404ef6a8ff994ca", req)
tr, _, _, err := iv.Capture(gr.String())
if err != nil {
t.Fatalf("The invoice should have been captured, but got: %s", err.Error())
}
if tr.Status == nil || *tr.Status != "completed" {
t.Errorf("The transaction should have been completed, but got: %v", tr.Status)
}
// Check the expand
tr, err = tr.Find(*tr.ID, TransactionFindParameters{
Options: &Options{
Expand: []string{"gateway_configuration"},
},
})
if err != nil {
t.Errorf("The invoice should have been captured, but got: %s", err.Error())
}
if tr.GatewayConfiguration == nil || tr.GatewayConfiguration.ID == nil || *tr.GatewayConfiguration.ID == "" {
t.Errorf("The transaction gateway configuration was expanded even though we expanded it")
}
}
func TestGetCustomers(t *testing.T) {
p := getClient()
_, err := p.NewCustomer().All()
if err != nil {
t.Errorf("The customers list could not be fetched: %s", err.Error())
}
}
func TestCreateCustomerPrefill(t *testing.T) {
p := getClient()
tmpl := &Customer{
Email: String("john@smith.com"),
}
cust, err := p.NewCustomer(tmpl).Create(CustomerCreateParameters{
Options: &Options{
Expand: []string{"project"},
},
})
if err != nil {
t.Errorf("The subscription could not be created: %s", err.Error())
}
if *cust.Email != *tmpl.Email {
t.Errorf("The email should be %s but was %s", *tmpl.Email, *cust.Email)
}
}
func TestCreateCustomerParameters(t *testing.T) {
p := getClient()
tmpl := &Customer{
Email: String("john@smith.com"),
}
cust, err := p.NewCustomer().Create(CustomerCreateParameters{
Options: &Options{
Expand: []string{"project"},
},
Customer: tmpl,
})
if err != nil {
t.Errorf("The subscription could not be created: %s", err.Error())
}
if *cust.Email != *tmpl.Email {
t.Errorf("The email should be %s but was %s", *tmpl.Email, *cust.Email)
}
}
func TestExpandCustomerProject(t *testing.T) {
p := getClient()
cust, _ := p.NewCustomer().Create(CustomerCreateParameters{
Options: &Options{
Expand: []string{"project"},
},
})
if cust.Project == nil {
t.Errorf("The customer project should be expanded")
}
}
func TestPaginateCustomersNext(t *testing.T) {
p := getClient()
custs, _ := p.NewCustomer().All(CustomerAllParameters{
Options: &Options{
Limit: 10,
},
})
seenIDs := []string{}
i := 0
for custs.Next() {
i++
cust := custs.Get().(*Customer)
for _, s := range seenIDs {
if s == *cust.ID {
t.Fatalf("the customer with ID %s was already found in last iteration", s)
}
}
seenIDs = append(seenIDs, *cust.ID)
if i > 11 {
break
}
}
if i < 11 {
t.Errorf("the iteration count should have been greater than 10")
}
if err := custs.Error(); err != nil {
t.Errorf("there shouldn't have been any error, but got %s", err.Error())
}
}
func TestPaginateCustomersPrev(t *testing.T) {
p := getClient()
custs, _ := p.NewCustomer().All(CustomerAllParameters{
Options: &Options{
Limit: 10,
},
})
for custs.Prev() {
t.Errorf("There shouldnt have been any iteration")
}
if err := custs.Error(); err != nil {
t.Errorf("There shouldn't have been any error, but got %s", err.Error())
}
}