Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

issue_watch_test.go 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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.Equal(t, true, iw.IsWatching)
  14. assert.NoError(t, CreateOrUpdateIssueWatch(1, 1, false))
  15. iw = AssertExistsAndLoadBean(t, &IssueWatch{UserID: 1, IssueID: 1}).(*IssueWatch)
  16. assert.Equal(t, false, iw.IsWatching)
  17. }
  18. func TestGetIssueWatch(t *testing.T) {
  19. assert.NoError(t, PrepareTestDatabase())
  20. _, exists, err := GetIssueWatch(9, 1)
  21. assert.Equal(t, true, exists)
  22. assert.NoError(t, err)
  23. _, exists, err = GetIssueWatch(2, 2)
  24. assert.Equal(t, true, exists)
  25. assert.NoError(t, err)
  26. _, exists, err = GetIssueWatch(3, 1)
  27. assert.Equal(t, false, exists)
  28. assert.NoError(t, err)
  29. }
  30. func TestGetIssueWatchers(t *testing.T) {
  31. assert.NoError(t, PrepareTestDatabase())
  32. iws, err := GetIssueWatchers(1)
  33. assert.NoError(t, err)
  34. // Watcher is inactive, thus 0
  35. assert.Equal(t, 0, len(iws))
  36. iws, err = GetIssueWatchers(2)
  37. assert.NoError(t, err)
  38. assert.Equal(t, 1, len(iws))
  39. iws, err = GetIssueWatchers(5)
  40. assert.NoError(t, err)
  41. assert.Equal(t, 0, len(iws))
  42. }