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.
69 lines
2.1 KiB
69 lines
2.1 KiB
8 years ago
|
// Copyright 2017 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.
|
||
|
|
||
3 years ago
|
package issues_test
|
||
8 years ago
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
3 years ago
|
"code.gitea.io/gitea/models/db"
|
||
3 years ago
|
issues_model "code.gitea.io/gitea/models/issues"
|
||
3 years ago
|
"code.gitea.io/gitea/models/unittest"
|
||
3 years ago
|
|
||
8 years ago
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestCreateOrUpdateIssueWatch(t *testing.T) {
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
8 years ago
|
|
||
3 years ago
|
assert.NoError(t, issues_model.CreateOrUpdateIssueWatch(3, 1, true))
|
||
|
iw := unittest.AssertExistsAndLoadBean(t, &issues_model.IssueWatch{UserID: 3, IssueID: 1}).(*issues_model.IssueWatch)
|
||
5 years ago
|
assert.True(t, iw.IsWatching)
|
||
8 years ago
|
|
||
3 years ago
|
assert.NoError(t, issues_model.CreateOrUpdateIssueWatch(1, 1, false))
|
||
|
iw = unittest.AssertExistsAndLoadBean(t, &issues_model.IssueWatch{UserID: 1, IssueID: 1}).(*issues_model.IssueWatch)
|
||
5 years ago
|
assert.False(t, iw.IsWatching)
|
||
8 years ago
|
}
|
||
|
|
||
|
func TestGetIssueWatch(t *testing.T) {
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
8 years ago
|
|
||
3 years ago
|
_, exists, err := issues_model.GetIssueWatch(db.DefaultContext, 9, 1)
|
||
5 years ago
|
assert.True(t, exists)
|
||
8 years ago
|
assert.NoError(t, err)
|
||
8 years ago
|
|
||
3 years ago
|
iw, exists, err := issues_model.GetIssueWatch(db.DefaultContext, 2, 2)
|
||
5 years ago
|
assert.True(t, exists)
|
||
8 years ago
|
assert.NoError(t, err)
|
||
4 years ago
|
assert.False(t, iw.IsWatching)
|
||
8 years ago
|
|
||
3 years ago
|
_, exists, err = issues_model.GetIssueWatch(db.DefaultContext, 3, 1)
|
||
5 years ago
|
assert.False(t, exists)
|
||
8 years ago
|
assert.NoError(t, err)
|
||
8 years ago
|
}
|
||
|
|
||
|
func TestGetIssueWatchers(t *testing.T) {
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
8 years ago
|
|
||
3 years ago
|
iws, err := issues_model.GetIssueWatchers(db.DefaultContext, 1, db.ListOptions{})
|
||
8 years ago
|
assert.NoError(t, err)
|
||
7 years ago
|
// Watcher is inactive, thus 0
|
||
5 years ago
|
assert.Len(t, iws, 0)
|
||
7 years ago
|
|
||
3 years ago
|
iws, err = issues_model.GetIssueWatchers(db.DefaultContext, 2, db.ListOptions{})
|
||
7 years ago
|
assert.NoError(t, err)
|
||
5 years ago
|
// Watcher is explicit not watching
|
||
|
assert.Len(t, iws, 0)
|
||
8 years ago
|
|
||
3 years ago
|
iws, err = issues_model.GetIssueWatchers(db.DefaultContext, 5, db.ListOptions{})
|
||
8 years ago
|
assert.NoError(t, err)
|
||
5 years ago
|
// Issue has no Watchers
|
||
|
assert.Len(t, iws, 0)
|
||
|
|
||
3 years ago
|
iws, err = issues_model.GetIssueWatchers(db.DefaultContext, 7, db.ListOptions{})
|
||
5 years ago
|
assert.NoError(t, err)
|
||
|
// Issue has one watcher
|
||
|
assert.Len(t, iws, 1)
|
||
8 years ago
|
}
|