Skip to content

Commit efb8af3

Browse files
[MM-974]: Added testcase fore more functions in webhook.go
1 parent f8d16a8 commit efb8af3

File tree

2 files changed

+608
-11
lines changed

2 files changed

+608
-11
lines changed

server/plugin/test_utils.go

+78-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const (
2121
MockChannelID = "mockChannelID"
2222
MockCreatorID = "mockCreatorID"
2323
MockBotID = "mockBotID"
24+
MockOrg = "mockOrg"
25+
MockSender = "mockSender"
2426
MockPostMessage = "mockPostMessage"
2527
MockOrgRepo = "mockOrg/mockRepo"
2628
MockHead = "mockHead"
@@ -253,22 +255,25 @@ func GetMockDeleteEventWithInvalidType() *github.DeleteEvent {
253255
}
254256
}
255257

256-
func GetMockPullRequestReviewEvent(action, state string) *github.PullRequestReviewEvent {
258+
func GetMockPullRequestReviewEvent(action, state, repo string, isPrivate bool, reviewer, author string) *github.PullRequestReviewEvent {
257259
return &github.PullRequestReviewEvent{
258260
Action: github.String(action),
259261
Repo: &github.Repository{
260-
Name: github.String(MockRepoName),
262+
Name: github.String(repo),
261263
FullName: github.String(MockOrgRepo),
262-
Private: github.Bool(false),
264+
Private: github.Bool(isPrivate),
263265
HTMLURL: github.String(fmt.Sprintf("%s%s", GithubBaseURL, MockOrgRepo)),
264266
},
267+
Sender: &github.User{Login: github.String(reviewer)},
265268
Review: &github.PullRequestReview{
269+
User: &github.User{
270+
Login: github.String(reviewer),
271+
},
266272
State: github.String(state),
267273
},
268-
Sender: &github.User{
269-
Login: github.String(MockUserLogin),
274+
PullRequest: &github.PullRequest{
275+
User: &github.User{Login: github.String(author)},
270276
},
271-
PullRequest: &github.PullRequest{},
272277
}
273278
}
274279

@@ -366,3 +371,70 @@ func GetMockPullRequestEvent(action, repoName string, isPrivate bool, sender, us
366371
RequestedReviewer: &github.User{Login: github.String(user)},
367372
}
368373
}
374+
375+
func GetMockIssuesEvent(action, repoName string, isPrivate bool, author, sender, assignee string) *github.IssuesEvent {
376+
return &github.IssuesEvent{
377+
Action: &action,
378+
Repo: &github.Repository{FullName: &repoName, Private: &isPrivate},
379+
Issue: &github.Issue{User: &github.User{Login: &author}},
380+
Sender: &github.User{Login: &sender},
381+
Assignee: func() *github.User {
382+
if assignee == "" {
383+
return nil
384+
}
385+
return &github.User{Login: &assignee}
386+
}(),
387+
}
388+
}
389+
390+
func GetMockStarEvent(repo, org string, isPrivate bool, sender string) *github.StarEvent {
391+
return &github.StarEvent{
392+
Repo: &github.Repository{
393+
Name: github.String(repo),
394+
Private: github.Bool(isPrivate),
395+
FullName: github.String(fmt.Sprintf("%s/%s", repo, org)),
396+
},
397+
Sender: &github.User{Login: github.String(sender)},
398+
}
399+
}
400+
401+
func GetMockReleaseEvent(repo, org, action, sender string) *github.ReleaseEvent {
402+
return &github.ReleaseEvent{
403+
Action: &action,
404+
Repo: &github.Repository{
405+
Name: github.String(repo),
406+
Owner: &github.User{Login: github.String(org)},
407+
FullName: github.String(fmt.Sprintf("%s/%s", repo, org)),
408+
},
409+
Sender: &github.User{Login: github.String(sender)},
410+
}
411+
}
412+
413+
func GetMockDiscussionEvent(repo, org, sender string) *github.DiscussionEvent {
414+
return &github.DiscussionEvent{
415+
Repo: &github.Repository{
416+
Name: github.String(repo),
417+
Owner: &github.User{Login: github.String(org)},
418+
FullName: github.String(fmt.Sprintf("%s/%s", repo, org)),
419+
},
420+
Sender: &github.User{Login: github.String(sender)},
421+
Discussion: &github.Discussion{
422+
Number: github.Int(123),
423+
},
424+
}
425+
}
426+
427+
func GetMockDiscussionCommentEvent(repo, org, action, sender string) *github.DiscussionCommentEvent {
428+
return &github.DiscussionCommentEvent{
429+
Action: &action,
430+
Repo: &github.Repository{
431+
Name: github.String(repo),
432+
Owner: &github.User{Login: github.String(org)},
433+
FullName: github.String(fmt.Sprintf("%s/%s", repo, org)),
434+
},
435+
Sender: &github.User{Login: github.String(sender)},
436+
Comment: &github.CommentDiscussion{
437+
ID: github.Int64(456),
438+
},
439+
}
440+
}

0 commit comments

Comments
 (0)