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.

issue_watch_test.go 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2017 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 models
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestCreateOrUpdateIssueWatch(t *testing.T) {
  10. assert.NoError(t, PrepareTestDatabase())
  11. assert.NoError(t, CreateOrUpdateIssueWatch(3, 1, true))
  12. iw := AssertExistsAndLoadBean(t, &IssueWatch{UserID: 3, IssueID: 1}).(*IssueWatch)
  13. assert.True(t, iw.IsWatching)
  14. assert.NoError(t, CreateOrUpdateIssueWatch(1, 1, false))
  15. iw = AssertExistsAndLoadBean(t, &IssueWatch{UserID: 1, IssueID: 1}).(*IssueWatch)
  16. assert.False(t, iw.IsWatching)
  17. }
  18. func TestGetIssueWatch(t *testing.T) {
  19. assert.NoError(t, PrepareTestDatabase())
  20. _, exists, err := GetIssueWatch(9, 1)
  21. assert.True(t, exists)
  22. assert.NoError(t, err)
  23. iw, exists, err := GetIssueWatch(2, 2)
  24. assert.True(t, exists)
  25. assert.NoError(t, err)
  26. assert.EqualValues(t, false, iw.IsWatching)
  27. _, exists, err = GetIssueWatch(3, 1)
  28. assert.False(t, exists)
  29. assert.NoError(t, err)
  30. }
  31. func TestGetIssueWatchers(t *testing.T) {
  32. assert.NoError(t, PrepareTestDatabase())
  33. iws, err := GetIssueWatchers(1, ListOptions{})
  34. assert.NoError(t, err)
  35. // Watcher is inactive, thus 0
  36. assert.Len(t, iws, 0)
  37. iws, err = GetIssueWatchers(2, ListOptions{})
  38. assert.NoError(t, err)
  39. // Watcher is explicit not watching
  40. assert.Len(t, iws, 0)
  41. iws, err = GetIssueWatchers(5, ListOptions{})
  42. assert.NoError(t, err)
  43. // Issue has no Watchers
  44. assert.Len(t, iws, 0)
  45. iws, err = GetIssueWatchers(7, ListOptions{})
  46. assert.NoError(t, err)
  47. // Issue has one watcher
  48. assert.Len(t, iws, 1)
  49. }