You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.7 KiB

  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package webhook
  5. import (
  6. "testing"
  7. api "code.gitea.io/gitea/modules/structs"
  8. "github.com/stretchr/testify/assert"
  9. "github.com/stretchr/testify/require"
  10. )
  11. func TestSlackIssuesPayloadOpened(t *testing.T) {
  12. p := issueTestPayload()
  13. p.Action = api.HookIssueOpened
  14. s := new(SlackPayload)
  15. s.Username = p.Sender.UserName
  16. pl, err := s.Issue(p)
  17. require.NoError(t, err)
  18. require.NotNil(t, pl)
  19. 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)
  20. p.Action = api.HookIssueClosed
  21. pl, err = s.Issue(p)
  22. require.NoError(t, err)
  23. require.NotNil(t, pl)
  24. 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)
  25. }
  26. func TestSlackIssueCommentPayload(t *testing.T) {
  27. p := issueCommentTestPayload()
  28. s := new(SlackPayload)
  29. s.Username = p.Sender.UserName
  30. pl, err := s.IssueComment(p)
  31. require.NoError(t, err)
  32. require.NotNil(t, pl)
  33. 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)
  34. }
  35. func TestSlackPullRequestCommentPayload(t *testing.T) {
  36. p := pullRequestCommentTestPayload()
  37. s := new(SlackPayload)
  38. s.Username = p.Sender.UserName
  39. pl, err := s.IssueComment(p)
  40. require.NoError(t, err)
  41. require.NotNil(t, pl)
  42. 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)
  43. }
  44. func TestSlackReleasePayload(t *testing.T) {
  45. p := pullReleaseTestPayload()
  46. s := new(SlackPayload)
  47. s.Username = p.Sender.UserName
  48. pl, err := s.Release(p)
  49. require.NoError(t, err)
  50. require.NotNil(t, pl)
  51. 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)
  52. }
  53. func TestSlackPullRequestPayload(t *testing.T) {
  54. p := pullRequestTestPayload()
  55. s := new(SlackPayload)
  56. s.Username = p.Sender.UserName
  57. pl, err := s.PullRequest(p)
  58. require.NoError(t, err)
  59. require.NotNil(t, pl)
  60. 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)
  61. }