5
5
package webhook
6
6
7
7
import (
8
+ "net/url"
8
9
"testing"
9
10
10
11
"code.gitea.io/gitea/models"
@@ -15,6 +16,16 @@ import (
15
16
)
16
17
17
18
func TestDingTalkPayload (t * testing.T ) {
19
+ parseRealSingleURL := func (singleURL string ) string {
20
+ if u , err := url .Parse (singleURL ); err == nil {
21
+ assert .Equal (t , "dingtalk" , u .Scheme )
22
+ assert .Equal (t , "dingtalkclient" , u .Host )
23
+ assert .Equal (t , "/page/link" , u .Path )
24
+ return u .Query ().Get ("url" )
25
+ }
26
+ return ""
27
+ }
28
+
18
29
t .Run ("Create" , func (t * testing.T ) {
19
30
p := createTestPayload ()
20
31
@@ -27,7 +38,7 @@ func TestDingTalkPayload(t *testing.T) {
27
38
assert .Equal (t , "[test/repo] branch test created" , pl .(* DingtalkPayload ).ActionCard .Text )
28
39
assert .Equal (t , "[test/repo] branch test created" , pl .(* DingtalkPayload ).ActionCard .Title )
29
40
assert .Equal (t , "view ref test" , pl .(* DingtalkPayload ).ActionCard .SingleTitle )
30
- assert .Equal (t , "http://localhost:3000/test/repo/src/test" , pl .(* DingtalkPayload ).ActionCard .SingleURL )
41
+ assert .Equal (t , "http://localhost:3000/test/repo/src/test" , parseRealSingleURL ( pl .(* DingtalkPayload ).ActionCard .SingleURL ) )
31
42
})
32
43
33
44
t .Run ("Delete" , func (t * testing.T ) {
@@ -42,7 +53,7 @@ func TestDingTalkPayload(t *testing.T) {
42
53
assert .Equal (t , "[test/repo] branch test deleted" , pl .(* DingtalkPayload ).ActionCard .Text )
43
54
assert .Equal (t , "[test/repo] branch test deleted" , pl .(* DingtalkPayload ).ActionCard .Title )
44
55
assert .Equal (t , "view ref test" , pl .(* DingtalkPayload ).ActionCard .SingleTitle )
45
- assert .Equal (t , "http://localhost:3000/test/repo/src/test" , pl .(* DingtalkPayload ).ActionCard .SingleURL )
56
+ assert .Equal (t , "http://localhost:3000/test/repo/src/test" , parseRealSingleURL ( pl .(* DingtalkPayload ).ActionCard .SingleURL ) )
46
57
})
47
58
48
59
t .Run ("Fork" , func (t * testing.T ) {
@@ -57,7 +68,7 @@ func TestDingTalkPayload(t *testing.T) {
57
68
assert .Equal (t , "test/repo2 is forked to test/repo" , pl .(* DingtalkPayload ).ActionCard .Text )
58
69
assert .Equal (t , "test/repo2 is forked to test/repo" , pl .(* DingtalkPayload ).ActionCard .Title )
59
70
assert .Equal (t , "view forked repo test/repo" , pl .(* DingtalkPayload ).ActionCard .SingleTitle )
60
- assert .Equal (t , "http://localhost:3000/test/repo" , pl .(* DingtalkPayload ).ActionCard .SingleURL )
71
+ assert .Equal (t , "http://localhost:3000/test/repo" , parseRealSingleURL ( pl .(* DingtalkPayload ).ActionCard .SingleURL ) )
61
72
})
62
73
63
74
t .Run ("Push" , func (t * testing.T ) {
@@ -72,7 +83,7 @@ func TestDingTalkPayload(t *testing.T) {
72
83
assert .Equal (t , "[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) commit message - user1\r \n [2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) commit message - user1" , pl .(* DingtalkPayload ).ActionCard .Text )
73
84
assert .Equal (t , "[test/repo:test] 2 new commits" , pl .(* DingtalkPayload ).ActionCard .Title )
74
85
assert .Equal (t , "view commit 2020558...2020558" , pl .(* DingtalkPayload ).ActionCard .SingleTitle )
75
- assert .Equal (t , "http://localhost:3000/test/repo/src/test" , pl .(* DingtalkPayload ).ActionCard .SingleURL )
86
+ assert .Equal (t , "http://localhost:3000/test/repo/src/test" , parseRealSingleURL ( pl .(* DingtalkPayload ).ActionCard .SingleURL ) )
76
87
})
77
88
78
89
t .Run ("Issue" , func (t * testing.T ) {
@@ -88,7 +99,7 @@ func TestDingTalkPayload(t *testing.T) {
88
99
assert .Equal (t , "[test/repo] Issue opened: #2 crash by user1\r \n \r \n issue body" , pl .(* DingtalkPayload ).ActionCard .Text )
89
100
assert .Equal (t , "#2 crash" , pl .(* DingtalkPayload ).ActionCard .Title )
90
101
assert .Equal (t , "view issue" , pl .(* DingtalkPayload ).ActionCard .SingleTitle )
91
- assert .Equal (t , "http://localhost:3000/test/repo/issues/2" , pl .(* DingtalkPayload ).ActionCard .SingleURL )
102
+ assert .Equal (t , "http://localhost:3000/test/repo/issues/2" , parseRealSingleURL ( pl .(* DingtalkPayload ).ActionCard .SingleURL ) )
92
103
93
104
p .Action = api .HookIssueClosed
94
105
pl , err = d .Issue (p )
@@ -99,7 +110,7 @@ func TestDingTalkPayload(t *testing.T) {
99
110
assert .Equal (t , "[test/repo] Issue closed: #2 crash by user1" , pl .(* DingtalkPayload ).ActionCard .Text )
100
111
assert .Equal (t , "#2 crash" , pl .(* DingtalkPayload ).ActionCard .Title )
101
112
assert .Equal (t , "view issue" , pl .(* DingtalkPayload ).ActionCard .SingleTitle )
102
- assert .Equal (t , "http://localhost:3000/test/repo/issues/2" , pl .(* DingtalkPayload ).ActionCard .SingleURL )
113
+ assert .Equal (t , "http://localhost:3000/test/repo/issues/2" , parseRealSingleURL ( pl .(* DingtalkPayload ).ActionCard .SingleURL ) )
103
114
})
104
115
105
116
t .Run ("IssueComment" , func (t * testing.T ) {
@@ -114,7 +125,7 @@ func TestDingTalkPayload(t *testing.T) {
114
125
assert .Equal (t , "[test/repo] New comment on issue #2 crash by user1\r \n \r \n more info needed" , pl .(* DingtalkPayload ).ActionCard .Text )
115
126
assert .Equal (t , "#2 crash" , pl .(* DingtalkPayload ).ActionCard .Title )
116
127
assert .Equal (t , "view issue comment" , pl .(* DingtalkPayload ).ActionCard .SingleTitle )
117
- assert .Equal (t , "http://localhost:3000/test/repo/issues/2#issuecomment-4" , pl .(* DingtalkPayload ).ActionCard .SingleURL )
128
+ assert .Equal (t , "http://localhost:3000/test/repo/issues/2#issuecomment-4" , parseRealSingleURL ( pl .(* DingtalkPayload ).ActionCard .SingleURL ) )
118
129
})
119
130
120
131
t .Run ("PullRequest" , func (t * testing.T ) {
@@ -129,7 +140,7 @@ func TestDingTalkPayload(t *testing.T) {
129
140
assert .Equal (t , "[test/repo] Pull request opened: #12 Fix bug by user1\r \n \r \n fixes bug #2" , pl .(* DingtalkPayload ).ActionCard .Text )
130
141
assert .Equal (t , "#12 Fix bug" , pl .(* DingtalkPayload ).ActionCard .Title )
131
142
assert .Equal (t , "view pull request" , pl .(* DingtalkPayload ).ActionCard .SingleTitle )
132
- assert .Equal (t , "http://localhost:3000/test/repo/pulls/12" , pl .(* DingtalkPayload ).ActionCard .SingleURL )
143
+ assert .Equal (t , "http://localhost:3000/test/repo/pulls/12" , parseRealSingleURL ( pl .(* DingtalkPayload ).ActionCard .SingleURL ) )
133
144
})
134
145
135
146
t .Run ("PullRequestComment" , func (t * testing.T ) {
@@ -144,7 +155,7 @@ func TestDingTalkPayload(t *testing.T) {
144
155
assert .Equal (t , "[test/repo] New comment on pull request #12 Fix bug by user1\r \n \r \n changes requested" , pl .(* DingtalkPayload ).ActionCard .Text )
145
156
assert .Equal (t , "#12 Fix bug" , pl .(* DingtalkPayload ).ActionCard .Title )
146
157
assert .Equal (t , "view issue comment" , pl .(* DingtalkPayload ).ActionCard .SingleTitle )
147
- assert .Equal (t , "http://localhost:3000/test/repo/pulls/12#issuecomment-4" , pl .(* DingtalkPayload ).ActionCard .SingleURL )
158
+ assert .Equal (t , "http://localhost:3000/test/repo/pulls/12#issuecomment-4" , parseRealSingleURL ( pl .(* DingtalkPayload ).ActionCard .SingleURL ) )
148
159
})
149
160
150
161
t .Run ("Review" , func (t * testing.T ) {
@@ -160,7 +171,7 @@ func TestDingTalkPayload(t *testing.T) {
160
171
assert .Equal (t , "[test/repo] Pull request review approved : #12 Fix bug\r \n \r \n good job" , pl .(* DingtalkPayload ).ActionCard .Text )
161
172
assert .Equal (t , "[test/repo] Pull request review approved : #12 Fix bug" , pl .(* DingtalkPayload ).ActionCard .Title )
162
173
assert .Equal (t , "view pull request" , pl .(* DingtalkPayload ).ActionCard .SingleTitle )
163
- assert .Equal (t , "http://localhost:3000/test/repo/pulls/12" , pl .(* DingtalkPayload ).ActionCard .SingleURL )
174
+ assert .Equal (t , "http://localhost:3000/test/repo/pulls/12" , parseRealSingleURL ( pl .(* DingtalkPayload ).ActionCard .SingleURL ) )
164
175
})
165
176
166
177
t .Run ("Repository" , func (t * testing.T ) {
@@ -175,7 +186,7 @@ func TestDingTalkPayload(t *testing.T) {
175
186
assert .Equal (t , "[test/repo] Repository created" , pl .(* DingtalkPayload ).ActionCard .Text )
176
187
assert .Equal (t , "[test/repo] Repository created" , pl .(* DingtalkPayload ).ActionCard .Title )
177
188
assert .Equal (t , "view repository" , pl .(* DingtalkPayload ).ActionCard .SingleTitle )
178
- assert .Equal (t , "http://localhost:3000/test/repo" , pl .(* DingtalkPayload ).ActionCard .SingleURL )
189
+ assert .Equal (t , "http://localhost:3000/test/repo" , parseRealSingleURL ( pl .(* DingtalkPayload ).ActionCard .SingleURL ) )
179
190
})
180
191
181
192
t .Run ("Release" , func (t * testing.T ) {
@@ -190,7 +201,7 @@ func TestDingTalkPayload(t *testing.T) {
190
201
assert .Equal (t , "[test/repo] Release created: v1.0 by user1" , pl .(* DingtalkPayload ).ActionCard .Text )
191
202
assert .Equal (t , "[test/repo] Release created: v1.0 by user1" , pl .(* DingtalkPayload ).ActionCard .Title )
192
203
assert .Equal (t , "view release" , pl .(* DingtalkPayload ).ActionCard .SingleTitle )
193
- assert .Equal (t , "http://localhost:3000/api/v1/repos/test/repo/releases/2" , pl .(* DingtalkPayload ).ActionCard .SingleURL )
204
+ assert .Equal (t , "http://localhost:3000/api/v1/repos/test/repo/releases/2" , parseRealSingleURL ( pl .(* DingtalkPayload ).ActionCard .SingleURL ) )
194
205
})
195
206
}
196
207
0 commit comments