1
|
|
|
package mobilenig |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"context" |
5
|
|
|
"errors" |
6
|
|
|
"net/http" |
7
|
|
|
"net/url" |
8
|
|
|
"strconv" |
9
|
|
|
"testing" |
10
|
|
|
"time" |
11
|
|
|
|
12
|
|
|
"github.com/NdoleStudio/mobilenig-go/internal/helpers" |
13
|
|
|
"github.com/NdoleStudio/mobilenig-go/internal/stubs" |
14
|
|
|
"github.com/stretchr/testify/assert" |
15
|
|
|
) |
16
|
|
|
|
17
|
|
|
const ( |
18
|
|
|
testUsername = "test_username" |
19
|
|
|
testAPIKey = "test_api_key" |
20
|
|
|
) |
21
|
|
|
|
22
|
|
|
func TestBillsService_CheckDStvUser_ResponseConstructedCorrectly(t *testing.T) { |
23
|
|
|
// Setup |
24
|
|
|
t.Parallel() |
25
|
|
|
server := helpers.MakeTestServer(http.StatusOK, stubs.CheckDstvUserResponse()) |
26
|
|
|
|
27
|
|
|
// Arrange |
28
|
|
|
baseURL, _ := url.Parse(server.URL) |
29
|
|
|
client := New(WithBaseURL(baseURL)) |
30
|
|
|
date, _ := time.Parse("2006-01-02T15:04:05-07:00", "2018-11-13T00:00:00+01:00") |
31
|
|
|
|
32
|
|
|
// Act |
33
|
|
|
user, _, err := client.Bills.CheckDStvUser(context.Background(), "4131953321") |
34
|
|
|
|
35
|
|
|
// Assert |
36
|
|
|
assert.NoError(t, err) |
37
|
|
|
|
38
|
|
|
assert.Equal(t, "OPEN", user.Details.AccountStatus) |
39
|
|
|
assert.Equal(t, "ESU", user.Details.Firstname) |
40
|
|
|
assert.Equal(t, "INI OBONG BASSEY", user.Details.Lastname) |
41
|
|
|
assert.Equal(t, "SUD", user.Details.CustomerType) |
42
|
|
|
assert.Equal(t, 1, user.Details.InvoicePeriod) |
43
|
|
|
assert.Equal(t, date, user.Details.DueDate) |
44
|
|
|
assert.Equal(t, int64(275953782), user.Details.CustomerNumber) |
45
|
|
|
|
46
|
|
|
// Teardown |
47
|
|
|
server.Close() |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
func TestBillsService_CheckDStvUser_RequestConstructedCorrectly(t *testing.T) { |
51
|
|
|
// Setup |
52
|
|
|
t.Parallel() |
53
|
|
|
|
54
|
|
|
environments := []Environment{LiveEnvironment, TestEnvironment} |
55
|
|
|
for _, environment := range environments { |
56
|
|
|
t.Run(environment.String(), func(t *testing.T) { |
57
|
|
|
// Setup |
58
|
|
|
t.Parallel() |
59
|
|
|
|
60
|
|
|
// Arrange |
61
|
|
|
request := new(http.Request) |
62
|
|
|
server := helpers.MakeRequestCapturingTestServer(http.StatusOK, stubs.CheckDstvUserResponse(), request) |
63
|
|
|
|
64
|
|
|
baseURL, _ := url.Parse(server.URL) |
65
|
|
|
username := testUsername |
66
|
|
|
apiKey := testAPIKey |
67
|
|
|
smartcardNumber := "4131953321" |
68
|
|
|
|
69
|
|
|
client := New(WithBaseURL(baseURL), WithAPIKey(apiKey), WithUsername(username), WithEnvironment(environment)) |
70
|
|
|
|
71
|
|
|
// Act |
72
|
|
|
_, _, _ = client.Bills.CheckDStvUser(context.Background(), smartcardNumber) |
73
|
|
|
|
74
|
|
|
// Assert |
75
|
|
|
assert.Equal(t, "/bills/user_check", request.URL.Path) |
76
|
|
|
assert.Equal(t, username, request.URL.Query().Get("username")) |
77
|
|
|
assert.Equal(t, apiKey, request.URL.Query().Get("api_key")) |
78
|
|
|
assert.Equal(t, "DSTV", request.URL.Query().Get("service")) |
79
|
|
|
assert.Equal(t, smartcardNumber, request.URL.Query().Get("number")) |
80
|
|
|
|
81
|
|
|
// Teardown |
82
|
|
|
server.Close() |
83
|
|
|
}) |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
func TestBillsService_CheckDStvUser_ErrorResponseConstructedCorrectly(t *testing.T) { |
88
|
|
|
t.Parallel() |
89
|
|
|
|
90
|
|
|
environments := []Environment{LiveEnvironment, TestEnvironment} |
91
|
|
|
for _, environment := range environments { |
92
|
|
|
t.Run(environment.String(), func(t *testing.T) { |
93
|
|
|
// Setup |
94
|
|
|
t.Parallel() |
95
|
|
|
|
96
|
|
|
// Arrange |
97
|
|
|
server := helpers.MakeTestServer(http.StatusOK, stubs.ErrorResponse()) |
98
|
|
|
baseURL, _ := url.Parse(server.URL) |
99
|
|
|
smartcardNumber := "4131953321" |
100
|
|
|
|
101
|
|
|
client := New(WithBaseURL(baseURL), WithEnvironment(environment)) |
102
|
|
|
|
103
|
|
|
// Act |
104
|
|
|
_, resp, err := client.Bills.CheckDStvUser(context.Background(), smartcardNumber) |
105
|
|
|
|
106
|
|
|
// Assert |
107
|
|
|
assert.Error(t, err) |
108
|
|
|
|
109
|
|
|
assert.Equal(t, "ERR101", resp.Error.Code) |
110
|
|
|
assert.Equal(t, "Invalid username or api_key", resp.Error.Description) |
111
|
|
|
|
112
|
|
|
// Teardown |
113
|
|
|
server.Close() |
114
|
|
|
}) |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
func TestBillsService_CheckDStvUser_CancelledContext(t *testing.T) { |
119
|
|
|
t.Parallel() |
120
|
|
|
|
121
|
|
|
environments := []Environment{LiveEnvironment, TestEnvironment} |
122
|
|
|
for _, environment := range environments { |
123
|
|
|
t.Run(environment.String(), func(t *testing.T) { |
124
|
|
|
t.Parallel() |
125
|
|
|
|
126
|
|
|
// Arrange |
127
|
|
|
server := helpers.MakeTestServer(http.StatusOK, stubs.CheckDstvUserResponse()) |
128
|
|
|
baseURL, _ := url.Parse(server.URL) |
129
|
|
|
client := New(WithBaseURL(baseURL), WithEnvironment(environment)) |
130
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
131
|
|
|
cancel() |
132
|
|
|
|
133
|
|
|
// Act |
134
|
|
|
_, _, err := client.Bills.CheckDStvUser(ctx, "") |
135
|
|
|
|
136
|
|
|
// Assert |
137
|
|
|
assert.True(t, errors.Is(err, context.Canceled)) |
138
|
|
|
server.Close() |
139
|
|
|
}) |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
func TestBillsService_CheckDStvUser_InvalidResponse(t *testing.T) { |
144
|
|
|
t.Parallel() |
145
|
|
|
environments := []Environment{LiveEnvironment, TestEnvironment} |
146
|
|
|
for _, environment := range environments { |
147
|
|
|
t.Run(environment.String(), func(t *testing.T) { |
148
|
|
|
t.Parallel() |
149
|
|
|
|
150
|
|
|
// Arrange |
151
|
|
|
server := helpers.MakeTestServer(http.StatusOK, "<not-a-json></not-a-json>") |
152
|
|
|
baseURL, _ := url.Parse(server.URL) |
153
|
|
|
client := New(WithBaseURL(baseURL), WithEnvironment(environment)) |
154
|
|
|
|
155
|
|
|
// Act |
156
|
|
|
_, _, err := client.Bills.CheckDStvUser(context.Background(), "") |
157
|
|
|
|
158
|
|
|
// Assert |
159
|
|
|
assert.Error(t, err) |
160
|
|
|
|
161
|
|
|
// Teardown |
162
|
|
|
server.Close() |
163
|
|
|
}) |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
func TestBillsService_PayDStv_ResponseConstructedCorrectly(t *testing.T) { |
168
|
|
|
t.Parallel() |
169
|
|
|
|
170
|
|
|
// Arrange |
171
|
|
|
server := helpers.MakeTestServer(http.StatusOK, stubs.PayDstvBillResponse()) |
172
|
|
|
baseURL, _ := url.Parse(server.URL) |
173
|
|
|
client := New(WithBaseURL(baseURL)) |
174
|
|
|
|
175
|
|
|
// Act |
176
|
|
|
transaction, _, err := client.Bills.PayDStv(context.Background(), &PayDstvOptions{}) |
177
|
|
|
|
178
|
|
|
// Assert |
179
|
|
|
assert.NoError(t, err) |
180
|
|
|
|
181
|
|
|
assert.Equal(t, "122790223", transaction.TransactionID) |
182
|
|
|
assert.Equal(t, "DSTV", transaction.Details.Service) |
183
|
|
|
assert.Equal(t, "DStv Mobile MAXI", transaction.Details.Package) |
184
|
|
|
assert.Equal(t, "4131953321", transaction.Details.SmartcardNumber) |
185
|
|
|
assert.Equal(t, "790", transaction.Details.Price) |
186
|
|
|
assert.Equal(t, "SUCCESSFUL", transaction.Details.Status) |
187
|
|
|
assert.Equal(t, "7931", transaction.Details.Balance) |
188
|
|
|
|
189
|
|
|
// Teardown |
190
|
|
|
server.Close() |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
func TestBillsService_PayDStv_RequestConstructedCorrectly(t *testing.T) { |
194
|
|
|
t.Parallel() |
195
|
|
|
|
196
|
|
|
environments := []Environment{LiveEnvironment, TestEnvironment} |
197
|
|
|
for _, environment := range environments { |
198
|
|
|
t.Run(environment.String(), func(t *testing.T) { |
199
|
|
|
// Arrange |
200
|
|
|
request := new(http.Request) |
201
|
|
|
server := helpers.MakeRequestCapturingTestServer(http.StatusOK, stubs.CheckDstvUserResponse(), request) |
202
|
|
|
|
203
|
|
|
baseURL, _ := url.Parse(server.URL) |
204
|
|
|
username := testUsername |
205
|
|
|
apiKey := testAPIKey |
206
|
|
|
smartcardNumber := "4131953321" |
207
|
|
|
customerNumber := "275953782" |
208
|
|
|
customerName := "ESU INI OBONG BASSEY" |
209
|
|
|
price := "790" |
210
|
|
|
transactionID := "122790223" |
211
|
|
|
|
212
|
|
|
client := New(WithBaseURL(baseURL), WithAPIKey(apiKey), WithUsername(username), WithEnvironment(environment)) |
213
|
|
|
|
214
|
|
|
// Act |
215
|
|
|
_, _, _ = client.Bills.PayDStv(context.Background(), &PayDstvOptions{ |
216
|
|
|
TransactionID: transactionID, |
217
|
|
|
Price: price, |
218
|
|
|
ProductCode: DstvProductCodePremium, |
219
|
|
|
CustomerName: customerName, |
220
|
|
|
CustomerNumber: customerNumber, |
221
|
|
|
SmartcardNumber: smartcardNumber, |
222
|
|
|
}) |
223
|
|
|
|
224
|
|
|
// Assert |
225
|
|
|
uri := "/bills/dstv" |
226
|
|
|
if environment == TestEnvironment { |
227
|
|
|
uri += "_test" |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
assert.Equal(t, uri, request.URL.Path) |
231
|
|
|
assert.Equal(t, username, request.URL.Query().Get("username")) |
232
|
|
|
assert.Equal(t, apiKey, request.URL.Query().Get("api_key")) |
233
|
|
|
assert.Equal(t, smartcardNumber, request.URL.Query().Get("smartno")) |
234
|
|
|
assert.Equal(t, string(DstvProductCodePremium), request.URL.Query().Get("product_code")) |
235
|
|
|
assert.Equal(t, customerName, request.URL.Query().Get("customer_name")) |
236
|
|
|
assert.Equal(t, customerNumber, request.URL.Query().Get("customer_number")) |
237
|
|
|
assert.Equal(t, price, request.URL.Query().Get("price")) |
238
|
|
|
assert.Equal(t, transactionID, request.URL.Query().Get("trans_id")) |
239
|
|
|
|
240
|
|
|
// Teardown |
241
|
|
|
server.Close() |
242
|
|
|
}) |
243
|
|
|
} |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
func TestBillsService_PayDStv_ErrorResponseConstructedCorrectly(t *testing.T) { |
247
|
|
|
t.Parallel() |
248
|
|
|
|
249
|
|
|
environments := []Environment{LiveEnvironment, TestEnvironment} |
250
|
|
|
for _, environment := range environments { |
251
|
|
|
t.Run(environment.String(), func(t *testing.T) { |
252
|
|
|
// Arrange |
253
|
|
|
server := helpers.MakeTestServer(http.StatusOK, stubs.ErrorResponse()) |
254
|
|
|
baseURL, _ := url.Parse(server.URL) |
255
|
|
|
|
256
|
|
|
client := New(WithBaseURL(baseURL), WithEnvironment(environment)) |
257
|
|
|
|
258
|
|
|
// Act |
259
|
|
|
_, resp, err := client.Bills.PayDStv(context.Background(), &PayDstvOptions{}) |
260
|
|
|
|
261
|
|
|
// Assert |
262
|
|
|
assert.Error(t, err) |
263
|
|
|
|
264
|
|
|
assert.Equal(t, "ERR101", resp.Error.Code) |
265
|
|
|
assert.Equal(t, "Invalid username or api_key", resp.Error.Description) |
266
|
|
|
|
267
|
|
|
server.Close() |
268
|
|
|
}) |
269
|
|
|
} |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
func TestBillsService_PayDStv_CancelledContext(t *testing.T) { |
273
|
|
|
t.Parallel() |
274
|
|
|
|
275
|
|
|
environments := []Environment{LiveEnvironment, TestEnvironment} |
276
|
|
|
for _, environment := range environments { |
277
|
|
|
t.Run(environment.String(), func(t *testing.T) { |
278
|
|
|
// Arrange |
279
|
|
|
server := helpers.MakeTestServer(http.StatusOK, stubs.CheckDstvUserResponse()) |
280
|
|
|
baseURL, _ := url.Parse(server.URL) |
281
|
|
|
client := New(WithBaseURL(baseURL), WithEnvironment(environment)) |
282
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
283
|
|
|
cancel() |
284
|
|
|
|
285
|
|
|
// Act |
286
|
|
|
_, _, err := client.Bills.PayDStv(ctx, &PayDstvOptions{}) |
287
|
|
|
|
288
|
|
|
// Assert |
289
|
|
|
assert.True(t, errors.Is(err, context.Canceled)) |
290
|
|
|
|
291
|
|
|
// Teardown |
292
|
|
|
server.Close() |
293
|
|
|
}) |
294
|
|
|
} |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
func TestBillsService_PayDStv_InvalidResponse(t *testing.T) { |
298
|
|
|
t.Parallel() |
299
|
|
|
|
300
|
|
|
environments := []Environment{LiveEnvironment, TestEnvironment} |
301
|
|
|
for _, environment := range environments { |
302
|
|
|
t.Run(environment.String(), func(t *testing.T) { |
303
|
|
|
t.Parallel() |
304
|
|
|
|
305
|
|
|
// Arrange |
306
|
|
|
server := helpers.MakeTestServer(http.StatusOK, "<not-a-json></not-a-json>") |
307
|
|
|
baseURL, _ := url.Parse(server.URL) |
308
|
|
|
client := New(WithBaseURL(baseURL), WithEnvironment(environment)) |
309
|
|
|
|
310
|
|
|
// Act |
311
|
|
|
_, _, err := client.Bills.PayDStv(context.Background(), &PayDstvOptions{}) |
312
|
|
|
|
313
|
|
|
// Assert |
314
|
|
|
assert.Error(t, err) |
315
|
|
|
|
316
|
|
|
// Teardown |
317
|
|
|
server.Close() |
318
|
|
|
}) |
319
|
|
|
} |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
func TestBillsService_PayDStv_NilOptions(t *testing.T) { |
323
|
|
|
t.Parallel() |
324
|
|
|
|
325
|
|
|
environments := []Environment{LiveEnvironment, TestEnvironment} |
326
|
|
|
for _, environment := range environments { |
327
|
|
|
t.Run(environment.String(), func(t *testing.T) { |
328
|
|
|
// Arrange |
329
|
|
|
server := helpers.MakeTestServer(http.StatusOK, stubs.CheckDstvUserResponse()) |
330
|
|
|
baseURL, _ := url.Parse(server.URL) |
331
|
|
|
client := New(WithBaseURL(baseURL), WithEnvironment(environment)) |
332
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
333
|
|
|
cancel() |
334
|
|
|
|
335
|
|
|
// Act |
336
|
|
|
_, _, err := client.Bills.PayDStv(ctx, nil) |
337
|
|
|
|
338
|
|
|
// Assert |
339
|
|
|
assert.Error(t, err) |
340
|
|
|
|
341
|
|
|
// Teardown |
342
|
|
|
server.Close() |
343
|
|
|
}) |
344
|
|
|
} |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
func TestBillsService_QueryDStv_ResponseConstructedCorrectly(t *testing.T) { |
348
|
|
|
t.Parallel() |
349
|
|
|
|
350
|
|
|
// Arrange |
351
|
|
|
server := helpers.MakeTestServer(http.StatusOK, stubs.PayDstvBillResponse()) |
352
|
|
|
baseURL, _ := url.Parse(server.URL) |
353
|
|
|
client := New(WithBaseURL(baseURL)) |
354
|
|
|
|
355
|
|
|
// Act |
356
|
|
|
transaction, _, err := client.Bills.QueryDStv(context.Background(), "122790223") |
357
|
|
|
|
358
|
|
|
// Assert |
359
|
|
|
assert.NoError(t, err) |
360
|
|
|
|
361
|
|
|
assert.Equal(t, "122790223", transaction.TransactionID) |
362
|
|
|
assert.Equal(t, "DSTV", transaction.Details.Service) |
363
|
|
|
assert.Equal(t, "DStv Mobile MAXI", transaction.Details.Package) |
364
|
|
|
assert.Equal(t, "4131953321", transaction.Details.SmartcardNumber) |
365
|
|
|
assert.Equal(t, "790", transaction.Details.Price) |
366
|
|
|
assert.Equal(t, "SUCCESSFUL", transaction.Details.Status) |
367
|
|
|
assert.Equal(t, "7931", transaction.Details.Balance) |
368
|
|
|
|
369
|
|
|
// Teardown |
370
|
|
|
server.Close() |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
func TestBillsService_QueryDStv_RequestConstructedCorrectly(t *testing.T) { |
374
|
|
|
t.Parallel() |
375
|
|
|
|
376
|
|
|
environments := []Environment{LiveEnvironment, TestEnvironment} |
377
|
|
|
for _, environment := range environments { |
378
|
|
|
t.Run(environment.String(), func(t *testing.T) { |
379
|
|
|
// Arrange |
380
|
|
|
request := new(http.Request) |
381
|
|
|
server := helpers.MakeRequestCapturingTestServer(http.StatusOK, stubs.CheckDstvUserResponse(), request) |
382
|
|
|
|
383
|
|
|
baseURL, _ := url.Parse(server.URL) |
384
|
|
|
username := testUsername |
385
|
|
|
apiKey := testAPIKey |
386
|
|
|
transactionID := "122790223" |
387
|
|
|
|
388
|
|
|
client := New(WithBaseURL(baseURL), WithAPIKey(apiKey), WithUsername(username), WithEnvironment(environment)) |
389
|
|
|
|
390
|
|
|
// Act |
391
|
|
|
_, _, _ = client.Bills.QueryDStv(context.Background(), transactionID) |
392
|
|
|
|
393
|
|
|
// Assert |
394
|
|
|
assert.Equal(t, "/bills/query", request.URL.Path) |
395
|
|
|
assert.Equal(t, username, request.URL.Query().Get("username")) |
396
|
|
|
assert.Equal(t, apiKey, request.URL.Query().Get("api_key")) |
397
|
|
|
assert.Equal(t, transactionID, request.URL.Query().Get("trans_id")) |
398
|
|
|
|
399
|
|
|
// Teardown |
400
|
|
|
server.Close() |
401
|
|
|
}) |
402
|
|
|
} |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
func TestBillsService_QueryDStv_ErrorResponseConstructedCorrectly(t *testing.T) { |
406
|
|
|
t.Parallel() |
407
|
|
|
|
408
|
|
|
environments := []Environment{LiveEnvironment, TestEnvironment} |
409
|
|
|
for _, environment := range environments { |
410
|
|
|
t.Run(environment.String(), func(t *testing.T) { |
411
|
|
|
// Arrange |
412
|
|
|
server := helpers.MakeTestServer(http.StatusOK, stubs.ErrorResponse()) |
413
|
|
|
baseURL, _ := url.Parse(server.URL) |
414
|
|
|
|
415
|
|
|
client := New(WithBaseURL(baseURL), WithEnvironment(environment)) |
416
|
|
|
|
417
|
|
|
// Act |
418
|
|
|
_, resp, err := client.Bills.QueryDStv(context.Background(), "122790223") |
419
|
|
|
|
420
|
|
|
// Assert |
421
|
|
|
assert.Error(t, err) |
422
|
|
|
|
423
|
|
|
assert.Equal(t, "ERR101", resp.Error.Code) |
424
|
|
|
assert.Equal(t, "Invalid username or api_key", resp.Error.Description) |
425
|
|
|
|
426
|
|
|
server.Close() |
427
|
|
|
}) |
428
|
|
|
} |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
func TestBillsService_QueryDStv_CancelledContext(t *testing.T) { |
432
|
|
|
t.Parallel() |
433
|
|
|
|
434
|
|
|
environments := []Environment{LiveEnvironment, TestEnvironment} |
435
|
|
|
for _, environment := range environments { |
436
|
|
|
t.Run(environment.String(), func(t *testing.T) { |
437
|
|
|
t.Parallel() |
438
|
|
|
|
439
|
|
|
// Arrange |
440
|
|
|
server := helpers.MakeTestServer(http.StatusOK, stubs.CheckDstvUserResponse()) |
441
|
|
|
baseURL, _ := url.Parse(server.URL) |
442
|
|
|
client := New(WithBaseURL(baseURL), WithEnvironment(environment)) |
443
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
444
|
|
|
cancel() |
445
|
|
|
|
446
|
|
|
// Act |
447
|
|
|
_, _, err := client.Bills.QueryDStv(ctx, "122790223") |
448
|
|
|
|
449
|
|
|
// Assert |
450
|
|
|
assert.True(t, errors.Is(err, context.Canceled)) |
451
|
|
|
|
452
|
|
|
// Teardown |
453
|
|
|
server.Close() |
454
|
|
|
}) |
455
|
|
|
} |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
func TestBillsService_QueryDStv_InvalidResponse(t *testing.T) { |
459
|
|
|
t.Parallel() |
460
|
|
|
|
461
|
|
|
environments := []Environment{LiveEnvironment, TestEnvironment} |
462
|
|
|
for _, environment := range environments { |
463
|
|
|
t.Run(environment.String(), func(t *testing.T) { |
464
|
|
|
t.Parallel() |
465
|
|
|
|
466
|
|
|
// Arrange |
467
|
|
|
server := helpers.MakeTestServer(http.StatusOK, "<not-a-json></not-a-json>") |
468
|
|
|
baseURL, _ := url.Parse(server.URL) |
469
|
|
|
client := New(WithBaseURL(baseURL), WithEnvironment(environment)) |
470
|
|
|
|
471
|
|
|
// Act |
472
|
|
|
_, _, err := client.Bills.QueryDStv(context.Background(), "122790223") |
473
|
|
|
|
474
|
|
|
// Assert |
475
|
|
|
assert.Error(t, err) |
476
|
|
|
|
477
|
|
|
// Teardown |
478
|
|
|
server.Close() |
479
|
|
|
}) |
480
|
|
|
} |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
func TestBillsService_GetDStvPackageResponse(t *testing.T) { |
484
|
|
|
// Setup |
485
|
|
|
t.Parallel() |
486
|
|
|
|
487
|
|
|
// Arrange |
488
|
|
|
server := helpers.MakeTestServer(http.StatusOK, stubs.DstvPackageResponse()) |
489
|
|
|
baseURL, _ := url.Parse(server.URL) |
490
|
|
|
client := New(WithBaseURL(baseURL)) |
491
|
|
|
expected := "DStv French Touch Add-on Bouquet E36 + DStv Yanga Bouquet E36" |
492
|
|
|
|
493
|
|
|
// Act |
494
|
|
|
dstvPackage, _, err := client.Bills.GetDStvPackage(context.Background(), 122790223) |
495
|
|
|
|
496
|
|
|
// Assert |
497
|
|
|
assert.NoError(t, err) |
498
|
|
|
|
499
|
|
|
assert.Equal(t, &expected, dstvPackage) |
500
|
|
|
|
501
|
|
|
// Teardown |
502
|
|
|
server.Close() |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
func TestBillsService_GetDStvPackageRequest(t *testing.T) { |
506
|
|
|
// Setup |
507
|
|
|
t.Parallel() |
508
|
|
|
|
509
|
|
|
// Arrange |
510
|
|
|
request := new(http.Request) |
511
|
|
|
server := helpers.MakeRequestCapturingTestServer(http.StatusOK, stubs.DstvPackageResponse(), request) |
512
|
|
|
|
513
|
|
|
baseURL, _ := url.Parse(server.URL) |
514
|
|
|
username := testUsername |
515
|
|
|
apiKey := testAPIKey |
516
|
|
|
transactionID := int64(122790223) |
517
|
|
|
|
518
|
|
|
client := New(WithBaseURL(baseURL), WithAPIKey(apiKey), WithUsername(username)) |
519
|
|
|
|
520
|
|
|
// Act |
521
|
|
|
_, _, _ = client.Bills.GetDStvPackage(context.Background(), transactionID) |
522
|
|
|
|
523
|
|
|
// Assert |
524
|
|
|
assert.Equal(t, "/bills/get_package", request.URL.Path) |
525
|
|
|
assert.Equal(t, username, request.URL.Query().Get("username")) |
526
|
|
|
assert.Equal(t, apiKey, request.URL.Query().Get("api_key")) |
527
|
|
|
assert.Equal(t, "DSTV", request.URL.Query().Get("service")) |
528
|
|
|
assert.Equal(t, strconv.FormatInt(transactionID, 10), request.URL.Query().Get("customerNumber")) |
529
|
|
|
|
530
|
|
|
// Teardown |
531
|
|
|
server.Close() |
532
|
|
|
} |
533
|
|
|
|