GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 31ed04...164c67 )
by
unknown
01:37
created

mollie.TestSalesInvoicesService_Create   F

Complexity

Conditions 15

Size

Total Lines 260
Code Lines 190

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 15
eloc 190
nop 1
dl 0
loc 260
rs 2.0999
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like mollie.TestSalesInvoicesService_Create often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
package mollie
2
3
import (
4
	"context"
5
	"encoding/json"
6
	"fmt"
7
	"net/http"
8
	"testing"
9
10
	"github.com/VictorAvelar/mollie-api-go/v4/testdata"
11
	"github.com/stretchr/testify/assert"
12
)
13
14
func TestSalesInvoicesService_Create(t *testing.T) {
15
	setEnv()
16
	defer unsetEnv()
17
18
	type args struct {
19
		ctx context.Context
20
		req CreateSalesInvoice
21
	}
22
23
	recipient := SalesInvoiceRecipient{
24
		Type:  ConsumerSalesInvoiceRecipientType,
25
		Email: "[email protected]",
26
		Address: Address{
27
			StreetAndNumber: "Keizersgracht 313",
28
			PostalCode:      "1016 EE",
29
			City:            "Amsterdam",
30
			Country:         "NL",
31
		},
32
		Locale: Dutch,
33
	}
34
35
	lines := []SalesInvoiceLineItem{
36
		{
37
			Description: "Product A",
38
			Quantity:    2,
39
			UnitPrice: Amount{
40
				Currency: "EUR",
41
				Value:    "50.00",
42
			},
43
			VATRate: "21.00",
44
		},
45
	}
46
47
	issuedCreateHandler := func(w http.ResponseWriter, r *http.Request) {
48
		testHeader(t, r, AuthHeader, "Bearer token_X12b31ggg23")
49
		testMethod(t, r, "POST")
50
51
		if _, ok := r.Header[AuthHeader]; !ok {
52
			w.WriteHeader(http.StatusUnauthorized)
53
			return
54
		}
55
56
		var payload map[string]any
57
		if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
58
			w.WriteHeader(http.StatusBadRequest)
59
			return
60
		}
61
62
		status, _ := payload["status"].(string)
63
		paymentDetails, hasPaymentDetails := payload["paymentDetails"].(map[string]any)
64
65
		if hasPaymentDetails {
66
			if source, ok := paymentDetails["source"].(string); !ok || source == "" {
67
				w.Header().Set("Content-Type", "application/json")
68
				w.WriteHeader(http.StatusUnprocessableEntity)
69
				_, _ = w.Write([]byte(`{"status":422,"title":"Unprocessable Entity","detail":"The 'source' field is required when providing paymentDetails.","field":"paymentDetails.source"}`))
70
				return
71
			}
72
73
			if status == string(IssuedSalesInvoiceStatus) {
74
				w.Header().Set("Content-Type", "application/json")
75
				w.WriteHeader(http.StatusUnprocessableEntity)
76
				_, _ = w.Write([]byte(`{"status":422,"title":"Unprocessable Entity","detail":"The 'paymentDetails' field is not allowed when status is 'issued'.","field":"paymentDetails"}`))
77
				return
78
			}
79
		}
80
81
		w.Header().Set("Content-Type", "application/json")
82
		w.WriteHeader(http.StatusCreated)
83
		_, _ = w.Write([]byte(testdata.CreateSalesInvoicesResponse))
84
	}
