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 ( ade00f...013a6a )
by
unknown
01:57 queued 14s
created

mollie/client_links_test.go   A

Size/Duplication

Total Lines 165
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 118
dl 0
loc 165
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B mollie.TestClientLinkService_GetFinalClientLink 0 58 3
B mollie.TestClientLinkService_Create 0 90 6
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 TestClientLinkService_Create(t *testing.T) {
14
	setEnv()
15
	defer unsetEnv()
16
17
	type args struct {
18
		ctx context.Context
19
		cd  CreateClientLink
20
	}
21
22
	cases := []struct {
23
		name    string
24
		args    args
25
		wantErr bool
26
		err     error
27
		handler http.HandlerFunc
28
		pre     func()
29
	}{
30
		{
31
			"create new client link",
32
			args{
33
				context.Background(),
34
				CreateClientLink{},
35
			},
36
			false,
37
			nil,
38
			func(w http.ResponseWriter, r *http.Request) {
39
				testHeader(t, r, AuthHeader, "Bearer token_X12b31ggg23")
40
				testMethod(t, r, "POST")
41
				if _, ok := r.Header[AuthHeader]; !ok {
42
					w.WriteHeader(http.StatusUnauthorized)
43
				}
44
45
				_, _ = w.Write([]byte(testdata.CreateClientLinkResponse))
46
			},
47
			noPre,
48
		},
49
		{
50
			"create client link, an error is returned from the server",
51
			args{
52
				context.Background(),
53
				CreateClientLink{},
54
			},
55
			true,
56
			fmt.Errorf("500 Internal Server Error: An internal server error occurred while processing your request."),
57
			errorHandler,
58
			noPre,
59
		},
60
		{
61
			"create client link, an error occurs when parsing json",
62
			args{
63
				context.Background(),
64
				CreateClientLink{},
65
			},
66
			true,
67
			fmt.Errorf("invalid character 'h' looking for beginning of object key string"),
68
			encodingHandler,
69
			noPre,
70
		},
71
		{
72
			"create client link, invalid url when building request",
73
			args{
74
				context.Background(),
75
				CreateClientLink{},
76
			},
77
			true,
78
			errBadBaseURL,
79
			errorHandler,
80
			crashSrv,
81
		},
82
	}
83
84
	for _, c := range cases {
85
		setup()
86
		defer teardown()
87
		t.Run(c.name, func(t *testing.T) {
88
			tMux.HandleFunc(
89
				"/v2/client-links",
90
				c.handler,
91
			)
92
			c.pre()
93
94
			res, cb, err := tClient.ClientLinks.Create(c.args.ctx, c.args.cd)
95
			if c.wantErr {
96
				assert.Error(t, err)
97
				assert.EqualError(t, err, c.err.Error())
98
			} else {
99
				assert.Nil(t, err)
100
				assert.EqualValues(t, c.args.ctx, res.Request.Context())
101
				assert.IsType(t, &ClientLink{}, cb)
102
				assert.IsType(t, &http.Response{}, res.Response)
103
			}
104
		})
105
	}
106
}
107
108
func TestClientLinkService_GetFinalClientLink(t *testing.T) {
109
	setEnv()
110
	defer unsetEnv()
111
112
	type args struct {
113
		ctx        context.Context
114
		clientLink string
115
		options    *ClientLinkAuthorizeOptions
116
	}
117
	tests := []struct {
118
		name              string
119
		args              args
120
		wantClientLinkURI string
121
	}{
122
		{
123
			"constructs client link finalize step correctly.",
124
			args{
125
				context.Background(),
126
				"https://my.mollie.com/dashboard/client-link/finalize/csr_vZCnNQsV2UtfXxYifWKWH",
127
				&ClientLinkAuthorizeOptions{
128
					ClientID: "app_j9Pakf56Ajta6Y65AkdTtAv",
129
					State:    "unique_string_to_compare",
130
					Scope:    []PermissionGrant{OnboardingRead, OnboardingWrite},
131
				},
132
			},
133
			"https://my.mollie.com/dashboard/client-link/finalize/csr_vZCnNQsV2UtfXxYifWKWH?clientId=app_j9Pakf56Ajta6Y65AkdTtAv&scope=onboarding.read%2Bonbording.write&state=unique_string_to_compare",
134
		},
135
		{
136
			"constructs client link finalize with complex values",
137
			args{
138
				context.Background(),
139
				"https://my.mollie.com/dashboard/client-link/finalize/csr_vZCnNQsV2UtfXxYifWKWH",
140
				&ClientLinkAuthorizeOptions{
141
					ClientID: "",
142
					State:    "\ns\\s\\s\\s\n",
143
					Scope:    []PermissionGrant{},
144
				},
145
			},
146
			"https://my.mollie.com/dashboard/client-link/finalize/csr_vZCnNQsV2UtfXxYifWKWH?state=%0As%5Cs%5Cs%5Cs%0A",
147
		},
148
		{
149
			"constructs client link finalize with no query params",
150
			args{
151
				context.Background(),
152
				"https://my.mollie.com/dashboard/client-link/finalize/csr_vZCnNQsV2UtfXxYifWKWH",
153
				&ClientLinkAuthorizeOptions{},
154
			},
155
			"https://my.mollie.com/dashboard/client-link/finalize/csr_vZCnNQsV2UtfXxYifWKWH?",
156
		},
157
	}
158
159
	setup()
160
	defer teardown()
161
	for _, tt := range tests {
162
		t.Run(tt.name, func(t *testing.T) {
163
			gotClientLinkURI := tClient.ClientLinks.GetFinalClientLink(tt.args.ctx, tt.args.clientLink, tt.args.options)
164
165
			assert.Equal(t, tt.wantClientLinkURI, gotClientLinkURI)
166
		})
167
	}
168
}
169