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
Branch feature/payments-resource-impl... (bdb051)
by Victor Hugo
02:14
created

mollie.TestPaymentsList   C

Complexity

Conditions 10

Size

Total Lines 45
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 31
nop 1
dl 0
loc 45
rs 5.9999
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like mollie.TestPaymentsList 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
	"fmt"
6
	"net/http"
7
	"reflect"
8
	"testing"
9
10
	"github.com/VictorAvelar/mollie-api-go/mollie/testdata"
11
)
12
13
func TestPaymentsList(t *testing.T) {
14
	setup()
15
	defer teardown()
16
	paymentsAPIEndpoint := "/v2/payments"
17
18
	testMux.HandleFunc(paymentsAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
19
		_, ok := r.Header[AuthHeader]
20
		if !ok {
21
			w.WriteHeader(http.StatusUnauthorized)
22
		}
23
		raw := testdata.ListPaymentsExample
24
		fmt.Fprint(w, raw)
25
	})
26
27
	err := testClient.WithAPIKey("dummy-key")
28
	if err != nil {
29
		t.Fatal(err)
30
	}
31
32
	var ctx context.Context
33
34
	tests := []struct {
35
		name    string
36
		want    int
37
		wantErr bool
38
		err     error
39
	}{
40
		{
41
			name:    "test request is successful",
42
			wantErr: false,
43
			err:     nil,
44
		},
45
	}
46
47
	for _, tt := range tests {
48
		t.Run(tt.name, func(t *testing.T) {
49
			_, err := testClient.Payments.List(ctx)
50
			if tt.wantErr && err != nil {
51
				if !reflect.DeepEqual(err, tt.err) {
52
					t.Fatal(err)
53
				}
54
			}
55
56
			if err != tt.err {
57
				t.Errorf("wanted nil, got %+v", err)
58
			}
59
		})
60
	}
61
}
62