85
86
	cases := []struct {
87
		name    string
88
		args    args
89
		wantErr bool
90
		err     error
91
		pre     func()
92
		handler http.HandlerFunc
93
	}{
94
		{
95
			name: "create sales invoice successfully",
96
			args: args{
97
				ctx: context.Background(),
98
				req: CreateSalesInvoice{
99
					Status:              DraftSalesInvoiceStatus,
100
					RecipientIdentifier: "customer_123456789",
101
					Recipient:           recipient,
102
					Lines:               lines,
103
				},
104
			},
105
			wantErr: false,
106
			pre:     noPre,
107
			handler: func(w http.ResponseWriter, r *http.Request) {
108
				testHeader(t, r, AuthHeader, "Bearer token_X12b31ggg23")
109
				testMethod(t, r, "POST")
110
111
				if _, ok := r.Header[AuthHeader]; !ok {
112
					w.WriteHeader(http.StatusUnauthorized)
113
				}
114
115
				w.Header().Set("Content-Type", "application/json")
116
				w.WriteHeader(http.StatusCreated)
117
				_, _ = w.Write([]byte(testdata.CreateSalesInvoicesResponse))
118
			},
119
		},
120
		{
121
			"create sales invoice works as expected with access tokens",
122
			args{
123
				context.Background(),
124
				CreateSalesInvoice{
125
					Status:              DraftSalesInvoiceStatus,
126
					RecipientIdentifier: "customer_123456789",
127
					Recipient:           recipient,
128
					Lines:               lines,
129
				},
130
			},
131
			false,
132
			nil,
133
			setAccessToken,
134
			func(w http.ResponseWriter, r *http.Request) {
135
				testHeader(t, r, AuthHeader, "Bearer access_token_test")
136
				testMethod(t, r, "POST")
137
138
				if _, ok := r.Header[AuthHeader]; !ok {
139
					w.WriteHeader(http.StatusUnauthorized)
140
				}
141
142
				w.WriteHeader(http.StatusCreated)
143
				_, _ = w.Write([]byte(testdata.CreateSalesInvoicesResponse))
144
			},
145
		},
146
		{
147
			"create sales invoices error handler",
148
			args{
149
				ctx: context.Background(),
150
				req: CreateSalesInvoice{
151
					Status:              DraftSalesInvoiceStatus,
152
					RecipientIdentifier: "customer_123456789",
153
					Recipient:           recipient,
154
					Lines:               lines,
155
				},
156
			},
157
			true,
158
			fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request"),
159
			noPre,
160
			errorHandler,
161
		},
162
		{
163
			"create sales invoice, an error occurs when parsing json",
164
			args{
165
				ctx: context.Background(),
166
				req: CreateSalesInvoice{
167
					Status:              DraftSalesInvoiceStatus,
168
					RecipientIdentifier: "customer_123456789",
169
					Recipient:           recipient,
170
					Lines:               lines,
171
				},
172
			},
173
			true,
174
			fmt.Errorf("invalid character 'h' looking for beginning of object key string"),
175
			noPre,
176
			encodingHandler,
177
		},
178
		{
179
			"create sales invoice, invalid url when building request",
180
			args{
181
				ctx: context.Background(),
182
				req: CreateSalesInvoice{
183
					Status:              DraftSalesInvoiceStatus,
184
					RecipientIdentifier: "customer_123456789",
185
					Recipient:           recipient,
186
					Lines:               lines,
187
				},
188
			},
189
			true,
190
			errBadBaseURL,
191
			crashSrv,
192
			errorHandler,
193
		},
194
		{
195
			name: "create issued sales invoice, without payment details",
196
			args: args{
197
				ctx: context.Background(),
198
				req: CreateSalesInvoice{
199
					Status:              IssuedSalesInvoiceStatus,
200
					RecipientIdentifier: "customer_123456789",
201
					Recipient:           recipient,
202
					Lines:               lines,
203
				},
204
			},
205
			wantErr: false,
206
			err:     nil,
207
			pre:     noPre,
208
			handler: issuedCreateHandler,
209
		},
210
		{
211
			name: "create issued sales invoice, payment details without source returns error",
212
			args: args{
213
				ctx: context.Background(),
214
				req: CreateSalesInvoice{
215
					Status:              IssuedSalesInvoiceStatus,
216
					RecipientIdentifier: "customer_123456789",
217
					Recipient:           recipient,
218
					Lines:               lines,
219
					PaymentDetails:      &SalesInvoicePaymentDetails{},
220
				},
221
			},
222
			wantErr: true,
223
			err: &BaseError{
224
				Status: http.StatusUnprocessableEntity,
225
				Title:  "Unprocessable Entity",
226
				Detail: "The 'source' field is required when providing paymentDetails.",
227
				Field:  "paymentDetails.source",
228
			},
229
			pre:     noPre,
230
			handler: issuedCreateHandler,
231
		},
232
		{
233
			name: "create issued sales invoice, payment details with source returns error",
234
			args: args{
235
				ctx: context.Background(),
236
				req: CreateSalesInvoice{
237
					Status:              IssuedSalesInvoiceStatus,
238
					RecipientIdentifier: "customer_123456789",
239
					Recipient:           recipient,
240
					Lines:               lines,
241
					PaymentDetails: &SalesInvoicePaymentDetails{
242
						Source: ManualSalesInvoiceSource,
243
					},
244
				},
245
			},
246
			wantErr: true,
247
			err: &BaseError{
248
				Status: http.StatusUnprocessableEntity,
249
				Title:  "Unprocessable Entity",
250
				Detail: "The 'paymentDetails' field is not allowed when status is 'issued'.",
251
				Field:  "paymentDetails",
252
			},
253
			pre:     noPre,
254
			handler: issuedCreateHandler,
255
		},
256
	}
