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