55package webhook
66
77import (
8+ "net/url"
89 "testing"
910
1011 "code.gitea.io/gitea/models"
@@ -15,6 +16,16 @@ import (
1516)
1617
1718func 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+
1829 t .Run ("Create" , func (t * testing.T ) {
1930 p := createTestPayload ()
2031
@@ -27,7 +38,7 @@ func TestDingTalkPayload(t *testing.T) {
2738 assert .Equal (t , "[test/repo] branch test created" , pl .(* DingtalkPayload ).ActionCard .Text )
2839 assert .Equal (t , "[test/repo] branch test created" , pl .(* DingtalkPayload ).ActionCard .Title )
2940 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 ) )
3142 })
3243
3344 t .Run ("Delete" , func (t * testing.T ) {
@@ -42,7 +53,7 @@ func TestDingTalkPayload(t *testing.T) {
4253 assert .Equal (t , "[test/repo] branch test deleted" , pl .(* DingtalkPayload ).ActionCard .Text )
4354 assert .Equal (t , "[test/repo] branch test deleted" , pl .(* DingtalkPayload ).ActionCard .Title )
4455 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 ) )
4657 })
4758
4859 t .Run ("Fork" , func (t * testing.T ) {
@@ -57,7 +68,7 @@ func TestDingTalkPayload(t *testing.T) {
5768 assert .Equal (t , "test/repo2 is forked to test/repo" , pl .(* DingtalkPayload ).ActionCard .Text )
5869 assert .Equal (t , "test/repo2 is forked to test/repo" , pl .(* DingtalkPayload ).ActionCard .Title )
5970 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 ) )
6172 })
6273
6374 t .Run ("Push" , func (t * testing.T ) {
@@ -72,7 +83,7 @@ func TestDingTalkPayload(t *testing.T) {
7283 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 )
7384 assert .Equal (t , "[test/repo:test] 2 new commits" , pl .(* DingtalkPayload ).ActionCard .Title )
7485 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 ) )
7687 })
7788
7889 t .Run ("Issue" , func (t * testing.T ) {
@@ -88,7 +99,7 @@ func TestDingTalkPayload(t *testing.T) {
8899 assert .Equal (t , "[test/repo] Issue opened: #2 crash by user1\r \n \r \n issue body" , pl .(* DingtalkPayload ).ActionCard .Text )
89100 assert .Equal (t , "#2 crash" , pl .(* DingtalkPayload ).ActionCard .Title )
90101 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 ) )
92103
93104 p .Action = api .HookIssueClosed
94105 pl , err = d .Issue (p )
@@ -99,7 +110,7 @@ func TestDingTalkPayload(t *testing.T) {
99110 assert .Equal (t , "[test/repo] Issue closed: #2 crash by user1" , pl .(* DingtalkPayload ).ActionCard .Text )
100111 assert .Equal (t , "#2 crash" , pl .(* DingtalkPayload ).ActionCard .Title )
101112 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 ) )
103114 })
104115
105116 t .Run ("IssueComment" , func (t * testing.T ) {
@@ -114,7 +125,7 @@ func TestDingTalkPayload(t *testing.T) {
114125 assert .Equal (t , "[test/repo] New comment on issue #2 crash by user1\r \n \r \n more info needed" , pl .(* DingtalkPayload ).ActionCard .Text )
115126 assert .Equal (t , "#2 crash" , pl .(* DingtalkPayload ).ActionCard .Title )
116127 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 ) )
118129 })
119130
120131 t .Run ("PullRequest" , func (t * testing.T ) {
@@ -129,7 +140,7 @@ func TestDingTalkPayload(t *testing.T) {
129140 assert .Equal (t , "[test/repo] Pull request opened: #12 Fix bug by user1\r \n \r \n fixes bug #2" , pl .(* DingtalkPayload ).ActionCard .Text )
130141 assert .Equal (t , "#12 Fix bug" , pl .(* DingtalkPayload ).ActionCard .Title )
131142 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 ) )
133144 })
134145
135146 t .Run ("PullRequestComment" , func (t * testing.T ) {
@@ -144,7 +155,7 @@ func TestDingTalkPayload(t *testing.T) {
144155 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 )
145156 assert .Equal (t , "#12 Fix bug" , pl .(* DingtalkPayload ).ActionCard .Title )
146157 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 ) )
148159 })
149160
150161 t .Run ("Review" , func (t * testing.T ) {
@@ -160,7 +171,7 @@ func TestDingTalkPayload(t *testing.T) {
160171 assert .Equal (t , "[test/repo] Pull request review approved : #12 Fix bug\r \n \r \n good job" , pl .(* DingtalkPayload ).ActionCard .Text )
161172 assert .Equal (t , "[test/repo] Pull request review approved : #12 Fix bug" , pl .(* DingtalkPayload ).ActionCard .Title )
162173 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 ) )
164175 })
165176
166177 t .Run ("Repository" , func (t * testing.T ) {
@@ -175,7 +186,7 @@ func TestDingTalkPayload(t *testing.T) {
175186 assert .Equal (t , "[test/repo] Repository created" , pl .(* DingtalkPayload ).ActionCard .Text )
176187 assert .Equal (t , "[test/repo] Repository created" , pl .(* DingtalkPayload ).ActionCard .Title )
177188 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 ) )
179190 })
180191
181192 t .Run ("Release" , func (t * testing.T ) {
@@ -190,7 +201,7 @@ func TestDingTalkPayload(t *testing.T) {
190201 assert .Equal (t , "[test/repo] Release created: v1.0 by user1" , pl .(* DingtalkPayload ).ActionCard .Text )
191202 assert .Equal (t , "[test/repo] Release created: v1.0 by user1" , pl .(* DingtalkPayload ).ActionCard .Title )
192203 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 ) )
194205 })
195206}
196207
0 commit comments