257
258
	for _, c := range cases {
259
		setup()
260
		defer teardown()
261
262
		t.Run(c.name, func(t *testing.T) {
263
			c.pre()
264
			tMux.HandleFunc("/v2/sales-invoices", c.handler)
265
266
			res, m, err := tClient.SalesInvoices.Create(c.args.ctx, c.args.req)
267
			if c.wantErr {
268
				assert.NotNil(t, err)
269
				assert.EqualError(t, err, c.err.Error())
270
			} else {
271
				assert.Nil(t, err)
272
				assert.IsType(t, &SalesInvoice{}, m)
273
				assert.IsType(t, &http.Response{}, res.Response)
274
			}
275
		})
276
	}
277
}
278
279
func TestSalesInvoicesService_Get(t *testing.T) {
280
	setEnv()
281
	defer unsetEnv()
282
283
	type args struct {
284
		ctx context.Context
285
		id  string
286
	}
287
288
	cases := []struct {
289
		name    string
290
		args    args
291
		wantErr bool
292
		err     error
293
		pre     func()
294
		handler http.HandlerFunc
295
	}{
296
		{
297
			name: "get sales invoice successfully",
298
			args: args{
299
				ctx: context.Background(),
300
				id:  "invoice_4Y0eZitmBnQ6IDoMqZQKh",
301
			},
302
			wantErr: false,
303
			pre:     noPre,
304
			handler: func(w http.ResponseWriter, r *http.Request) {
305
				testHeader(t, r, AuthHeader, "Bearer token_X12b31ggg23")
306
				testMethod(t, r, "GET")
307
308
				if _, ok := r.Header[AuthHeader]; !ok {
309
					w.WriteHeader(http.StatusUnauthorized)
310
				}
311
312
				w.Header().Set("Content-Type", "application/json")
313
				w.WriteHeader(http.StatusOK)
314
				_, _ = w.Write([]byte(testdata.GetSalesInvoicesResponse))
315
			},
316
		},
317
		{
318
			"get sales invoice works as expected with access tokens",
319
			args{
320
				context.Background(),
321
				"invoice_4Y0eZitmBnQ6IDoMqZQKh",
322
			},
323
			false,
324
			nil,
325
			setAccessToken,
326
			func(w http.ResponseWriter, r *http.Request) {
327
				testHeader(t, r, AuthHeader, "Bearer access_token_test")
328
				testMethod(t, r, "GET")
329
330
				if _, ok := r.Header[AuthHeader]; !ok {
331
					w.WriteHeader(http.StatusUnauthorized)
332
				}
333
334
				w.WriteHeader(http.StatusOK)
335
				_, _ = w.Write([]byte(testdata.GetSalesInvoicesResponse))
336
			},
337
		},
338
		{
339
			"get sales invoice error handler",
340
			args{
341
				ctx: context.Background(),
342
				id:  "invoice_4Y0eZitmBnQ6IDoMqZQKh",
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
			"get sales invoice, an error occurs when parsing json",
351
			args{
352
				ctx: context.Background(),
353
				id:  "invoice_4Y0eZitmBnQ6IDoMqZQKh",
354
			},
355
			true,
356
			fmt.Errorf("invalid character 'h' looking for beginning of object key string"),
357
			noPre,
358
			encodingHandler,
359
		},
360
		{
361
			"get sales invoice, invalid url when building request",
362
			args{
363
				ctx: context.Background(),
364
				id:  "invoice_4Y0eZitmBnQ6IDoMqZQKh",
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/sales-invoices/"+c.args.id, c.handler)
380
381
			res, m, err := tClient.SalesInvoices.Get(c.args.ctx, c.args.id)
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, &SalesInvoice{}, m)
388
				assert.IsType(t, &http.Response{}, res.Response)
389
			}
390
		})
391
	}
