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.7KB

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