Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-974]: Added testcase fore more functions in webhook.go #857

Open
wants to merge 1 commit into
base: MM-956
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 78 additions & 6 deletions server/plugin/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const (
MockChannelID = "mockChannelID"
MockCreatorID = "mockCreatorID"
MockBotID = "mockBotID"
MockOrg = "mockOrg"
MockSender = "mockSender"
MockPostMessage = "mockPostMessage"
MockOrgRepo = "mockOrg/mockRepo"
MockHead = "mockHead"
Expand Down Expand Up @@ -253,22 +255,25 @@ func GetMockDeleteEventWithInvalidType() *github.DeleteEvent {
}
}

func GetMockPullRequestReviewEvent(action, state string) *github.PullRequestReviewEvent {
func GetMockPullRequestReviewEvent(action, state, repo string, isPrivate bool, reviewer, author string) *github.PullRequestReviewEvent {
return &github.PullRequestReviewEvent{
Action: github.String(action),
Repo: &github.Repository{
Name: github.String(MockRepoName),
Name: github.String(repo),
FullName: github.String(MockOrgRepo),
Private: github.Bool(false),
Private: github.Bool(isPrivate),
HTMLURL: github.String(fmt.Sprintf("%s%s", GithubBaseURL, MockOrgRepo)),
},
Sender: &github.User{Login: github.String(reviewer)},
Review: &github.PullRequestReview{
User: &github.User{
Login: github.String(reviewer),
},
State: github.String(state),
},
Sender: &github.User{
Login: github.String(MockUserLogin),
PullRequest: &github.PullRequest{
User: &github.User{Login: github.String(author)},
},
PullRequest: &github.PullRequest{},
}
}

Expand Down Expand Up @@ -366,3 +371,70 @@ func GetMockPullRequestEvent(action, repoName string, isPrivate bool, sender, us
RequestedReviewer: &github.User{Login: github.String(user)},
}
}

func GetMockIssuesEvent(action, repoName string, isPrivate bool, author, sender, assignee string) *github.IssuesEvent {
return &github.IssuesEvent{
Action: &action,
Repo: &github.Repository{FullName: &repoName, Private: &isPrivate},
Issue: &github.Issue{User: &github.User{Login: &author}},
Sender: &github.User{Login: &sender},
Assignee: func() *github.User {
if assignee == "" {
return nil
}
return &github.User{Login: &assignee}
}(),
}
}

func GetMockStarEvent(repo, org string, isPrivate bool, sender string) *github.StarEvent {
return &github.StarEvent{
Repo: &github.Repository{
Name: github.String(repo),
Private: github.Bool(isPrivate),
FullName: github.String(fmt.Sprintf("%s/%s", repo, org)),
},
Sender: &github.User{Login: github.String(sender)},
}
}

func GetMockReleaseEvent(repo, org, action, sender string) *github.ReleaseEvent {
return &github.ReleaseEvent{
Action: &action,
Repo: &github.Repository{
Name: github.String(repo),
Owner: &github.User{Login: github.String(org)},
FullName: github.String(fmt.Sprintf("%s/%s", repo, org)),
},
Sender: &github.User{Login: github.String(sender)},
}
}

func GetMockDiscussionEvent(repo, org, sender string) *github.DiscussionEvent {
return &github.DiscussionEvent{
Repo: &github.Repository{
Name: github.String(repo),
Owner: &github.User{Login: github.String(org)},
FullName: github.String(fmt.Sprintf("%s/%s", repo, org)),
},
Sender: &github.User{Login: github.String(sender)},
Discussion: &github.Discussion{
Number: github.Int(123),
},
}
}

func GetMockDiscussionCommentEvent(repo, org, action, sender string) *github.DiscussionCommentEvent {
return &github.DiscussionCommentEvent{
Action: &action,
Repo: &github.Repository{
Name: github.String(repo),
Owner: &github.User{Login: github.String(org)},
FullName: github.String(fmt.Sprintf("%s/%s", repo, org)),
},
Sender: &github.User{Login: github.String(sender)},
Comment: &github.CommentDiscussion{
ID: github.Int64(456),
},
}
}
Loading