@@ -7,18 +7,133 @@ package webhook
7
7
import (
8
8
"testing"
9
9
10
+ "code.gitea.io/gitea/models"
10
11
api "code.gitea.io/gitea/modules/structs"
12
+
11
13
"github.com/stretchr/testify/assert"
12
14
"github.com/stretchr/testify/require"
13
15
)
14
16
15
- func TestGetTelegramIssuesPayload (t * testing.T ) {
16
- p := issueTestPayload ()
17
- p .Action = api .HookIssueClosed
17
+ func TestTelegramPayload (t * testing.T ) {
18
+ t .Run ("Create" , func (t * testing.T ) {
19
+ p := createTestPayload ()
20
+
21
+ d := new (TelegramPayload )
22
+ pl , err := d .Create (p )
23
+ require .NoError (t , err )
24
+ require .NotNil (t , pl )
25
+ require .IsType (t , & TelegramPayload {}, pl )
26
+
27
+ assert .Equal (t , `[<a href="http://localhost:3000/test/repo">test/repo</a>] branch <a href="http://localhost:3000/test/repo/src/test">test</a> created` , pl .(* TelegramPayload ).Message )
28
+ })
29
+
30
+ t .Run ("Delete" , func (t * testing.T ) {
31
+ p := deleteTestPayload ()
32
+
33
+ d := new (TelegramPayload )
34
+ pl , err := d .Delete (p )
35
+ require .NoError (t , err )
36
+ require .NotNil (t , pl )
37
+ require .IsType (t , & TelegramPayload {}, pl )
38
+
39
+ assert .Equal (t , `[<a href="http://localhost:3000/test/repo">test/repo</a>] branch <a href="http://localhost:3000/test/repo/src/test">test</a> deleted` , pl .(* TelegramPayload ).Message )
40
+ })
41
+
42
+ t .Run ("Fork" , func (t * testing.T ) {
43
+ p := forkTestPayload ()
44
+
45
+ d := new (TelegramPayload )
46
+ pl , err := d .Fork (p )
47
+ require .NoError (t , err )
48
+ require .NotNil (t , pl )
49
+ require .IsType (t , & TelegramPayload {}, pl )
50
+
51
+ assert .Equal (t , `test/repo2 is forked to <a href="http://localhost:3000/test/repo">test/repo</a>` , pl .(* TelegramPayload ).Message )
52
+ })
53
+
54
+ t .Run ("Push" , func (t * testing.T ) {
55
+ p := pushTestPayload ()
56
+
57
+ d := new (TelegramPayload )
58
+ pl , err := d .Push (p )
59
+ require .NoError (t , err )
60
+ require .NotNil (t , pl )
61
+ require .IsType (t , & TelegramPayload {}, pl )
62
+
63
+ assert .Equal (t , "[<a href=\" http://localhost:3000/test/repo\" >test/repo</a>:<a href=\" http://localhost:3000/test/repo/src/test\" >test</a>] 2 new commits\n [<a href=\" http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778\" >2020558</a>] commit message - user1\n [<a href=\" http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778\" >2020558</a>] commit message - user1" , pl .(* TelegramPayload ).Message )
64
+ })
65
+
66
+ t .Run ("Issue" , func (t * testing.T ) {
67
+ p := issueTestPayload ()
68
+
69
+ d := new (TelegramPayload )
70
+ p .Action = api .HookIssueOpened
71
+ pl , err := d .Issue (p )
72
+ require .NoError (t , err )
73
+ require .NotNil (t , pl )
74
+ require .IsType (t , & TelegramPayload {}, pl )
75
+
76
+ assert .Equal (t , "[<a href=\" http://localhost:3000/test/repo\" >test/repo</a>] Issue opened: <a href=\" http://localhost:3000/test/repo/issues/2\" >#2 crash</a> by <a href=\" https://try.gitea.io/user1\" >user1</a>\n \n issue body" , pl .(* TelegramPayload ).Message )
77
+ })
78
+
79
+ t .Run ("IssueComment" , func (t * testing.T ) {
80
+ p := issueCommentTestPayload ()
81
+
82
+ d := new (TelegramPayload )
83
+ pl , err := d .IssueComment (p )
84
+ require .NoError (t , err )
85
+ require .NotNil (t , pl )
86
+ require .IsType (t , & TelegramPayload {}, pl )
87
+
88
+ assert .Equal (t , "[<a href=\" http://localhost:3000/test/repo\" >test/repo</a>] New comment on issue <a href=\" http://localhost:3000/test/repo/issues/2\" >#2 crash</a> by <a href=\" https://try.gitea.io/user1\" >user1</a>\n more info needed" , pl .(* TelegramPayload ).Message )
89
+ })
90
+
91
+ t .Run ("PullRequest" , func (t * testing.T ) {
92
+ p := pullRequestTestPayload ()
93
+
94
+ d := new (TelegramPayload )
95
+ pl , err := d .PullRequest (p )
96
+ require .NoError (t , err )
97
+ require .NotNil (t , pl )
98
+ require .IsType (t , & TelegramPayload {}, pl )
99
+
100
+ assert .Equal (t , "[<a href=\" http://localhost:3000/test/repo\" >test/repo</a>] Pull request opened: <a href=\" http://localhost:3000/test/repo/pulls/12\" >#12 Fix bug</a> by <a href=\" https://try.gitea.io/user1\" >user1</a>\n fixes bug #2" , pl .(* TelegramPayload ).Message )
101
+ })
102
+
103
+ t .Run ("Review" , func (t * testing.T ) {
104
+ p := pullRequestTestPayload ()
105
+ p .Action = api .HookIssueReviewed
106
+
107
+ d := new (TelegramPayload )
108
+ pl , err := d .Review (p , models .HookEventPullRequestReviewApproved )
109
+ require .NoError (t , err )
110
+ require .NotNil (t , pl )
111
+ require .IsType (t , & TelegramPayload {}, pl )
112
+
113
+ assert .Equal (t , "[test/repo] Pull request review approved: #12 Fix bug\n good job" , pl .(* TelegramPayload ).Message )
114
+ })
115
+
116
+ t .Run ("Repository" , func (t * testing.T ) {
117
+ p := repositoryTestPayload ()
118
+
119
+ d := new (TelegramPayload )
120
+ pl , err := d .Repository (p )
121
+ require .NoError (t , err )
122
+ require .NotNil (t , pl )
123
+ require .IsType (t , & TelegramPayload {}, pl )
124
+
125
+ assert .Equal (t , `[<a href="http://localhost:3000/test/repo">test/repo</a>] Repository created` , pl .(* TelegramPayload ).Message )
126
+ })
127
+
128
+ t .Run ("Release" , func (t * testing.T ) {
129
+ p := pullReleaseTestPayload ()
18
130
19
- pl , err := new (TelegramPayload ).Issue (p )
20
- require .NoError (t , err )
21
- require .NotNil (t , pl )
131
+ d := new (TelegramPayload )
132
+ pl , err := d .Release (p )
133
+ require .NoError (t , err )
134
+ require .NotNil (t , pl )
135
+ require .IsType (t , & TelegramPayload {}, pl )
22
136
23
- assert .Equal (t , "[<a href=\" http://localhost:3000/test/repo\" >test/repo</a>] Issue closed: <a href=\" http://localhost:3000/test/repo/issues/2\" >#2 crash</a> by <a href=\" https://try.gitea.io/user1\" >user1</a>\n \n " , pl .(* TelegramPayload ).Message )
137
+ assert .Equal (t , `[<a href="http://localhost:3000/test/repo">test/repo</a>] Release created: <a href="http://localhost:3000/test/repo/src/v1.0">v1.0</a> by <a href="https://try.gitea.io/user1">user1</a>` , pl .(* TelegramPayload ).Message )
138
+ })
24
139
}
0 commit comments