Files
forge/models/issues/issue_watch_test.go
zeekayandHanzo Dev 9a07b4d089 legal: Hanzo AI, Inc. copyright above the upstream notices
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git),
so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form
used by the handful of files that had ours.

Shape is now:

	// Copyright 2026 Hanzo AI, Inc. All rights reserved.
	// Copyright 2015 The Gogs Authors. All rights reserved.
	// Copyright 2019 The Gitea Authors. All rights reserved.
	// SPDX-License-Identifier: MIT

Ours on top, theirs retained verbatim. Retained because MIT requires it, and
separately because they are true — those authors did write that code.

Not renamed to "The Git Authors": Git is a different project under a different
license, and putting its name here would attribute this code to people who have
nothing to do with it. Adding our line is the fix; overwriting theirs would have
been both a licence violation and a false statement.

gofmt still reports import-order drift in some of these files. It predates this
change (verified against a stash) and is left alone rather than burying a
one-line-per-file legal change under 3000 files of unrelated reordering.

Build clean.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-27 13:49:52 -07:00

69 lines
2.0 KiB
Go

// Copyright 2026 Hanzo AI, Inc. All rights reserved.
// Copyright 2017 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package issues_test
import (
"testing"
"github.com/hanzoai/git/models/db"
issues_model "github.com/hanzoai/git/models/issues"
"github.com/hanzoai/git/models/unittest"
"github.com/stretchr/testify/assert"
)
func TestCreateOrUpdateIssueWatch(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
assert.NoError(t, issues_model.CreateOrUpdateIssueWatch(t.Context(), 3, 1, true))
iw := unittest.AssertExistsAndLoadBean(t, &issues_model.IssueWatch{UserID: 3, IssueID: 1})
assert.True(t, iw.IsWatching)
assert.NoError(t, issues_model.CreateOrUpdateIssueWatch(t.Context(), 1, 1, false))
iw = unittest.AssertExistsAndLoadBean(t, &issues_model.IssueWatch{UserID: 1, IssueID: 1})
assert.False(t, iw.IsWatching)
}
func TestGetIssueWatch(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
_, exists, err := issues_model.GetIssueWatch(t.Context(), 9, 1)
assert.True(t, exists)
assert.NoError(t, err)
iw, exists, err := issues_model.GetIssueWatch(t.Context(), 2, 2)
assert.True(t, exists)
assert.NoError(t, err)
assert.False(t, iw.IsWatching)
_, exists, err = issues_model.GetIssueWatch(t.Context(), 3, 1)
assert.False(t, exists)
assert.NoError(t, err)
}
func TestGetIssueWatchers(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
iws, err := issues_model.GetIssueWatchers(t.Context(), 1, db.ListOptions{})
assert.NoError(t, err)
// Watcher is inactive, thus 0
assert.Empty(t, iws)
iws, err = issues_model.GetIssueWatchers(t.Context(), 2, db.ListOptions{})
assert.NoError(t, err)
// Watcher is explicit not watching
assert.Empty(t, iws)
iws, err = issues_model.GetIssueWatchers(t.Context(), 5, db.ListOptions{})
assert.NoError(t, err)
// Issue has no Watchers
assert.Empty(t, iws)
iws, err = issues_model.GetIssueWatchers(t.Context(), 7, db.ListOptions{})
assert.NoError(t, err)
// Issue has one watcher
assert.Len(t, iws, 1)
}