@@ -241,19 +241,68 @@ func Test_WebhookIssueComment(t *testing.T) {
241
241
242
242
testAPICreateWebhookForRepo (t , session , "user2" , "repo1" , provider .URL (), "issue_comment" )
243
243
244
- // 2. trigger the webhook
245
- issueURL := testNewIssue (t , session , "user2" , "repo1" , "Title2" , "Description2" )
246
- testIssueAddComment (t , session , issueURL , "issue title2 comment1" , "" )
244
+ t .Run ("create comment" , func (t * testing.T ) {
245
+ // 2. trigger the webhook
246
+ issueURL := testNewIssue (t , session , "user2" , "repo1" , "Title2" , "Description2" )
247
+ testIssueAddComment (t , session , issueURL , "issue title2 comment1" , "" )
248
+
249
+ // 3. validate the webhook is triggered
250
+ assert .Equal (t , "issue_comment" , triggeredEvent )
251
+ assert .Len (t , payloads , 1 )
252
+ assert .EqualValues (t , "created" , payloads [0 ].Action )
253
+ assert .Equal (t , "repo1" , payloads [0 ].Issue .Repo .Name )
254
+ assert .Equal (t , "user2/repo1" , payloads [0 ].Issue .Repo .FullName )
255
+ assert .Equal (t , "Title2" , payloads [0 ].Issue .Title )
256
+ assert .Equal (t , "Description2" , payloads [0 ].Issue .Body )
257
+ assert .Equal (t , "issue title2 comment1" , payloads [0 ].Comment .Body )
258
+ })
247
259
248
- // 3. validate the webhook is triggered
249
- assert .Equal (t , "issue_comment" , triggeredEvent )
250
- assert .Len (t , payloads , 1 )
251
- assert .EqualValues (t , "created" , payloads [0 ].Action )
252
- assert .Equal (t , "repo1" , payloads [0 ].Issue .Repo .Name )
253
- assert .Equal (t , "user2/repo1" , payloads [0 ].Issue .Repo .FullName )
254
- assert .Equal (t , "Title2" , payloads [0 ].Issue .Title )
255
- assert .Equal (t , "Description2" , payloads [0 ].Issue .Body )
256
- assert .Equal (t , "issue title2 comment1" , payloads [0 ].Comment .Body )
260
+ t .Run ("update comment" , func (t * testing.T ) {
261
+ payloads = make ([]api.IssueCommentPayload , 0 , 2 )
262
+ triggeredEvent = ""
263
+
264
+ // 2. trigger the webhook
265
+ issueURL := testNewIssue (t , session , "user2" , "repo1" , "Title3" , "Description3" )
266
+ commentID := testIssueAddComment (t , session , issueURL , "issue title3 comment1" , "" )
267
+ modifiedContent := "issue title2 comment1 - modified"
268
+ req := NewRequestWithValues (t , "POST" , fmt .Sprintf ("/%s/%s/comments/%d" , "user2" , "repo1" , commentID ), map [string ]string {
269
+ "_csrf" : GetUserCSRFToken (t , session ),
270
+ "content" : modifiedContent ,
271
+ })
272
+ session .MakeRequest (t , req , http .StatusOK )
273
+
274
+ // 3. validate the webhook is triggered
275
+ assert .Equal (t , "issue_comment" , triggeredEvent )
276
+ assert .Len (t , payloads , 2 )
277
+ assert .EqualValues (t , "edited" , payloads [1 ].Action )
278
+ assert .Equal (t , "repo1" , payloads [1 ].Issue .Repo .Name )
279
+ assert .Equal (t , "user2/repo1" , payloads [1 ].Issue .Repo .FullName )
280
+ assert .Equal (t , "Title3" , payloads [1 ].Issue .Title )
281
+ assert .Equal (t , "Description3" , payloads [1 ].Issue .Body )
282
+ assert .Equal (t , modifiedContent , payloads [1 ].Comment .Body )
283
+ })
284
+
285
+ t .Run ("Update comment with no content change" , func (t * testing.T ) {
286
+ payloads = make ([]api.IssueCommentPayload , 0 , 2 )
287
+ triggeredEvent = ""
288
+ commentContent := "issue title3 comment1"
289
+
290
+ // 2. trigger the webhook
291
+ issueURL := testNewIssue (t , session , "user2" , "repo1" , "Title3" , "Description3" )
292
+ commentID := testIssueAddComment (t , session , issueURL , commentContent , "" )
293
+
294
+ payloads = make ([]api.IssueCommentPayload , 0 , 2 )
295
+ triggeredEvent = ""
296
+ req := NewRequestWithValues (t , "POST" , fmt .Sprintf ("/%s/%s/comments/%d" , "user2" , "repo1" , commentID ), map [string ]string {
297
+ "_csrf" : GetUserCSRFToken (t , session ),
298
+ "content" : commentContent ,
299
+ })
300
+ session .MakeRequest (t , req , http .StatusOK )
301
+
302
+ // 3. validate the webhook is not triggered because no content change
303
+ assert .Empty (t , triggeredEvent )
304
+ assert .Empty (t , payloads )
305
+ })
257
306
})
258
307
}
259
308
0 commit comments