diff options
Diffstat (limited to 'services/webhook/general_test.go')
-rw-r--r-- | services/webhook/general_test.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/services/webhook/general_test.go b/services/webhook/general_test.go index 4d73afe060..4acf51ac71 100644 --- a/services/webhook/general_test.go +++ b/services/webhook/general_test.go @@ -195,6 +195,22 @@ func pullRequestCommentTestPayload() *api.IssueCommentPayload { } } +func wikiTestPayload() *api.WikiPayload { + return &api.WikiPayload{ + Repository: &api.Repository{ + HTMLURL: "http://localhost:3000/test/repo", + Name: "repo", + FullName: "test/repo", + }, + Sender: &api.User{ + UserName: "user1", + AvatarURL: "http://localhost:3000/user1/avatar", + }, + Page: "index", + Comment: "Wiki change comment", + } +} + func pullReleaseTestPayload() *api.ReleasePayload { return &api.ReleasePayload{ Action: api.HookReleasePublished, @@ -469,6 +485,44 @@ func TestGetPullRequestPayloadInfo(t *testing.T) { } } +func TestGetWikiPayloadInfo(t *testing.T) { + p := wikiTestPayload() + + cases := []struct { + action api.HookWikiAction + text string + color int + link string + }{ + { + api.HookWikiCreated, + "[test/repo] New wiki page 'index' (Wiki change comment) by user1", + greenColor, + "index", + }, + { + api.HookWikiEdited, + "[test/repo] Wiki page 'index' edited (Wiki change comment) by user1", + yellowColor, + "index", + }, + { + api.HookWikiDeleted, + "[test/repo] Wiki page 'index' deleted by user1", + redColor, + "index", + }, + } + + for i, c := range cases { + p.Action = c.action + text, color, link := getWikiPayloadInfo(p, noneLinkFormatter, true) + assert.Equal(t, c.text, text, "case %d", i) + assert.Equal(t, c.color, color, "case %d", i) + assert.Equal(t, c.link, link, "case %d", i) + } +} + func TestGetReleasePayloadInfo(t *testing.T) { p := pullReleaseTestPayload() |