392
}
393
394
func TestSalesInvoicesService_List(t *testing.T) {
395
	setEnv()
396
	defer unsetEnv()
397
398
	type args struct {
399
		ctx  context.Context
400
		opts ListSalesInvoicesOptions
401
	}
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
			name: "list sales invoices successfully",
413
			args: args{
414
				ctx: context.Background(),
415
				opts: ListSalesInvoicesOptions{
416
					Limit: 5,
417
				},
418
			},
419
			wantErr: false,
420
			pre:     noPre,
421
			handler: func(w http.ResponseWriter, r *http.Request) {
422
				testHeader(t, r, AuthHeader, "Bearer token_X12b31ggg23")
423
				testMethod(t, r, "GET")
424
425
				if _, ok := r.Header[AuthHeader]; !ok {
426
					w.WriteHeader(http.StatusUnauthorized)
427
				}
428
429
				w.Header().Set("Content-Type", "application/json")
430
				w.WriteHeader(http.StatusOK)
431
				_, _ = w.Write([]byte(testdata.ListSalesInvoicesResponse))
432
			},
433
		},
434
		{
435
			"list sales invoices works as expected with access tokens",
436
			args{
437
				context.Background(),
438
				ListSalesInvoicesOptions{
439
					Limit: 5,
440
				},
441
			},
442
			false,
443
			nil,
444
			setAccessToken,
445
			func(w http.ResponseWriter, r *http.Request) {
446
				testHeader(t, r, AuthHeader, "Bearer access_token_test")
447
				testMethod(t, r, "GET")
448
449
				if _, ok := r.Header[AuthHeader]; !ok {
450
					w.WriteHeader(http.StatusUnauthorized)
451
				}
452
453
				w.WriteHeader(http.StatusOK)
454
				_, _ = w.Write([]byte(testdata.ListSalesInvoicesResponse))
455
			},
456
		},
457
		{
458
			"list sales invoices error handler",
459
			args{
460
				ctx:  context.Background(),
461
				opts: ListSalesInvoicesOptions{},
462
			},
463
			true,
464
			fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request"),
465
			noPre,
466
			errorHandler,
467
		},
468
		{
469
			"list sales invoices, an error occurs when parsing json",
470
			args{
471
				ctx:  context.Background(),
472
				opts: ListSalesInvoicesOptions{},
473
			},
474
			true,
475
			fmt.Errorf("invalid character 'h' looking for beginning of object key string"),
476
			noPre,
477
			encodingHandler,
478
		},
479
		{
480
			"list sales invoices, invalid url when building request",
481
			args{
482
				ctx:  context.Background(),
483
				opts: ListSalesInvoicesOptions{},
484
			},
485
			true,
486
			errBadBaseURL,
487
			crashSrv,
488
			errorHandler,
489
		},
490
	}
