-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransactions_test.go
More file actions
223 lines (188 loc) · 5.74 KB
/
Copy pathtransactions_test.go
File metadata and controls
223 lines (188 loc) · 5.74 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
package goqonto
import (
"fmt"
"net/http"
"reflect"
"testing"
"time"
)
var (
transactionFixture = `{
"id": "6ea8271c-87b1-49d0-a66f-1e29a2fe43ba",
"transaction_id": "mycompany-bank-account-1-transaction-491",
"amount": 126.0,
"amount_cents": 12600,
"attachment_ids": [],
"local_amount": 126.0,
"local_amount_cents": 12600,
"side": "debit",
"operation_type": "transfer",
"currency": "EUR",
"local_currency": "EUR",
"label": "Qonto",
"settled_at": "2019-05-29T05:28:00.191Z",
"emitted_at": "2019-05-29T05:27:51.353Z",
"updated_at": "2019-05-29T05:29:38.068Z",
"status": "completed",
"note": "Memo added by the user on the transaction",
"reference": "Message sent along income, transfer and direct_debit transactions",
"vat_amount": 21.0,
"vat_amount_cents": 2100,
"vat_rate": 20.0,
"initiator_id": "ID of the membership who initiated the transaction",
"label_ids": [
"f4c39147-9c1f-43b0-4720-bd6ef6ac372d",
"dee2cfdb-8147-444c-9b8d-5c0aa25b8dd9"
],
"attachment_lost": false,
"attachment_required": true
}`
metaFixture = `"meta": {
"current_page": 2,
"next_page": 3,
"prev_page": 1,
"total_pages": 3,
"total_count": 30,
"per_page": 10
}`
listTransactionsFixture = fmt.Sprintf(`{
"transactions": [ %s ],
%s
}`, transactionFixture, metaFixture)
getTransactionFixture = fmt.Sprintf(`{
"transaction": %s
}`, transactionFixture)
trx1SettledAt, _ = time.Parse(time.RFC3339, "2019-05-29T05:28:00.191Z")
trx1EmittedAt, _ = time.Parse(time.RFC3339, "2019-05-29T05:27:51.353Z")
trx1UpdatedAt, _ = time.Parse(time.RFC3339, "2019-05-29T05:29:38.068Z")
trx1 = Transaction{
ID: "6ea8271c-87b1-49d0-a66f-1e29a2fe43ba",
TransactionID: "mycompany-bank-account-1-transaction-491",
Amount: 126.0,
AmountCents: 12600,
AttachmentIds: []string{},
LocalAmount: 126.0,
LocalAmountCents: 12600,
Side: "debit",
OperationType: "transfer",
Currency: "EUR",
LocalCurrency: "EUR",
Label: "Qonto",
SettledAt: trx1SettledAt,
EmittedAt: trx1EmittedAt,
UpdatedAt: trx1UpdatedAt,
Status: "completed",
Note: "Memo added by the user on the transaction",
Reference: "Message sent along income, transfer and direct_debit transactions",
VatAmount: 21.0,
VatAmountCents: 2100,
VatRate: 20.0,
InitiatorID: "ID of the membership who initiated the transaction",
LabelIds: []string{
"f4c39147-9c1f-43b0-4720-bd6ef6ac372d",
"dee2cfdb-8147-444c-9b8d-5c0aa25b8dd9",
},
AttachmentLost: false,
AttachmentRequired: true,
}
transactions = transactionsRoot{
Transactions: []Transaction{trx1},
}
)
func TestTransaction_marshall(t *testing.T) {
testJSONMarshal(t, &Transaction{}, "{}")
testJSONMarshal(t, &trx1, transactionFixture)
}
func TestTransactionsService_List(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/%s", transactionsBasePath), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testHeader(t, r, "Accept", mediaType)
testHeader(t, r, "Content-Type", mediaType)
testBody(t, r, `{"slug":"mycompany-9134","iban":"FR761679800001000000123456"}`+"\n")
fmt.Fprint(w, listTransactionsFixture)
})
params := &TransactionsOptions{
Slug: "mycompany-9134",
IBAN: "FR761679800001000000123456",
}
got, resp, err := client.Transactions.List(ctx, params)
if err != nil {
t.Errorf("Transactions.List returned error: %v", err)
}
want := transactions.Transactions
if !reflect.DeepEqual(got, want) {
t.Errorf("Transactions.List \n got %v\n want %v\n", got, want)
}
testResponseMeta(t, resp.Meta, &ResponseMeta{
CurrentPage: 2,
NextPage: 3,
PrevPage: 1,
TotalPages: 3,
TotalCount: 30,
PerPage: 10,
})
}
func TestTransactionsService_List_Error(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testHeader(t, r, "Accept", mediaType)
testHeader(t, r, "Content-Type", mediaType)
w.WriteHeader(http.StatusNotFound)
fmt.Fprint(w, `{ "message": "Not found" }`)
})
got, resp, err := client.Transactions.List(ctx, &TransactionsOptions{})
if err.Error() == "" {
t.Errorf("Expected non-empty err.Error()")
}
if resp.StatusCode != http.StatusNotFound {
t.Errorf("Expected 404 Status")
}
if got != nil {
t.Errorf("Expected empty body")
}
}
func TestTransactionsService_Get(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc(
fmt.Sprintf("/%s/6ea8271c-87b1-49d0-a66f-1e29a2fe43ba", transactionsBasePath),
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testHeader(t, r, "Accept", mediaType)
testHeader(t, r, "Content-Type", mediaType)
fmt.Fprint(w, getTransactionFixture)
})
got, _, err := client.Transactions.Get(ctx, "6ea8271c-87b1-49d0-a66f-1e29a2fe43ba")
if err != nil {
t.Errorf("Transactions.Get returned error: %v", err)
}
want := &trx1
if !reflect.DeepEqual(got, want) {
t.Errorf("Transactions.Get \n got %v\n want %v\n", got, want)
}
}
func TestTransactionsService_Get_Error(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testHeader(t, r, "Accept", mediaType)
testHeader(t, r, "Content-Type", mediaType)
w.WriteHeader(http.StatusNotFound)
fmt.Fprint(w, `{ "message": "Not found" }`)
})
got, resp, err := client.Transactions.Get(ctx, "6ea8271c-87b1-49d0-a66f-1e29a2fe43ba")
if err.Error() == "" {
t.Errorf("Expected non-empty err.Error()")
}
if resp.StatusCode != http.StatusNotFound {
t.Errorf("Expected 404 Status")
}
if got != nil {
t.Errorf("Expected empty body")
}
}