1
|
|
|
package mollie |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"context" |
5
|
|
|
"fmt" |
6
|
|
|
"net/http" |
7
|
|
|
"testing" |
8
|
|
|
|
9
|
|
|
"github.com/VictorAvelar/mollie-api-go/v4/testdata" |
10
|
|
|
"github.com/stretchr/testify/assert" |
11
|
|
|
) |
12
|
|
|
|
13
|
|
|
func TestProfilesService_Get(t *testing.T) { |
14
|
|
|
setEnv() |
15
|
|
|
defer unsetEnv() |
16
|
|
|
|
17
|
|
|
type args struct { |
18
|
|
|
ctx context.Context |
19
|
|
|
profile string |
20
|
|
|
} |
21
|
|
|
cases := []struct { |
22
|
|
|
name string |
23
|
|
|
args args |
24
|
|
|
wantErr bool |
25
|
|
|
err error |
26
|
|
|
pre func() |
27
|
|
|
handler http.HandlerFunc |
28
|
|
|
}{ |
29
|
|
|
{ |
30
|
|
|
"get profile works as expected.", |
31
|
|
|
args{ |
32
|
|
|
context.Background(), |
33
|
|
|
"pfl_v9hTwCvYqw", |
34
|
|
|
}, |
35
|
|
|
false, |
36
|
|
|
nil, |
37
|
|
|
func() { |
38
|
|
|
tClient.WithAuthenticationValue("access_X12b31ggg23") |
39
|
|
|
}, |
40
|
|
|
func(w http.ResponseWriter, r *http.Request) { |
41
|
|
|
testHeader(t, r, AuthHeader, "Bearer access_X12b31ggg23") |
42
|
|
|
testMethod(t, r, "GET") |
43
|
|
|
testQuery(t, r, "testmode=true") |
44
|
|
|
|
45
|
|
|
if _, ok := r.Header[AuthHeader]; !ok { |
46
|
|
|
w.WriteHeader(http.StatusUnauthorized) |
47
|
|
|
} |
48
|
|
|
_, _ = w.Write([]byte(testdata.GetProfileResponse)) |
49
|
|
|
}, |
50
|
|
|
}, |
51
|
|
|
{ |
52
|
|
|
"get profile, an error is returned from the server", |
53
|
|
|
args{ |
54
|
|
|
context.Background(), |
55
|
|
|
"pfl_v9hTwCvYqw", |
56
|
|
|
}, |
57
|
|
|
true, |
58
|
|
|
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."), |
59
|
|
|
noPre, |
60
|
|
|
errorHandler, |
61
|
|
|
}, |
62
|
|
|
{ |
63
|
|
|
"get profile, an error occurs when parsing json", |
64
|
|
|
args{ |
65
|
|
|
context.Background(), |
66
|
|
|
"pfl_v9hTwCvYqw", |
67
|
|
|
}, |
68
|
|
|
true, |
69
|
|
|
fmt.Errorf("invalid character 'h' looking for beginning of object key string"), |
70
|
|
|
noPre, |
71
|
|
|
encodingHandler, |
72
|
|
|
}, |
73
|
|
|
{ |
74
|
|
|
"get profile, invalid url when building request", |
75
|
|
|
args{ |
76
|
|
|
context.Background(), |
77
|
|
|
"pfl_v9hTwCvYqw", |
78
|
|
|
}, |
79
|
|
|
true, |
80
|
|
|
errBadBaseURL, |
81
|
|
|
crashSrv, |
82
|
|
|
errorHandler, |
83
|
|
|
}, |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
for _, c := range cases { |
87
|
|
|
setup() |
88
|
|
|
defer teardown() |
89
|
|
|
|
90
|
|
|
t.Run(c.name, func(t *testing.T) { |
91
|
|
|
c.pre() |
92
|
|
|
tMux.HandleFunc(fmt.Sprintf("/v2/profiles/%s", c.args.profile), c.handler) |
93
|
|
|
|
94
|
|
|
res, m, err := tClient.Profiles.Get(c.args.ctx, c.args.profile) |
95
|
|
|
if c.wantErr { |
96
|
|
|
assert.NotNil(t, err) |
97
|
|
|
assert.EqualError(t, err, c.err.Error()) |
98
|
|
|
} else { |
99
|
|
|
assert.Nil(t, err) |
100
|
|
|
assert.IsType(t, &Profile{}, m) |
101
|
|
|
assert.IsType(t, &http.Response{}, res.Response) |
102
|
|
|
} |
103
|
|
|
}) |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
func TestProfilesService_GetCurrent(t *testing.T) { |
108
|
|
|
setEnv() |
109
|
|
|
defer unsetEnv() |
110
|
|
|
|
111
|
|
|
cases := []struct { |
112
|
|
|
name string |
113
|
|
|
wantErr bool |
114
|
|
|
err error |
115
|
|
|
pre func() |
116
|
|
|
handler http.HandlerFunc |
117
|
|
|
}{ |
118
|
|
|
{ |
119
|
|
|
"get current profile works as expected.", |
120
|
|
|
false, |
121
|
|
|
nil, |
122
|
|
|
func() { |
123
|
|
|
tClient.WithAuthenticationValue("access_X12b31ggg23") |
124
|
|
|
}, |
125
|
|
|
func(w http.ResponseWriter, r *http.Request) { |
126
|
|
|
testHeader(t, r, AuthHeader, "Bearer access_X12b31ggg23") |
127
|
|
|
testMethod(t, r, "GET") |
128
|
|
|
testQuery(t, r, "testmode=true") |
129
|
|
|
|
130
|
|
|
if _, ok := r.Header[AuthHeader]; !ok { |
131
|
|
|
w.WriteHeader(http.StatusUnauthorized) |
132
|
|
|
} |
133
|
|
|
_, _ = w.Write([]byte(testdata.GetProfileResponse)) |
134
|
|
|
}, |
135
|
|
|
}, |
136
|
|
|
{ |
137
|
|
|
"get current profile, an error is returned from the server", |
138
|
|
|
true, |
139
|
|
|
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."), |
140
|
|
|
noPre, |
141
|
|
|
errorHandler, |
142
|
|
|
}, |
143
|
|
|
{ |
144
|
|
|
"get current profile, an error occurs when parsing json", |
145
|
|
|
true, |
146
|
|
|
fmt.Errorf("invalid character 'h' looking for beginning of object key string"), |
147
|
|
|
noPre, |
148
|
|
|
encodingHandler, |
149
|
|
|
}, |
150
|
|
|
{ |
151
|
|
|
"get current profile, invalid url when building request", |
152
|
|
|
true, |
153
|
|
|
errBadBaseURL, |
154
|
|
|
crashSrv, |
155
|
|
|
errorHandler, |
156
|
|
|
}, |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
for _, c := range cases { |
160
|
|
|
setup() |
161
|
|
|
defer teardown() |
162
|
|
|
|
163
|
|
|
t.Run(c.name, func(t *testing.T) { |
164
|
|
|
c.pre() |
165
|
|
|
tMux.HandleFunc(fmt.Sprintf("/v2/profiles/%s", "me"), c.handler) |
166
|
|
|
|
167
|
|
|
res, m, err := tClient.Profiles.Current(context.Background()) |
168
|
|
|
if c.wantErr { |
169
|
|
|
assert.NotNil(t, err) |
170
|
|
|
assert.EqualError(t, err, c.err.Error()) |
171
|
|
|
} else { |
172
|
|
|
assert.Nil(t, err) |
173
|
|
|
assert.IsType(t, &Profile{}, m) |
174
|
|
|
assert.IsType(t, &http.Response{}, res.Response) |
175
|
|
|
} |
176
|
|
|
}) |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
func TestProfilesService_List(t *testing.T) { |
181
|
|
|
setEnv() |
182
|
|
|
defer unsetEnv() |
183
|
|
|
|
184
|
|
|
type args struct { |
185
|
|
|
ctx context.Context |
186
|
|
|
options *ListProfilesOptions |
187
|
|
|
} |
188
|
|
|
cases := []struct { |
189
|
|
|
name string |
190
|
|
|
args args |
191
|
|
|
wantErr bool |
192
|
|
|
err error |
193
|
|
|
pre func() |
194
|
|
|
handler http.HandlerFunc |
195
|
|
|
}{ |
196
|
|
|
{ |
197
|
|
|
"list profiles works as expected.", |
198
|
|
|
args{ |
199
|
|
|
context.Background(), |
200
|
|
|
&ListProfilesOptions{}, |
201
|
|
|
}, |
202
|
|
|
false, |
203
|
|
|
nil, |
204
|
|
|
func() { |
205
|
|
|
tClient.WithAuthenticationValue("access_X12b31ggg23") |
206
|
|
|
}, |
207
|
|
|
func(w http.ResponseWriter, r *http.Request) { |
208
|
|
|
testHeader(t, r, AuthHeader, "Bearer access_X12b31ggg23") |
209
|
|
|
testMethod(t, r, "GET") |
210
|
|
|
testQuery(t, r, "testmode=true") |
211
|
|
|
|
212
|
|
|
if _, ok := r.Header[AuthHeader]; !ok { |
213
|
|
|
w.WriteHeader(http.StatusUnauthorized) |
214
|
|
|
} |
215
|
|
|
_, _ = w.Write([]byte(testdata.GetProfilesListResponse)) |
216
|
|
|
}, |
217
|
|
|
}, |
218
|
|
|
{ |
219
|
|
|
"list profiles with options, works as expected.", |
220
|
|
|
args{ |
221
|
|
|
context.Background(), |
222
|
|
|
&ListProfilesOptions{ |
223
|
|
|
Limit: 100, |
224
|
|
|
}, |
225
|
|
|
}, |
226
|
|
|
false, |
227
|
|
|
nil, |
228
|
|
|
func() { |
229
|
|
|
tClient.WithAuthenticationValue("access_X12b31ggg23") |
230
|
|
|
}, |
231
|
|
|
func(w http.ResponseWriter, r *http.Request) { |
232
|
|
|
testHeader(t, r, AuthHeader, "Bearer access_X12b31ggg23") |
233
|
|
|
testMethod(t, r, "GET") |
234
|
|
|
testQuery(t, r, "limit=100&testmode=true") |
235
|
|
|
|
236
|
|
|
if _, ok := r.Header[AuthHeader]; !ok { |
237
|
|
|
w.WriteHeader(http.StatusUnauthorized) |
238
|
|
|
} |
239
|
|
|
_, _ = w.Write([]byte(testdata.GetProfilesListResponse)) |
240
|
|
|
}, |
241
|
|
|
}, |
242
|
|
|
{ |
243
|
|
|
"list profiles, an error is returned from the server", |
244
|
|
|
args{ |
245
|
|
|
context.Background(), |
246
|
|
|
&ListProfilesOptions{}, |
247
|
|
|
}, |
248
|
|
|
true, |
249
|
|
|
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."), |
250
|
|
|
noPre, |
251
|
|
|
errorHandler, |
252
|
|
|
}, |
253
|
|
|
{ |
254
|
|
|
"list profiles, an error occurs when parsing json", |
255
|
|
|
args{ |
256
|
|
|
context.Background(), |
257
|
|
|
&ListProfilesOptions{}, |
258
|
|
|
}, |
259
|
|
|
true, |
260
|
|
|
fmt.Errorf("invalid character 'h' looking for beginning of object key string"), |
261
|
|
|
noPre, |
262
|
|
|
encodingHandler, |
263
|
|
|
}, |
264
|
|
|
{ |
265
|
|
|
"list profiles, invalid url when building request", |
266
|
|
|
args{ |
267
|
|
|
context.Background(), |
268
|
|
|
&ListProfilesOptions{}, |
269
|
|
|
}, |
270
|
|
|
true, |
271
|
|
|
errBadBaseURL, |
272
|
|
|
crashSrv, |
273
|
|
|
errorHandler, |
274
|
|
|
}, |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
for _, c := range cases { |
278
|
|
|
setup() |
279
|
|
|
defer teardown() |
280
|
|
|
|
281
|
|
|
t.Run(c.name, func(t *testing.T) { |
282
|
|
|
c.pre() |
283
|
|
|
tMux.HandleFunc("/v2/profiles", c.handler) |
284
|
|
|
|
285
|
|
|
res, m, err := tClient.Profiles.List(c.args.ctx, c.args.options) |
286
|
|
|
if c.wantErr { |
287
|
|
|
assert.NotNil(t, err) |
288
|
|
|
assert.EqualError(t, err, c.err.Error()) |
289
|
|
|
} else { |
290
|
|
|
assert.Nil(t, err) |
291
|
|
|
assert.IsType(t, &ProfilesList{}, m) |
292
|
|
|
assert.IsType(t, &http.Response{}, res.Response) |
293
|
|
|
} |
294
|
|
|
}) |
295
|
|
|
} |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
func TestProfilesService_Create(t *testing.T) { |
299
|
|
|
setEnv() |
300
|
|
|
defer unsetEnv() |
301
|
|
|
|
302
|
|
|
type args struct { |
303
|
|
|
ctx context.Context |
304
|
|
|
profile CreateOrUpdateProfile |
305
|
|
|
} |
306
|
|
|
cases := []struct { |
307
|
|
|
name string |
308
|
|
|
args args |
309
|
|
|
wantErr bool |
310
|
|
|
err error |
311
|
|
|
pre func() |
312
|
|
|
handler http.HandlerFunc |
313
|
|
|
}{ |
314
|
|
|
{ |
315
|
|
|
"create profile works as expected.", |
316
|
|
|
args{ |
317
|
|
|
context.Background(), |
318
|
|
|
CreateOrUpdateProfile{ |
319
|
|
|
Name: "testing name", |
320
|
|
|
}, |
321
|
|
|
}, |
322
|
|
|
false, |
323
|
|
|
nil, |
324
|
|
|
func() { |
325
|
|
|
tClient.WithAuthenticationValue("access_X12b31ggg23") |
326
|
|
|
}, |
327
|
|
|
func(w http.ResponseWriter, r *http.Request) { |
328
|
|
|
testHeader(t, r, AuthHeader, "Bearer access_X12b31ggg23") |
329
|
|
|
testMethod(t, r, "POST") |
330
|
|
|
testQuery(t, r, "testmode=true") |
331
|
|
|
|
332
|
|
|
if _, ok := r.Header[AuthHeader]; !ok { |
333
|
|
|
w.WriteHeader(http.StatusUnauthorized) |
334
|
|
|
} |
335
|
|
|
_, _ = w.Write([]byte(testdata.GetProfileResponse)) |
336
|
|
|
}, |
337
|
|
|
}, |
338
|
|
|
{ |
339
|
|
|
"create profile, an error is returned from the server", |
340
|
|
|
args{ |
341
|
|
|
context.Background(), |
342
|
|
|
CreateOrUpdateProfile{}, |
343
|
|
|
}, |
344
|
|
|
true, |
345
|
|
|
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."), |
346
|
|
|
noPre, |
347
|
|
|
errorHandler, |
348
|
|
|
}, |
349
|
|
|
{ |
350
|
|
|
"create profile, an error occurs when parsing json", |
351
|
|
|
args{ |
352
|
|
|
context.Background(), |
353
|
|
|
CreateOrUpdateProfile{}, |
354
|
|
|
}, |
355
|
|
|
true, |
356
|
|
|
fmt.Errorf("invalid character 'h' looking for beginning of object key string"), |
357
|
|
|
noPre, |
358
|
|
|
encodingHandler, |
359
|
|
|
}, |
360
|
|
|
{ |
361
|
|
|
"create profile, invalid url when building request", |
362
|
|
|
args{ |
363
|
|
|
context.Background(), |
364
|
|
|
CreateOrUpdateProfile{}, |
365
|
|
|
}, |
366
|
|
|
true, |
367
|
|
|
errBadBaseURL, |
368
|
|
|
crashSrv, |
369
|
|
|
errorHandler, |
370
|
|
|
}, |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
for _, c := range cases { |
374
|
|
|
setup() |
375
|
|
|
defer teardown() |
376
|
|
|
|
377
|
|
|
t.Run(c.name, func(t *testing.T) { |
378
|
|
|
c.pre() |
379
|
|
|
tMux.HandleFunc("/v2/profiles", c.handler) |
380
|
|
|
|
381
|
|
|
res, m, err := tClient.Profiles.Create(c.args.ctx, c.args.profile) |
382
|
|
|
if c.wantErr { |
383
|
|
|
assert.NotNil(t, err) |
384
|
|
|
assert.EqualError(t, err, c.err.Error()) |
385
|
|
|
} else { |
386
|
|
|
assert.Nil(t, err) |
387
|
|
|
assert.IsType(t, &Profile{}, m) |
388
|
|
|
assert.IsType(t, &http.Response{}, res.Response) |
389
|
|
|
} |
390
|
|
|
}) |
391
|
|
|
} |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
func TestProfilesService_Update(t *testing.T) { |
395
|
|
|
setEnv() |
396
|
|
|
defer unsetEnv() |
397
|
|
|
|
398
|
|
|
type args struct { |
399
|
|
|
ctx context.Context |
400
|
|
|
profileID string |
401
|
|
|
profile CreateOrUpdateProfile |
402
|
|
|
} |
403
|
|
|
cases := []struct { |
404
|
|
|
name string |
405
|
|
|
args args |
406
|
|
|
wantErr bool |
407
|
|
|
err error |
408
|
|
|
pre func() |
409
|
|
|
handler http.HandlerFunc |
410
|
|
|
}{ |
411
|
|
|
{ |
412
|
|
|
"update profile works as expected.", |
413
|
|
|
args{ |
414
|
|
|
context.Background(), |
415
|
|
|
"pfl_v9hTwCvYqw", |
416
|
|
|
CreateOrUpdateProfile{ |
417
|
|
|
Name: "testing name", |
418
|
|
|
}, |
419
|
|
|
}, |
420
|
|
|
false, |
421
|
|
|
nil, |
422
|
|
|
func() { |
423
|
|
|
tClient.WithAuthenticationValue("access_X12b31ggg23") |
424
|
|
|
}, |
425
|
|
|
func(w http.ResponseWriter, r *http.Request) { |
426
|
|
|
testHeader(t, r, AuthHeader, "Bearer access_X12b31ggg23") |
427
|
|
|
testMethod(t, r, "PATCH") |
428
|
|
|
testQuery(t, r, "testmode=true") |
429
|
|
|
|
430
|
|
|
if _, ok := r.Header[AuthHeader]; !ok { |
431
|
|
|
w.WriteHeader(http.StatusUnauthorized) |
432
|
|
|
} |
433
|
|
|
_, _ = w.Write([]byte(testdata.GetProfileResponse)) |
434
|
|
|
}, |
435
|
|
|
}, |
436
|
|
|
{ |
437
|
|
|
"update profile, an error is returned from the server", |
438
|
|
|
args{ |
439
|
|
|
context.Background(), |
440
|
|
|
"pfl_v9hTwCvYqw", |
441
|
|
|
CreateOrUpdateProfile{}, |
442
|
|
|
}, |
443
|
|
|
true, |
444
|
|
|
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."), |
445
|
|
|
noPre, |
446
|
|
|
errorHandler, |
447
|
|
|
}, |
448
|
|
|
{ |
449
|
|
|
"update profile, an error occurs when parsing json", |
450
|
|
|
args{ |
451
|
|
|
context.Background(), |
452
|
|
|
"pfl_v9hTwCvYqw", |
453
|
|
|
CreateOrUpdateProfile{}, |
454
|
|
|
}, |
455
|
|
|
true, |
456
|
|
|
fmt.Errorf("invalid character 'h' looking for beginning of object key string"), |
457
|
|
|
noPre, |
458
|
|
|
encodingHandler, |
459
|
|
|
}, |
460
|
|
|
{ |
461
|
|
|
"update profile, invalid url when building request", |
462
|
|
|
args{ |
463
|
|
|
context.Background(), |
464
|
|
|
"pfl_v9hTwCvYqw", |
465
|
|
|
CreateOrUpdateProfile{}, |
466
|
|
|
}, |
467
|
|
|
true, |
468
|
|
|
errBadBaseURL, |
469
|
|
|
crashSrv, |
470
|
|
|
errorHandler, |
471
|
|
|
}, |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
for _, c := range cases { |
475
|
|
|
setup() |
476
|
|
|
defer teardown() |
477
|
|
|
|
478
|
|
|
t.Run(c.name, func(t *testing.T) { |
479
|
|
|
c.pre() |
480
|
|
|
tMux.HandleFunc(fmt.Sprintf("/v2/profiles/%s", c.args.profileID), c.handler) |
481
|
|
|
|
482
|
|
|
res, m, err := tClient.Profiles.Update(c.args.ctx, c.args.profileID, c.args.profile) |
483
|
|
|
if c.wantErr { |
484
|
|
|
assert.NotNil(t, err) |
485
|
|
|
assert.EqualError(t, err, c.err.Error()) |
486
|
|
|
} else { |
487
|
|
|
assert.Nil(t, err) |
488
|
|
|
assert.IsType(t, &Profile{}, m) |
489
|
|
|
assert.IsType(t, &http.Response{}, res.Response) |
490
|
|
|
} |
491
|
|
|
}) |
492
|
|
|
} |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
func TestProfilesService_Delete(t *testing.T) { |
496
|
|
|
setEnv() |
497
|
|
|
defer unsetEnv() |
498
|
|
|
|
499
|
|
|
type args struct { |
500
|
|
|
ctx context.Context |
501
|
|
|
profile string |
502
|
|
|
} |
503
|
|
|
cases := []struct { |
504
|
|
|
name string |
505
|
|
|
args args |
506
|
|
|
wantErr bool |
507
|
|
|
err error |
508
|
|
|
pre func() |
509
|
|
|
handler http.HandlerFunc |
510
|
|
|
}{ |
511
|
|
|
{ |
512
|
|
|
"delete profile works as expected.", |
513
|
|
|
args{ |
514
|
|
|
context.Background(), |
515
|
|
|
"pfl_v9hTwCvYqw", |
516
|
|
|
}, |
517
|
|
|
false, |
518
|
|
|
nil, |
519
|
|
|
func() { |
520
|
|
|
tClient.WithAuthenticationValue("access_X12b31ggg23") |
521
|
|
|
}, |
522
|
|
|
func(w http.ResponseWriter, r *http.Request) { |
523
|
|
|
testHeader(t, r, AuthHeader, "Bearer access_X12b31ggg23") |
524
|
|
|
testMethod(t, r, "DELETE") |
525
|
|
|
testQuery(t, r, "testmode=true") |
526
|
|
|
|
527
|
|
|
if _, ok := r.Header[AuthHeader]; !ok { |
528
|
|
|
w.WriteHeader(http.StatusUnauthorized) |
529
|
|
|
} |
530
|
|
|
_, _ = w.Write([]byte(testdata.GetProfileResponse)) |
531
|
|
|
}, |
532
|
|
|
}, |
533
|
|
|
{ |
534
|
|
|
"delete profile, an error is returned from the server", |
535
|
|
|
args{ |
536
|
|
|
context.Background(), |
537
|
|
|
"pfl_v9hTwCvYqw", |
538
|
|
|
}, |
539
|
|
|
true, |
540
|
|
|
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."), |
541
|
|
|
noPre, |
542
|
|
|
errorHandler, |
543
|
|
|
}, |
544
|
|
|
{ |
545
|
|
|
"delete profile, invalid url when building request", |
546
|
|
|
args{ |
547
|
|
|
context.Background(), |
548
|
|
|
"pfl_v9hTwCvYqw", |
549
|
|
|
}, |
550
|
|
|
true, |
551
|
|
|
errBadBaseURL, |
552
|
|
|
crashSrv, |
553
|
|
|
errorHandler, |
554
|
|
|
}, |
555
|
|
|
} |
556
|
|
|
|
557
|
|
|
for _, c := range cases { |
558
|
|
|
setup() |
559
|
|
|
defer teardown() |
560
|
|
|
|
561
|
|
|
t.Run(c.name, func(t *testing.T) { |
562
|
|
|
c.pre() |
563
|
|
|
tMux.HandleFunc(fmt.Sprintf("/v2/profiles/%s", c.args.profile), c.handler) |
564
|
|
|
|
565
|
|
|
res, err := tClient.Profiles.Delete(c.args.ctx, c.args.profile) |
566
|
|
|
if c.wantErr { |
567
|
|
|
assert.NotNil(t, err) |
568
|
|
|
assert.EqualError(t, err, c.err.Error()) |
569
|
|
|
} else { |
570
|
|
|
assert.Nil(t, err) |
571
|
|
|
assert.IsType(t, &http.Response{}, res.Response) |
572
|
|
|
} |
573
|
|
|
}) |
574
|
|
|
} |
575
|
|
|
} |
576
|
|
|
|
577
|
|
|
func TestProfilesService_EnablePaymentMethod(t *testing.T) { |
578
|
|
|
setEnv() |
579
|
|
|
defer unsetEnv() |
580
|
|
|
|
581
|
|
|
type args struct { |
582
|
|
|
ctx context.Context |
583
|
|
|
profile string |
584
|
|
|
method PaymentMethod |
585
|
|
|
} |
586
|
|
|
cases := []struct { |
587
|
|
|
name string |
588
|
|
|
args args |
589
|
|
|
wantErr bool |
590
|
|
|
err error |
591
|
|
|
pre func() |
592
|
|
|
handler http.HandlerFunc |
593
|
|
|
}{ |
594
|
|
|
{ |
595
|
|
|
"enable payment method for profile works as expected.", |
596
|
|
|
args{ |
597
|
|
|
context.Background(), |
598
|
|
|
"pfl_v9hTwCvYqw", |
599
|
|
|
PayPal, |
600
|
|
|
}, |
601
|
|
|
false, |
602
|
|
|
nil, |
603
|
|
|
func() { |
604
|
|
|
tClient.WithAuthenticationValue("access_X12b31ggg23") |
605
|
|
|
}, |
606
|
|
|
func(w http.ResponseWriter, r *http.Request) { |
607
|
|
|
testHeader(t, r, AuthHeader, "Bearer access_X12b31ggg23") |
608
|
|
|
testMethod(t, r, "POST") |
609
|
|
|
testQuery(t, r, "testmode=true") |
610
|
|
|
|
611
|
|
|
if _, ok := r.Header[AuthHeader]; !ok { |
612
|
|
|
w.WriteHeader(http.StatusUnauthorized) |
613
|
|
|
} |
614
|
|
|
_, _ = w.Write([]byte(testdata.EnablePaymentMethodResponse)) |
615
|
|
|
}, |
616
|
|
|
}, |
617
|
|
|
{ |
618
|
|
|
"enable payment method for profile, an error is returned from the server", |
619
|
|
|
args{ |
620
|
|
|
context.Background(), |
621
|
|
|
"pfl_v9hTwCvYqw", |
622
|
|
|
PayPal, |
623
|
|
|
}, |
624
|
|
|
true, |
625
|
|
|
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."), |
626
|
|
|
noPre, |
627
|
|
|
errorHandler, |
628
|
|
|
}, |
629
|
|
|
{ |
630
|
|
|
"enable payment method for profile, an error occurs when parsing json", |
631
|
|
|
args{ |
632
|
|
|
context.Background(), |
633
|
|
|
"pfl_v9hTwCvYqw", |
634
|
|
|
PayPal, |
635
|
|
|
}, |
636
|
|
|
true, |
637
|
|
|
fmt.Errorf("invalid character 'h' looking for beginning of object key string"), |
638
|
|
|
noPre, |
639
|
|
|
encodingHandler, |
640
|
|
|
}, |
641
|
|
|
{ |
642
|
|
|
"enable payment method for profile, invalid url when building request", |
643
|
|
|
args{ |
644
|
|
|
context.Background(), |
645
|
|
|
"pfl_v9hTwCvYqw", |
646
|
|
|
PayPal, |
647
|
|
|
}, |
648
|
|
|
true, |
649
|
|
|
errBadBaseURL, |
650
|
|
|
crashSrv, |
651
|
|
|
errorHandler, |
652
|
|
|
}, |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
for _, c := range cases { |
656
|
|
|
setup() |
657
|
|
|
defer teardown() |
658
|
|
|
|
659
|
|
|
t.Run(c.name, func(t *testing.T) { |
660
|
|
|
c.pre() |
661
|
|
|
tMux.HandleFunc(fmt.Sprintf("/v2/profiles/%s/methods/%s", c.args.profile, c.args.method), c.handler) |
662
|
|
|
|
663
|
|
|
res, m, err := tClient.Profiles.EnablePaymentMethod(c.args.ctx, c.args.profile, c.args.method) |
664
|
|
|
if c.wantErr { |
665
|
|
|
assert.NotNil(t, err) |
666
|
|
|
assert.EqualError(t, err, c.err.Error()) |
667
|
|
|
} else { |
668
|
|
|
assert.Nil(t, err) |
669
|
|
|
assert.IsType(t, &PaymentMethodDetails{}, m) |
670
|
|
|
assert.IsType(t, &http.Response{}, res.Response) |
671
|
|
|
} |
672
|
|
|
}) |
673
|
|
|
} |
674
|
|
|
} |
675
|
|
|
|
676
|
|
|
func TestProfilesService_DisablePaymentMethod(t *testing.T) { |
677
|
|
|
setEnv() |
678
|
|
|
defer unsetEnv() |
679
|
|
|
|
680
|
|
|
type args struct { |
681
|
|
|
ctx context.Context |
682
|
|
|
profile string |
683
|
|
|
method PaymentMethod |
684
|
|
|
} |
685
|
|
|
cases := []struct { |
686
|
|
|
name string |
687
|
|
|
args args |
688
|
|
|
wantErr bool |
689
|
|
|
err error |
690
|
|
|
pre func() |
691
|
|
|
handler http.HandlerFunc |
692
|
|
|
}{ |
693
|
|
|
{ |
694
|
|
|
"disable payment method for profile works as expected.", |
695
|
|
|
args{ |
696
|
|
|
context.Background(), |
697
|
|
|
"pfl_v9hTwCvYqw", |
698
|
|
|
PayPal, |
699
|
|
|
}, |
700
|
|
|
false, |
701
|
|
|
nil, |
702
|
|
|
func() { |
703
|
|
|
tClient.WithAuthenticationValue("access_X12b31ggg23") |
704
|
|
|
}, |
705
|
|
|
func(w http.ResponseWriter, r *http.Request) { |
706
|
|
|
testHeader(t, r, AuthHeader, "Bearer access_X12b31ggg23") |
707
|
|
|
testMethod(t, r, "DELETE") |
708
|
|
|
testQuery(t, r, "testmode=true") |
709
|
|
|
|
710
|
|
|
if _, ok := r.Header[AuthHeader]; !ok { |
711
|
|
|
w.WriteHeader(http.StatusUnauthorized) |
712
|
|
|
} |
713
|
|
|
|
714
|
|
|
w.WriteHeader(http.StatusOK) |
715
|
|
|
}, |
716
|
|
|
}, |
717
|
|
|
{ |
718
|
|
|
"disable payment method for profile, an error is returned from the server", |
719
|
|
|
args{ |
720
|
|
|
context.Background(), |
721
|
|
|
"pfl_v9hTwCvYqw", |
722
|
|
|
PayPal, |
723
|
|
|
}, |
724
|
|
|
true, |
725
|
|
|
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."), |
726
|
|
|
noPre, |
727
|
|
|
errorHandler, |
728
|
|
|
}, |
729
|
|
|
{ |
730
|
|
|
"disable payment method for profile, invalid url when building request", |
731
|
|
|
args{ |
732
|
|
|
context.Background(), |
733
|
|
|
"pfl_v9hTwCvYqw", |
734
|
|
|
PayPal, |
735
|
|
|
}, |
736
|
|
|
true, |
737
|
|
|
errBadBaseURL, |
738
|
|
|
crashSrv, |
739
|
|
|
errorHandler, |
740
|
|
|
}, |
741
|
|
|
} |
742
|
|
|
|
743
|
|
|
for _, c := range cases { |
744
|
|
|
setup() |
745
|
|
|
defer teardown() |
746
|
|
|
|
747
|
|
|
t.Run(c.name, func(t *testing.T) { |
748
|
|
|
c.pre() |
749
|
|
|
tMux.HandleFunc(fmt.Sprintf("/v2/profiles/%s/methods/%s", c.args.profile, c.args.method), c.handler) |
750
|
|
|
|
751
|
|
|
res, err := tClient.Profiles.DisablePaymentMethod(c.args.ctx, c.args.profile, c.args.method) |
752
|
|
|
if c.wantErr { |
753
|
|
|
assert.NotNil(t, err) |
754
|
|
|
assert.EqualError(t, err, c.err.Error()) |
755
|
|
|
} else { |
756
|
|
|
assert.Nil(t, err) |
757
|
|
|
assert.IsType(t, &http.Response{}, res.Response) |
758
|
|
|
} |
759
|
|
|
}) |
760
|
|
|
} |
761
|
|
|
} |
762
|
|
|
|
763
|
|
|
func TestProfilesService_EnableGiftCardIssuer(t *testing.T) { |
764
|
|
|
setEnv() |
765
|
|
|
defer unsetEnv() |
766
|
|
|
|
767
|
|
|
type args struct { |
768
|
|
|
ctx context.Context |
769
|
|
|
profile string |
770
|
|
|
issuer GiftCardIssuer |
771
|
|
|
} |
772
|
|
|
cases := []struct { |
773
|
|
|
name string |
774
|
|
|
args args |
775
|
|
|
wantErr bool |
776
|
|
|
err error |
777
|
|
|
pre func() |
778
|
|
|
handler http.HandlerFunc |
779
|
|
|
}{ |
780
|
|
|
{ |
781
|
|
|
"enable gifcard issuer for profile works as expected.", |
782
|
|
|
args{ |
783
|
|
|
context.Background(), |
784
|
|
|
"pfl_v9hTwCvYqw", |
785
|
|
|
Good4fun, |
786
|
|
|
}, |
787
|
|
|
false, |
788
|
|
|
nil, |
789
|
|
|
func() { |
790
|
|
|
tClient.WithAuthenticationValue("access_X12b31ggg23") |
791
|
|
|
}, |
792
|
|
|
func(w http.ResponseWriter, r *http.Request) { |
793
|
|
|
testHeader(t, r, AuthHeader, "Bearer access_X12b31ggg23") |
794
|
|
|
testMethod(t, r, "POST") |
795
|
|
|
testQuery(t, r, "testmode=true") |
796
|
|
|
|
797
|
|
|
if _, ok := r.Header[AuthHeader]; !ok { |
798
|
|
|
w.WriteHeader(http.StatusUnauthorized) |
799
|
|
|
} |
800
|
|
|
_, _ = w.Write([]byte(testdata.EnablePaymentMethodResponse)) |
801
|
|
|
}, |
802
|
|
|
}, |
803
|
|
|
{ |
804
|
|
|
"enable gifcard issuer for profile, an error is returned from the server", |
805
|
|
|
args{ |
806
|
|
|
context.Background(), |
807
|
|
|
"pfl_v9hTwCvYqw", |
808
|
|
|
Good4fun, |
809
|
|
|
}, |
810
|
|
|
true, |
811
|
|
|
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."), |
812
|
|
|
noPre, |
813
|
|
|
errorHandler, |
814
|
|
|
}, |
815
|
|
|
{ |
816
|
|
|
"enable gifcard issuer for profile, an error occurs when parsing json", |
817
|
|
|
args{ |
818
|
|
|
context.Background(), |
819
|
|
|
"pfl_v9hTwCvYqw", |
820
|
|
|
Good4fun, |
821
|
|
|
}, |
822
|
|
|
true, |
823
|
|
|
fmt.Errorf("invalid character 'h' looking for beginning of object key string"), |
824
|
|
|
noPre, |
825
|
|
|
encodingHandler, |
826
|
|
|
}, |
827
|
|
|
{ |
828
|
|
|
"enable gifcard issuer for profile, invalid url when building request", |
829
|
|
|
args{ |
830
|
|
|
context.Background(), |
831
|
|
|
"pfl_v9hTwCvYqw", |
832
|
|
|
Good4fun, |
833
|
|
|
}, |
834
|
|
|
true, |
835
|
|
|
errBadBaseURL, |
836
|
|
|
crashSrv, |
837
|
|
|
errorHandler, |
838
|
|
|
}, |
839
|
|
|
} |
840
|
|
|
|
841
|
|
|
for _, c := range cases { |
842
|
|
|
setup() |
843
|
|
|
defer teardown() |
844
|
|
|
|
845
|
|
|
t.Run(c.name, func(t *testing.T) { |
846
|
|
|
c.pre() |
847
|
|
|
tMux.HandleFunc(fmt.Sprintf("/v2/profiles/%s/methods/giftcard/issuers/%s", c.args.profile, c.args.issuer), c.handler) |
848
|
|
|
|
849
|
|
|
res, m, err := tClient.Profiles.EnableGiftCardIssuer(c.args.ctx, c.args.profile, c.args.issuer) |
850
|
|
|
if c.wantErr { |
851
|
|
|
assert.NotNil(t, err) |
852
|
|
|
assert.EqualError(t, err, c.err.Error()) |
853
|
|
|
} else { |
854
|
|
|
assert.Nil(t, err) |
855
|
|
|
assert.IsType(t, &GiftCardEnabled{}, m) |
856
|
|
|
assert.IsType(t, &http.Response{}, res.Response) |
857
|
|
|
} |
858
|
|
|
}) |
859
|
|
|
} |
860
|
|
|
} |
861
|
|
|
|
862
|
|
|
func TestProfilesService_DisableGiftCardIssuer(t *testing.T) { |
863
|
|
|
setEnv() |
864
|
|
|
defer unsetEnv() |
865
|
|
|
|
866
|
|
|
type args struct { |
867
|
|
|
ctx context.Context |
868
|
|
|
profile string |
869
|
|
|
issuer GiftCardIssuer |
870
|
|
|
} |
871
|
|
|
cases := []struct { |
872
|
|
|
name string |
873
|
|
|
args args |
874
|
|
|
wantErr bool |
875
|
|
|
err error |
876
|
|
|
pre func() |
877
|
|
|
handler http.HandlerFunc |
878
|
|
|
}{ |
879
|
|
|
{ |
880
|
|
|
"disable giftcard issuer for profile works as expected.", |
881
|
|
|
args{ |
882
|
|
|
context.Background(), |
883
|
|
|
"pfl_v9hTwCvYqw", |
884
|
|
|
Good4fun, |
885
|
|
|
}, |
886
|
|
|
false, |
887
|
|
|
nil, |
888
|
|
|
func() { |
889
|
|
|
tClient.WithAuthenticationValue("access_X12b31ggg23") |
890
|
|
|
}, |
891
|
|
|
func(w http.ResponseWriter, r *http.Request) { |
892
|
|
|
testHeader(t, r, AuthHeader, "Bearer access_X12b31ggg23") |
893
|
|
|
testMethod(t, r, "DELETE") |
894
|
|
|
testQuery(t, r, "testmode=true") |
895
|
|
|
|
896
|
|
|
if _, ok := r.Header[AuthHeader]; !ok { |
897
|
|
|
w.WriteHeader(http.StatusUnauthorized) |
898
|
|
|
} |
899
|
|
|
|
900
|
|
|
w.WriteHeader(http.StatusOK) |
901
|
|
|
}, |
902
|
|
|
}, |
903
|
|
|
{ |
904
|
|
|
"disable giftcard issuer for profile, an error is returned from the server", |
905
|
|
|
args{ |
906
|
|
|
context.Background(), |
907
|
|
|
"pfl_v9hTwCvYqw", |
908
|
|
|
Good4fun, |
909
|
|
|
}, |
910
|
|
|
true, |
911
|
|
|
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."), |
912
|
|
|
noPre, |
913
|
|
|
errorHandler, |
914
|
|
|
}, |
915
|
|
|
{ |
916
|
|
|
"disable giftcard issuer for profile, invalid url when building request", |
917
|
|
|
args{ |
918
|
|
|
context.Background(), |
919
|
|
|
"pfl_v9hTwCvYqw", |
920
|
|
|
Good4fun, |
921
|
|
|
}, |
922
|
|
|
true, |
923
|
|
|
errBadBaseURL, |
924
|
|
|
crashSrv, |
925
|
|
|
errorHandler, |
926
|
|
|
}, |
927
|
|
|
} |
928
|
|
|
|
929
|
|
|
for _, c := range cases { |
930
|
|
|
setup() |
931
|
|
|
defer teardown() |
932
|
|
|
|
933
|
|
|
t.Run(c.name, func(t *testing.T) { |
934
|
|
|
c.pre() |
935
|
|
|
tMux.HandleFunc(fmt.Sprintf("/v2/profiles/%s/methods/giftcard/issuers/%s", c.args.profile, c.args.issuer), c.handler) |
936
|
|
|
|
937
|
|
|
res, err := tClient.Profiles.DisableGiftCardIssuer(c.args.ctx, c.args.profile, c.args.issuer) |
938
|
|
|
if c.wantErr { |
939
|
|
|
assert.NotNil(t, err) |
940
|
|
|
assert.EqualError(t, err, c.err.Error()) |
941
|
|
|
} else { |
942
|
|
|
assert.Nil(t, err) |
943
|
|
|
assert.IsType(t, &http.Response{}, res.Response) |
944
|
|
|
} |
945
|
|
|
}) |
946
|
|
|
} |
947
|
|
|
} |
948
|
|
|
|
949
|
|
|
func TestProfilesService_EnableGiftCardIssuerForCurrent(t *testing.T) { |
950
|
|
|
setEnv() |
951
|
|
|
defer unsetEnv() |
952
|
|
|
|
953
|
|
|
type args struct { |
954
|
|
|
ctx context.Context |
955
|
|
|
issuer GiftCardIssuer |
956
|
|
|
} |
957
|
|
|
cases := []struct { |
958
|
|
|
name string |
959
|
|
|
args args |
960
|
|
|
wantErr bool |
961
|
|
|
err error |
962
|
|
|
pre func() |
963
|
|
|
handler http.HandlerFunc |
964
|
|
|
}{ |
965
|
|
|
{ |
966
|
|
|
"enable gifcard issuer for profile works as expected.", |
967
|
|
|
args{ |
968
|
|
|
context.Background(), |
969
|
|
|
Good4fun, |
970
|
|
|
}, |
971
|
|
|
false, |
972
|
|
|
nil, |
973
|
|
|
func() { |
974
|
|
|
tClient.WithAuthenticationValue("access_X12b31ggg23") |
975
|
|
|
}, |
976
|
|
|
func(w http.ResponseWriter, r *http.Request) { |
977
|
|
|
testHeader(t, r, AuthHeader, "Bearer access_X12b31ggg23") |
978
|
|
|
testMethod(t, r, "POST") |
979
|
|
|
testQuery(t, r, "testmode=true") |
980
|
|
|
|
981
|
|
|
if _, ok := r.Header[AuthHeader]; !ok { |
982
|
|
|
w.WriteHeader(http.StatusUnauthorized) |
983
|
|
|
} |
984
|
|
|
_, _ = w.Write([]byte(testdata.EnableGiftCardIssuerResponse)) |
985
|
|
|
}, |
986
|
|
|
}, |
987
|
|
|
{ |
988
|
|
|
"enable gifcard issuer for profile, an error is returned from the server", |
989
|
|
|
args{ |
990
|
|
|
context.Background(), |
991
|
|
|
Good4fun, |
992
|
|
|
}, |
993
|
|
|
true, |
994
|
|
|
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."), |
995
|
|
|
noPre, |
996
|
|
|
errorHandler, |
997
|
|
|
}, |
998
|
|
|
{ |
999
|
|
|
"enable gifcard issuer for profile, an error occurs when parsing json", |
1000
|
|
|
args{ |
1001
|
|
|
context.Background(), |
1002
|
|
|
Good4fun, |
1003
|
|
|
}, |
1004
|
|
|
true, |
1005
|
|
|
fmt.Errorf("invalid character 'h' looking for beginning of object key string"), |
1006
|
|
|
noPre, |
1007
|
|
|
encodingHandler, |
1008
|
|
|
}, |
1009
|
|
|
{ |
1010
|
|
|
"enable gifcard issuer for profile, invalid url when building request", |
1011
|
|
|
args{ |
1012
|
|
|
context.Background(), |
1013
|
|
|
Good4fun, |
1014
|
|
|
}, |
1015
|
|
|
true, |
1016
|
|
|
errBadBaseURL, |
1017
|
|
|
crashSrv, |
1018
|
|
|
errorHandler, |
1019
|
|
|
}, |
1020
|
|
|
} |
1021
|
|
|
|
1022
|
|
|
for _, c := range cases { |
1023
|
|
|
setup() |
1024
|
|
|
defer teardown() |
1025
|
|
|
|
1026
|
|
|
t.Run(c.name, func(t *testing.T) { |
1027
|
|
|
c.pre() |
1028
|
|
|
tMux.HandleFunc(fmt.Sprintf("/v2/profiles/me/methods/giftcard/issuers/%s", c.args.issuer), c.handler) |
1029
|
|
|
|
1030
|
|
|
res, m, err := tClient.Profiles.EnableGiftCardIssuerForCurrent(c.args.ctx, c.args.issuer) |
1031
|
|
|
if c.wantErr { |
1032
|
|
|
assert.NotNil(t, err) |
1033
|
|
|
assert.EqualError(t, err, c.err.Error()) |
1034
|
|
|
} else { |
1035
|
|
|
assert.Nil(t, err) |
1036
|
|
|
assert.IsType(t, &GiftCardEnabled{}, m) |
1037
|
|
|
assert.IsType(t, &http.Response{}, res.Response) |
1038
|
|
|
} |
1039
|
|
|
}) |
1040
|
|
|
} |
1041
|
|
|
} |
1042
|
|
|
|
1043
|
|
|
func TestProfilesService_DisableGiftCardIssuerForCurrent(t *testing.T) { |
1044
|
|
|
setEnv() |
1045
|
|
|
defer unsetEnv() |
1046
|
|
|
|
1047
|
|
|
type args struct { |
1048
|
|
|
ctx context.Context |
1049
|
|
|
issuer GiftCardIssuer |
1050
|
|
|
} |
1051
|
|
|
cases := []struct { |
1052
|
|
|
name string |
1053
|
|
|
args args |
1054
|
|
|
wantErr bool |
1055
|
|
|
err error |
1056
|
|
|
pre func() |
1057
|
|
|
handler http.HandlerFunc |
1058
|
|
|
}{ |
1059
|
|
|
{ |
1060
|
|
|
"disable giftcard issuer for profile works as expected.", |
1061
|
|
|
args{ |
1062
|
|
|
context.Background(), |
1063
|
|
|
Good4fun, |
1064
|
|
|
}, |
1065
|
|
|
false, |
1066
|
|
|
nil, |
1067
|
|
|
func() { |
1068
|
|
|
tClient.WithAuthenticationValue("access_X12b31ggg23") |
1069
|
|
|
}, |
1070
|
|
|
func(w http.ResponseWriter, r *http.Request) { |
1071
|
|
|
testHeader(t, r, AuthHeader, "Bearer access_X12b31ggg23") |
1072
|
|
|
testMethod(t, r, "DELETE") |
1073
|
|
|
testQuery(t, r, "testmode=true") |
1074
|
|
|
|
1075
|
|
|
if _, ok := r.Header[AuthHeader]; !ok { |
1076
|
|
|
w.WriteHeader(http.StatusUnauthorized) |
1077
|
|
|
} |
1078
|
|
|
|
1079
|
|
|
w.WriteHeader(http.StatusOK) |
1080
|
|
|
}, |
1081
|
|
|
}, |
1082
|
|
|
{ |
1083
|
|
|
"disable giftcard issuer for profile, an error is returned from the server", |
1084
|
|
|
args{ |
1085
|
|
|
context.Background(), |
1086
|
|
|
Good4fun, |
1087
|
|
|
}, |
1088
|
|
|
true, |
1089
|
|
|
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."), |
1090
|
|
|
noPre, |
1091
|
|
|
errorHandler, |
1092
|
|
|
}, |
1093
|
|
|
{ |
1094
|
|
|
"disable giftcard issuer for profile, invalid url when building request", |
1095
|
|
|
args{ |
1096
|
|
|
context.Background(), |
1097
|
|
|
Good4fun, |
1098
|
|
|
}, |
1099
|
|
|
true, |
1100
|
|
|
errBadBaseURL, |
1101
|
|
|
crashSrv, |
1102
|
|
|
errorHandler, |
1103
|
|
|
}, |
1104
|
|
|
} |
1105
|
|
|
|
1106
|
|
|
for _, c := range cases { |
1107
|
|
|
setup() |
1108
|
|
|
defer teardown() |
1109
|
|
|
|
1110
|
|
|
t.Run(c.name, func(t *testing.T) { |
1111
|
|
|
c.pre() |
1112
|
|
|
tMux.HandleFunc(fmt.Sprintf("/v2/profiles/me/methods/giftcard/issuers/%s", c.args.issuer), c.handler) |
1113
|
|
|
|
1114
|
|
|
res, err := tClient.Profiles.DisableGiftCardIssuerForCurrent(c.args.ctx, c.args.issuer) |
1115
|
|
|
if c.wantErr { |
1116
|
|
|
assert.NotNil(t, err) |
1117
|
|
|
assert.EqualError(t, err, c.err.Error()) |
1118
|
|
|
} else { |
1119
|
|
|
assert.Nil(t, err) |
1120
|
|
|
assert.IsType(t, &http.Response{}, res.Response) |
1121
|
|
|
} |
1122
|
|
|
}) |
1123
|
|
|
} |
1124
|
|
|
} |
1125
|
|
|
|
1126
|
|
|
func TestProfilesService_EnableVoucherIssuer(t *testing.T) { |
1127
|
|
|
setEnv() |
1128
|
|
|
defer unsetEnv() |
1129
|
|
|
|
1130
|
|
|
type args struct { |
1131
|
|
|
ctx context.Context |
1132
|
|
|
profile string |
1133
|
|
|
issuer VoucherIssuer |
1134
|
|
|
vi *EnableVoucherIssuer |
1135
|
|
|
} |
1136
|
|
|
cases := []struct { |
1137
|
|
|
name string |
1138
|
|
|
args args |
1139
|
|
|
wantErr bool |
1140
|
|
|
err error |
1141
|
|
|
pre func() |
1142
|
|
|
handler http.HandlerFunc |
1143
|
|
|
}{ |
1144
|
|
|
{ |
1145
|
|
|
"enable voucher issuer for profile works as expected using an access key.", |
1146
|
|
|
args{ |
1147
|
|
|
context.Background(), |
1148
|
|
|
"pfl_v9hTwCvYqw", |
1149
|
|
|
PluxeeEcoVoucher, |
1150
|
|
|
nil, |
1151
|
|
|
}, |
1152
|
|
|
false, |
1153
|
|
|
nil, |
1154
|
|
|
setAccessToken, |
1155
|
|
|
func(w http.ResponseWriter, r *http.Request) { |
1156
|
|
|
testMethod(t, r, "POST") |
1157
|
|
|
_, _ = w.Write([]byte(testdata.EnableVoucherIssuerResponse)) |
1158
|
|
|
}, |
1159
|
|
|
}, |
1160
|
|
|
{ |
1161
|
|
|
"enable voucher issuer for profile an error is returned from the server.", |
1162
|
|
|
args{ |
1163
|
|
|
context.Background(), |
1164
|
|
|
"pfl_v9hTwCvYqw", |
1165
|
|
|
PluxeeEcoVoucher, |
1166
|
|
|
nil, |
1167
|
|
|
}, |
1168
|
|
|
true, |
1169
|
|
|
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."), |
1170
|
|
|
setAccessToken, |
1171
|
|
|
errorHandler, |
1172
|
|
|
}, |
1173
|
|
|
{ |
1174
|
|
|
"enable voucher issuer for profile an error occurs when parsing json.", |
1175
|
|
|
args{ |
1176
|
|
|
context.Background(), |
1177
|
|
|
"pfl_v9hTwCvYqw", |
1178
|
|
|
PluxeeEcoVoucher, |
1179
|
|
|
nil, |
1180
|
|
|
}, |
1181
|
|
|
true, |
1182
|
|
|
fmt.Errorf("invalid character 'h' looking for beginning of object key string"), |
1183
|
|
|
setAccessToken, |
1184
|
|
|
encodingHandler, |
1185
|
|
|
}, |
1186
|
|
|
{ |
1187
|
|
|
"enable voucher issuer for profile invalid url when building request.", |
1188
|
|
|
args{ |
1189
|
|
|
context.Background(), |
1190
|
|
|
"pfl_v9hTwCvYqw", |
1191
|
|
|
PluxeeEcoVoucher, |
1192
|
|
|
nil, |
1193
|
|
|
}, |
1194
|
|
|
true, |
1195
|
|
|
errBadBaseURL, |
1196
|
|
|
crashSrv, |
1197
|
|
|
errorHandler, |
1198
|
|
|
}, |
1199
|
|
|
} |
1200
|
|
|
|
1201
|
|
|
for _, c := range cases { |
1202
|
|
|
setup() |
1203
|
|
|
defer teardown() |
1204
|
|
|
|
1205
|
|
|
t.Run(c.name, func(t *testing.T) { |
1206
|
|
|
c.pre() |
1207
|
|
|
|
1208
|
|
|
if tClient.HasAccessToken() { |
1209
|
|
|
tMux.HandleFunc( |
1210
|
|
|
fmt.Sprintf("/v2/profiles/%s/methods/voucher/issuers/%s", |
1211
|
|
|
c.args.profile, |
1212
|
|
|
c.args.issuer, |
1213
|
|
|
), |
1214
|
|
|
c.handler, |
1215
|
|
|
) |
1216
|
|
|
} else { |
1217
|
|
|
tMux.HandleFunc( |
1218
|
|
|
fmt.Sprintf("/v2/profiles/me/methods/voucher/issuers/%s", |
1219
|
|
|
c.args.issuer, |
1220
|
|
|
), |
1221
|
|
|
c.handler, |
1222
|
|
|
) |
1223
|
|
|
} |
1224
|
|
|
|
1225
|
|
|
res, m, err := tClient.Profiles.EnableVoucherIssuer(c.args.ctx, c.args.profile, c.args.issuer, c.args.vi) |
1226
|
|
|
if c.wantErr { |
1227
|
|
|
assert.NotNil(t, err) |
1228
|
|
|
assert.EqualError(t, err, c.err.Error()) |
1229
|
|
|
} else { |
1230
|
|
|
assert.Nil(t, err) |
1231
|
|
|
assert.IsType(t, &VoucherIssuerEnabled{}, m) |
1232
|
|
|
assert.IsType(t, &http.Response{}, res.Response) |
1233
|
|
|
} |
1234
|
|
|
}) |
1235
|
|
|
} |
1236
|
|
|
} |
1237
|
|
|
|
1238
|
|
|
func TestProfileService_DisableVoucherIssuer(t *testing.T) { |
1239
|
|
|
setEnv() |
1240
|
|
|
defer unsetEnv() |
1241
|
|
|
|
1242
|
|
|
type args struct { |
1243
|
|
|
ctx context.Context |
1244
|
|
|
profile string |
1245
|
|
|
issuer VoucherIssuer |
1246
|
|
|
} |
1247
|
|
|
cases := []struct { |
1248
|
|
|
name string |
1249
|
|
|
args args |
1250
|
|
|
wantErr bool |
1251
|
|
|
err error |
1252
|
|
|
pre func() |
1253
|
|
|
handler http.HandlerFunc |
1254
|
|
|
}{ |
1255
|
|
|
{ |
1256
|
|
|
"disable voucher issuer for profile works as expected.", |
1257
|
|
|
args{ |
1258
|
|
|
context.Background(), |
1259
|
|
|
"pfl_v9hTwCvYqw", |
1260
|
|
|
PluxeeEcoVoucher, |
1261
|
|
|
}, |
1262
|
|
|
false, |
1263
|
|
|
nil, |
1264
|
|
|
func() { |
1265
|
|
|
tClient.WithAuthenticationValue("access_X12b31ggg23") |
1266
|
|
|
}, |
1267
|
|
|
func(w http.ResponseWriter, r *http.Request) { |
1268
|
|
|
testMethod(t, r, "DELETE") |
1269
|
|
|
w.WriteHeader(http.StatusNoContent) |
1270
|
|
|
}, |
1271
|
|
|
}, |
1272
|
|
|
{ |
1273
|
|
|
"disable voucher issuer for profile an error is returned from the server.", |
1274
|
|
|
args{ |
1275
|
|
|
context.Background(), |
1276
|
|
|
"pfl_v9hTwCvYqw", |
1277
|
|
|
PluxeeEcoVoucher, |
1278
|
|
|
}, |
1279
|
|
|
true, |
1280
|
|
|
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."), |
1281
|
|
|
noPre, |
1282
|
|
|
errorHandler, |
1283
|
|
|
}, |
1284
|
|
|
{ |
1285
|
|
|
"disable voucher issuer for profile invalid url when building request.", |
1286
|
|
|
args{ |
1287
|
|
|
context.Background(), |
1288
|
|
|
"pfl_v9hTwCvYqw", |
1289
|
|
|
PluxeeEcoVoucher, |
1290
|
|
|
}, |
1291
|
|
|
true, |
1292
|
|
|
errBadBaseURL, |
1293
|
|
|
crashSrv, |
1294
|
|
|
errorHandler, |
1295
|
|
|
}, |
1296
|
|
|
} |
1297
|
|
|
|
1298
|
|
|
for _, c := range cases { |
1299
|
|
|
setup() |
1300
|
|
|
defer teardown() |
1301
|
|
|
|
1302
|
|
|
t.Run(c.name, func(t *testing.T) { |
1303
|
|
|
c.pre() |
1304
|
|
|
tMux.HandleFunc( |
1305
|
|
|
fmt.Sprintf("/v2/profiles/%s/methods/voucher/issuers/%s", |
1306
|
|
|
c.args.profile, |
1307
|
|
|
c.args.issuer, |
1308
|
|
|
), |
1309
|
|
|
c.handler, |
1310
|
|
|
) |
1311
|
|
|
|
1312
|
|
|
res, err := tClient.Profiles.DisableVoucherIssuer(c.args.ctx, c.args.profile, c.args.issuer) |
1313
|
|
|
if c.wantErr { |
1314
|
|
|
assert.NotNil(t, err) |
1315
|
|
|
assert.EqualError(t, err, c.err.Error()) |
1316
|
|
|
} else { |
1317
|
|
|
assert.Nil(t, err) |
1318
|
|
|
assert.IsType(t, &http.Response{}, res.Response) |
1319
|
|
|
assert.Equal(t, http.StatusNoContent, res.StatusCode) |
1320
|
|
|
} |
1321
|
|
|
}) |
1322
|
|
|
} |
1323
|
|
|
} |
1324
|
|
|
|
1325
|
|
|
func TestProfileService_EnableVoucherIssuerForCurrent(t *testing.T) { |
1326
|
|
|
setEnv() |
1327
|
|
|
defer unsetEnv() |
1328
|
|
|
|
1329
|
|
|
type args struct { |
1330
|
|
|
ctx context.Context |
1331
|
|
|
issuer VoucherIssuer |
1332
|
|
|
} |
1333
|
|
|
cases := []struct { |
1334
|
|
|
name string |
1335
|
|
|
args args |
1336
|
|
|
wantErr bool |
1337
|
|
|
err error |
1338
|
|
|
pre func() |
1339
|
|
|
handler http.HandlerFunc |
1340
|
|
|
}{ |
1341
|
|
|
{ |
1342
|
|
|
"enable voucher issuer for current profile works as expected.", |
1343
|
|
|
args{ |
1344
|
|
|
context.Background(), |
1345
|
|
|
PluxeeEcoVoucher, |
1346
|
|
|
}, |
1347
|
|
|
false, |
1348
|
|
|
nil, |
1349
|
|
|
noPre, |
1350
|
|
|
func(w http.ResponseWriter, r *http.Request) { |
1351
|
|
|
testMethod(t, r, "POST") |
1352
|
|
|
w.WriteHeader(http.StatusCreated) |
1353
|
|
|
_, _ = w.Write([]byte(testdata.EnableVoucherIssuerResponse)) |
1354
|
|
|
}, |
1355
|
|
|
}, |
1356
|
|
|
{ |
1357
|
|
|
"enable voucher issuer for current profile an error is returned from the server.", |
1358
|
|
|
args{ |
1359
|
|
|
context.Background(), |
1360
|
|
|
PluxeeEcoVoucher, |
1361
|
|
|
}, |
1362
|
|
|
true, |
1363
|
|
|
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."), |
1364
|
|
|
noPre, |
1365
|
|
|
errorHandler, |
1366
|
|
|
}, |
1367
|
|
|
{ |
1368
|
|
|
"enable voucher issuer for current profile an error occurs when parsing json.", |
1369
|
|
|
args{ |
1370
|
|
|
context.Background(), |
1371
|
|
|
PluxeeEcoVoucher, |
1372
|
|
|
}, |
1373
|
|
|
true, |
1374
|
|
|
fmt.Errorf("invalid character 'h' looking for beginning of object key string"), |
1375
|
|
|
noPre, |
1376
|
|
|
encodingHandler, |
1377
|
|
|
}, |
1378
|
|
|
{ |
1379
|
|
|
"enable voucher issuer for current profile invalid url when building request.", |
1380
|
|
|
args{ |
1381
|
|
|
context.Background(), |
1382
|
|
|
PluxeeEcoVoucher, |
1383
|
|
|
}, |
1384
|
|
|
true, |
1385
|
|
|
errBadBaseURL, |
1386
|
|
|
crashSrv, |
1387
|
|
|
errorHandler, |
1388
|
|
|
}, |
1389
|
|
|
} |
1390
|
|
|
|
1391
|
|
|
for _, c := range cases { |
1392
|
|
|
setup() |
1393
|
|
|
defer teardown() |
1394
|
|
|
|
1395
|
|
|
t.Run(c.name, func(t *testing.T) { |
1396
|
|
|
c.pre() |
1397
|
|
|
tMux.HandleFunc( |
1398
|
|
|
fmt.Sprintf("/v2/profiles/me/methods/voucher/issuers/%s", |
1399
|
|
|
c.args.issuer, |
1400
|
|
|
), |
1401
|
|
|
c.handler, |
1402
|
|
|
) |
1403
|
|
|
|
1404
|
|
|
res, vi, err := tClient.Profiles.EnableVoucherIssuerForCurrent(c.args.ctx, c.args.issuer) |
1405
|
|
|
if c.wantErr { |
1406
|
|
|
assert.NotNil(t, err) |
1407
|
|
|
assert.EqualError(t, err, c.err.Error()) |
1408
|
|
|
} else { |
1409
|
|
|
assert.Nil(t, err) |
1410
|
|
|
assert.IsType(t, &http.Response{}, res.Response) |
1411
|
|
|
assert.IsType(t, &VoucherIssuerEnabled{}, vi) |
1412
|
|
|
assert.Equal(t, http.StatusCreated, res.StatusCode) |
1413
|
|
|
} |
1414
|
|
|
}) |
1415
|
|
|
} |
1416
|
|
|
} |
1417
|
|
|
|
1418
|
|
|
func TestProfileService_DisableVoucherIssuerForCurrent(t *testing.T) { |
1419
|
|
|
setEnv() |
1420
|
|
|
defer unsetEnv() |
1421
|
|
|
|
1422
|
|
|
type args struct { |
1423
|
|
|
ctx context.Context |
1424
|
|
|
issuer VoucherIssuer |
1425
|
|
|
} |
1426
|
|
|
cases := []struct { |
1427
|
|
|
name string |
1428
|
|
|
args args |
1429
|
|
|
wantErr bool |
1430
|
|
|
err error |
1431
|
|
|
pre func() |
1432
|
|
|
handler http.HandlerFunc |
1433
|
|
|
}{ |
1434
|
|
|
{ |
1435
|
|
|
"disable voucher issuer for current profile works as expected.", |
1436
|
|
|
args{ |
1437
|
|
|
context.Background(), |
1438
|
|
|
PluxeeEcoVoucher, |
1439
|
|
|
}, |
1440
|
|
|
false, |
1441
|
|
|
nil, |
1442
|
|
|
noPre, |
1443
|
|
|
func(w http.ResponseWriter, r *http.Request) { |
1444
|
|
|
testMethod(t, r, "DELETE") |
1445
|
|
|
w.WriteHeader(http.StatusNoContent) |
1446
|
|
|
}, |
1447
|
|
|
}, |
1448
|
|
|
{ |
1449
|
|
|
"disable voucher issuer for current profile an error is returned from the server.", |
1450
|
|
|
args{ |
1451
|
|
|
context.Background(), |
1452
|
|
|
PluxeeEcoVoucher, |
1453
|
|
|
}, |
1454
|
|
|
true, |
1455
|
|
|
fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."), |
1456
|
|
|
noPre, |
1457
|
|
|
errorHandler, |
1458
|
|
|
}, |
1459
|
|
|
{ |
1460
|
|
|
"disable voucher issuer for current profile invalid url when building request.", |
1461
|
|
|
args{ |
1462
|
|
|
context.Background(), |
1463
|
|
|
PluxeeEcoVoucher, |
1464
|
|
|
}, |
1465
|
|
|
true, |
1466
|
|
|
errBadBaseURL, |
1467
|
|
|
crashSrv, |
1468
|
|
|
errorHandler, |
1469
|
|
|
}, |
1470
|
|
|
} |
1471
|
|
|
|
1472
|
|
|
for _, c := range cases { |
1473
|
|
|
setup() |
1474
|
|
|
defer teardown() |
1475
|
|
|
|
1476
|
|
|
t.Run(c.name, func(t *testing.T) { |
1477
|
|
|
c.pre() |
1478
|
|
|
tMux.HandleFunc( |
1479
|
|
|
fmt.Sprintf("/v2/profiles/me/methods/voucher/issuers/%s", |
1480
|
|
|
c.args.issuer, |
1481
|
|
|
), |
1482
|
|
|
c.handler, |
1483
|
|
|
) |
1484
|
|
|
|
1485
|
|
|
res, err := tClient.Profiles.DisableVoucherIssuerForCurrent(c.args.ctx, c.args.issuer) |
1486
|
|
|
if c.wantErr { |
1487
|
|
|
assert.NotNil(t, err) |
1488
|
|
|
assert.EqualError(t, err, c.err.Error()) |
1489
|
|
|
} else { |
1490
|
|
|
assert.Nil(t, err) |
1491
|
|
|
assert.IsType(t, &http.Response{}, res.Response) |
1492
|
|
|
assert.Equal(t, http.StatusNoContent, res.StatusCode) |
1493
|
|
|
} |
1494
|
|
|
}) |
1495
|
|
|
} |
1496
|
|
|
} |
1497
|
|
|
|