491
492
	for _, c := range cases {
493
		setup()
494
		defer teardown()
495
496
		t.Run(c.name, func(t *testing.T) {
497
			c.pre()
498
			tMux.HandleFunc("/v2/sales-invoices", c.handler)
499
500
			res, m, err := tClient.SalesInvoices.List(c.args.ctx, &c.args.opts)
501
			if c.wantErr {
502
				assert.NotNil(t, err)
503
				assert.EqualError(t, err, c.err.Error())
504
			} else {
505
				assert.Nil(t, err)
506
				assert.IsType(t, &SalesInvoiceList{}, m)
507
				assert.IsType(t, &http.Response{}, res.Response)
508
			}
509
		})
510
	}
511
}
512
513
func TestSalesInvoicesService_Delete(t *testing.T) {
514
	setEnv()
515
	defer unsetEnv()
516
517
	type args struct {
518
		ctx context.Context
519
		id  string
520
	}
521
522
	cases := []struct {
523
		name    string
524
		args    args
525
		wantErr bool
526
		err     error
527
		pre     func()
528
		handler http.HandlerFunc
529
	}{
530
		{
531
			name: "delete sales invoice successfully",
532
			args: args{
533
				ctx: context.Background(),
534
				id:  "invoice_4Y0eZitmBnQ6IDoMqZQKh",
535
			},
536
			wantErr: false,
537
			pre:     noPre,
538
			handler: func(w http.ResponseWriter, r *http.Request) {
539
				testHeader(t, r, AuthHeader, "Bearer token_X12b31ggg23")
540
				testMethod(t, r, "DELETE")
541
542
				if _, ok := r.Header[AuthHeader]; !ok {
543
					w.WriteHeader(http.StatusUnauthorized)
544
				}
545
546
				w.WriteHeader(http.StatusNoContent)
547
			},
548
		},
549
		{
550
			"delete sales invoice works as expected with access tokens",
551
			args{
552
				context.Background(),
553
				"invoice_4Y0eZitmBnQ6IDoMqZQKh",
554
			},
555
			false,
556
			nil,
557
			setAccessToken,
558
			func(w http.ResponseWriter, r *http.Request) {
559
				testHeader(t, r, AuthHeader, "Bearer access_token_test")
560
				testMethod(t, r, "DELETE")
561
562
				if _, ok := r.Header[AuthHeader]; !ok {
563
					w.WriteHeader(http.StatusUnauthorized)
564
				}
565
566
				w.WriteHeader(http.StatusNoContent)
567
			},
568
		},
569
		{
570
			"delete sales invoice error handler",
571
			args{
572
				ctx: context.Background(),
573
				id:  "invoice_4Y0eZitmBnQ6IDoMqZQKh",
574
			},
575
			true,
576
			fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request"),
577
			noPre,
578
			errorHandler,
579
		},
580
		{
581
			"delete sales invoice, invalid url when building request",
582
			args{
583
				ctx: context.Background(),
584
				id:  "invoice_4Y0eZitmBnQ6IDoMqZQKh",
585
			},
586
			true,
587
			errBadBaseURL,
588
			crashSrv,
589
			errorHandler,
590
		},
591
	}
592
593
	for _, c := range cases {
594
		setup()
595
		defer teardown()
596
597
		t.Run(c.name, func(t *testing.T) {
598
			c.pre()
599
			tMux.HandleFunc("/v2/sales-invoices/"+c.args.id, c.handler)
600
601
			res, err := tClient.SalesInvoices.Delete(c.args.ctx, c.args.id)
602
			if c.wantErr {
603
				assert.NotNil(t, err)
604
				assert.EqualError(t, err, c.err.Error())
605
			} else {
606
				assert.Nil(t, err)
607
				assert.IsType(t, &http.Response{}, res.Response)
608
			}
609
		})
610
	}
611
}
612
613
func TestSalesInvoicesService_Update(t *testing.T) {
614
	setEnv()
615
	defer unsetEnv()
616
617
	type args struct {
618
		ctx context.Context
619
		id  string
620
		req UpdateSalesInvoice
621
	}
622
623
	cases := []struct {
624
		name    string
625
		args    args
626
		wantErr bool
627
		err     error
628
		pre     func()
629
		handler http.HandlerFunc
630
	}{
631
		{
632
			name: "update sales invoice successfully",
633
			args: args{
634
				ctx: context.Background(),
635
				id:  "invoice_4Y0eZitmBnQ6IDoMqZQKh",
636
				req: UpdateSalesInvoice{
637
					Status: PaidSalesInvoiceStatus,
638
				},
639
			},
640
			wantErr: false,
641
			pre:     noPre,
642
			handler: func(w http.ResponseWriter, r *http.Request) {
643
				testHeader(t, r, AuthHeader, "Bearer token_X12b31ggg23")
644
				testMethod(t, r, "PATCH")
645
646
				if _, ok := r.Header[AuthHeader]; !ok {
647
					w.WriteHeader(http.StatusUnauthorized)
648
				}
649
650
				w.Header().Set("Content-Type", "application/json")
651
				w.WriteHeader(http.StatusOK)
652
				_, _ = w.Write([]byte(testdata.GetSalesInvoicesResponse))
653
			},
654
		},
655
		{
656
			"update sales invoice works as expected with access tokens",
657
			args{
658
				context.Background(),
659
				"invoice_4Y0eZitmBnQ6IDoMqZQKh",
660
				UpdateSalesInvoice{
661
					Status: PaidSalesInvoiceStatus,
662
				},
663
			},
664
			false,
665
			nil,
666
			setAccessToken,
667
			func(w http.ResponseWriter, r *http.Request) {
668
				testHeader(t, r, AuthHeader, "Bearer access_token_test")
669
				testMethod(t, r, "PATCH")
670
671
				if _, ok := r.Header[AuthHeader]; !ok {
672
					w.WriteHeader(http.StatusUnauthorized)
673
				}
674
675
				w.WriteHeader(http.StatusOK)
676
				_, _ = w.Write([]byte(testdata.GetSalesInvoicesResponse))
677
			},
678
		},
679
		{
680
			"update sales invoice error handler",
681
			args{
682
				ctx: context.Background(),
683
				id:  "invoice_4Y0eZitmBnQ6IDoMqZQKh",
684
				req: UpdateSalesInvoice{
685
					Status: PaidSalesInvoiceStatus,
686
				},
687
			},
688
			true,
689
			fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request"),
690
			noPre,
691
			errorHandler,
692
		},
693
		{
694
			"update sales invoice, an error occurs when parsing json",
695
			args{
696
				ctx: context.Background(),
697
				id:  "invoice_4Y0eZitmBnQ6IDoMqZQKh",
698
				req: UpdateSalesInvoice{
699
					Status: PaidSalesInvoiceStatus,
700
				},
701
			},
702
			true,
703
			fmt.Errorf("invalid character 'h' looking for beginning of object key string"),
704
			noPre,
705
			encodingHandler,
706
		},
707
		{
708
			"update sales invoice, invalid url when building request",
709
			args{
710
				ctx: context.Background(),
711
				id:  "invoice_4Y0eZitmBnQ6IDoMqZQKh",
712
				req: UpdateSalesInvoice{
713
					Status: PaidSalesInvoiceStatus,
714
				},
715
			},
716
			true,
717
			errBadBaseURL,
718
			crashSrv,
719
			errorHandler,
720
		},
721
	}
722
723
	for _, c := range cases {
724
		setup()
725
		defer teardown()
726
727
		t.Run(c.name, func(t *testing.T) {
728
			c.pre()
729
			tMux.HandleFunc("/v2/sales-invoices/"+c.args.id, c.handler)
730
731
			res, m, err := tClient.SalesInvoices.Update(c.args.ctx, c.args.id, c.args.req)
732
			if c.wantErr {
733
				assert.NotNil(t, err)
734
				assert.EqualError(t, err, c.err.Error())
735
			} else {
736
				assert.Nil(t, err)
737
				assert.IsType(t, &SalesInvoice{}, m)
738
				assert.IsType(t, &http.Response{}, res.Response)
739
			}
740
		})
741
	}
742
}
743