2019-12-28 09:55:09 +01:00
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package webhook
import (
"testing"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSlackIssuesPayloadOpened ( t * testing . T ) {
p := issueTestPayload ( )
p . Action = api . HookIssueOpened
2020-09-05 04:57:13 +02:00
s := new ( SlackPayload )
s . Username = p . Sender . UserName
pl , err := s . Issue ( p )
2020-07-19 11:53:40 +02:00
require . NoError ( t , err )
2019-12-28 09:55:09 +01:00
require . NotNil ( t , pl )
2020-09-05 04:57:13 +02:00
assert . Equal ( t , "[<http://localhost:3000/test/repo|test/repo>] Issue opened: <http://localhost:3000/test/repo/issues/2|#2 crash> by <https://try.gitea.io/user1|user1>" , pl . ( * SlackPayload ) . Text )
2019-12-28 09:55:09 +01:00
p . Action = api . HookIssueClosed
2020-09-05 04:57:13 +02:00
pl , err = s . Issue ( p )
2020-07-19 11:53:40 +02:00
require . NoError ( t , err )
2019-12-28 09:55:09 +01:00
require . NotNil ( t , pl )
2020-09-05 04:57:13 +02:00
assert . Equal ( t , "[<http://localhost:3000/test/repo|test/repo>] Issue closed: <http://localhost:3000/test/repo/issues/2|#2 crash> by <https://try.gitea.io/user1|user1>" , pl . ( * SlackPayload ) . Text )
2019-12-28 09:55:09 +01:00
}
func TestSlackIssueCommentPayload ( t * testing . T ) {
p := issueCommentTestPayload ( )
2020-09-05 04:57:13 +02:00
s := new ( SlackPayload )
s . Username = p . Sender . UserName
2019-12-28 09:55:09 +01:00
2020-09-05 04:57:13 +02:00
pl , err := s . IssueComment ( p )
2020-07-19 11:53:40 +02:00
require . NoError ( t , err )
2019-12-28 09:55:09 +01:00
require . NotNil ( t , pl )
2020-09-05 04:57:13 +02:00
assert . Equal ( t , "[<http://localhost:3000/test/repo|test/repo>] New comment on issue <http://localhost:3000/test/repo/issues/2|#2 crash> by <https://try.gitea.io/user1|user1>" , pl . ( * SlackPayload ) . Text )
2019-12-28 09:55:09 +01:00
}
func TestSlackPullRequestCommentPayload ( t * testing . T ) {
p := pullRequestCommentTestPayload ( )
2020-09-05 04:57:13 +02:00
s := new ( SlackPayload )
s . Username = p . Sender . UserName
2019-12-28 09:55:09 +01:00
2020-09-05 04:57:13 +02:00
pl , err := s . IssueComment ( p )
2020-07-19 11:53:40 +02:00
require . NoError ( t , err )
2019-12-28 09:55:09 +01:00
require . NotNil ( t , pl )
2020-09-05 04:57:13 +02:00
assert . Equal ( t , "[<http://localhost:3000/test/repo|test/repo>] New comment on pull request <http://localhost:3000/test/repo/pulls/2|#2 Fix bug> by <https://try.gitea.io/user1|user1>" , pl . ( * SlackPayload ) . Text )
2019-12-28 09:55:09 +01:00
}
func TestSlackReleasePayload ( t * testing . T ) {
p := pullReleaseTestPayload ( )
2020-09-05 04:57:13 +02:00
s := new ( SlackPayload )
s . Username = p . Sender . UserName
2019-12-28 09:55:09 +01:00
2020-09-05 04:57:13 +02:00
pl , err := s . Release ( p )
2020-07-19 11:53:40 +02:00
require . NoError ( t , err )
2019-12-28 09:55:09 +01:00
require . NotNil ( t , pl )
2020-09-05 04:57:13 +02:00
assert . Equal ( t , "[<http://localhost:3000/test/repo|test/repo>] Release created: <http://localhost:3000/test/repo/src/v1.0|v1.0> by <https://try.gitea.io/user1|user1>" , pl . ( * SlackPayload ) . Text )
2019-12-28 09:55:09 +01:00
}
func TestSlackPullRequestPayload ( t * testing . T ) {
p := pullRequestTestPayload ( )
2020-09-05 04:57:13 +02:00
s := new ( SlackPayload )
s . Username = p . Sender . UserName
2019-12-28 09:55:09 +01:00
2020-09-05 04:57:13 +02:00
pl , err := s . PullRequest ( p )
2020-07-19 11:53:40 +02:00
require . NoError ( t , err )
2019-12-28 09:55:09 +01:00
require . NotNil ( t , pl )
2020-09-05 04:57:13 +02:00
assert . Equal ( t , "[<http://localhost:3000/test/repo|test/repo>] Pull request opened: <http://localhost:3000/test/repo/pulls/12|#2 Fix bug> by <https://try.gitea.io/user1|user1>" , pl . ( * SlackPayload ) . Text )
2019-12-28 09:55:09 +01:00
}