mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
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]>
204 lines
5.8 KiB
Go
204 lines
5.8 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package feed
|
|
|
|
import (
|
|
"testing"
|
|
|
|
activities_model "github.com/hanzoai/git/models/activities"
|
|
"github.com/hanzoai/git/models/db"
|
|
repo_model "github.com/hanzoai/git/models/repo"
|
|
"github.com/hanzoai/git/models/unittest"
|
|
user_model "github.com/hanzoai/git/models/user"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetFeeds(t *testing.T) {
|
|
// test with an individual user
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
|
|
|
actions, count, err := GetFeeds(t.Context(), activities_model.GetFeedsOptions{
|
|
RequestedUser: user,
|
|
Actor: user,
|
|
IncludePrivate: true,
|
|
OnlyPerformedBy: false,
|
|
IncludeDeleted: true,
|
|
})
|
|
assert.NoError(t, err)
|
|
if assert.Len(t, actions, 1) {
|
|
assert.EqualValues(t, 1, actions[0].ID)
|
|
assert.Equal(t, user.ID, actions[0].UserID)
|
|
}
|
|
assert.Equal(t, int64(1), count)
|
|
|
|
actions, count, err = GetFeeds(t.Context(), activities_model.GetFeedsOptions{
|
|
RequestedUser: user,
|
|
Actor: user,
|
|
IncludePrivate: false,
|
|
OnlyPerformedBy: false,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Empty(t, actions)
|
|
assert.Equal(t, int64(0), count)
|
|
}
|
|
|
|
func TestGetFeedsForRepos(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
|
privRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
|
|
pubRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 8})
|
|
|
|
// private repo & no login
|
|
actions, count, err := GetFeeds(t.Context(), activities_model.GetFeedsOptions{
|
|
RequestedRepo: privRepo,
|
|
IncludePrivate: true,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Empty(t, actions)
|
|
assert.Equal(t, int64(0), count)
|
|
|
|
// public repo & no login
|
|
actions, count, err = GetFeeds(t.Context(), activities_model.GetFeedsOptions{
|
|
RequestedRepo: pubRepo,
|
|
IncludePrivate: true,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, actions, 1)
|
|
assert.Equal(t, int64(1), count)
|
|
|
|
// private repo and login
|
|
actions, count, err = GetFeeds(t.Context(), activities_model.GetFeedsOptions{
|
|
RequestedRepo: privRepo,
|
|
IncludePrivate: true,
|
|
Actor: user,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, actions, 1)
|
|
assert.Equal(t, int64(1), count)
|
|
|
|
// public repo & login
|
|
actions, count, err = GetFeeds(t.Context(), activities_model.GetFeedsOptions{
|
|
RequestedRepo: pubRepo,
|
|
IncludePrivate: true,
|
|
Actor: user,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, actions, 1)
|
|
assert.Equal(t, int64(1), count)
|
|
}
|
|
|
|
func TestGetFeeds2(t *testing.T) {
|
|
// test with an organization user
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3})
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
|
|
|
actions, count, err := GetFeeds(t.Context(), activities_model.GetFeedsOptions{
|
|
RequestedUser: org,
|
|
Actor: user,
|
|
IncludePrivate: true,
|
|
OnlyPerformedBy: false,
|
|
IncludeDeleted: true,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, actions, 1)
|
|
if assert.Len(t, actions, 1) {
|
|
assert.EqualValues(t, 2, actions[0].ID)
|
|
assert.Equal(t, org.ID, actions[0].UserID)
|
|
}
|
|
assert.Equal(t, int64(1), count)
|
|
|
|
actions, count, err = GetFeeds(t.Context(), activities_model.GetFeedsOptions{
|
|
RequestedUser: org,
|
|
Actor: user,
|
|
IncludePrivate: false,
|
|
OnlyPerformedBy: false,
|
|
IncludeDeleted: true,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Empty(t, actions)
|
|
assert.Equal(t, int64(0), count)
|
|
}
|
|
|
|
func TestGetFeedsCorrupted(t *testing.T) {
|
|
// Now we will not check for corrupted data in the feeds
|
|
// users should run doctor to fix their data
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
|
unittest.AssertExistsAndLoadBean(t, &activities_model.Action{
|
|
ID: 8,
|
|
RepoID: 1700,
|
|
})
|
|
|
|
actions, count, err := GetFeeds(t.Context(), activities_model.GetFeedsOptions{
|
|
RequestedUser: user,
|
|
Actor: user,
|
|
IncludePrivate: true,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, actions, 1)
|
|
assert.Equal(t, int64(1), count)
|
|
}
|
|
|
|
func TestRepoActions(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
|
_ = db.TruncateBeans(t.Context(), &activities_model.Action{})
|
|
for i := range 3 {
|
|
_ = db.Insert(t.Context(), &activities_model.Action{
|
|
UserID: 2 + int64(i),
|
|
ActUserID: 2,
|
|
RepoID: repo.ID,
|
|
OpType: activities_model.ActionCommentIssue,
|
|
})
|
|
}
|
|
count, _ := db.Count[activities_model.Action](t.Context(), &db.ListOptions{})
|
|
assert.EqualValues(t, 3, count)
|
|
actions, _, err := GetFeeds(t.Context(), activities_model.GetFeedsOptions{
|
|
RequestedRepo: repo,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, actions, 1)
|
|
}
|
|
|
|
func TestNotifyWatchers(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
action := &activities_model.Action{
|
|
ActUserID: 8,
|
|
RepoID: 1,
|
|
OpType: activities_model.ActionStarRepo,
|
|
}
|
|
assert.NoError(t, NotifyWatchers(t.Context(), action))
|
|
|
|
// One watchers are inactive, thus action is only created for user 8, 1, 4, 11
|
|
unittest.AssertExistsAndLoadBean(t, &activities_model.Action{
|
|
ActUserID: action.ActUserID,
|
|
UserID: 8,
|
|
RepoID: action.RepoID,
|
|
OpType: action.OpType,
|
|
})
|
|
unittest.AssertExistsAndLoadBean(t, &activities_model.Action{
|
|
ActUserID: action.ActUserID,
|
|
UserID: 1,
|
|
RepoID: action.RepoID,
|
|
OpType: action.OpType,
|
|
})
|
|
unittest.AssertExistsAndLoadBean(t, &activities_model.Action{
|
|
ActUserID: action.ActUserID,
|
|
UserID: 4,
|
|
RepoID: action.RepoID,
|
|
OpType: action.OpType,
|
|
})
|
|
unittest.AssertExistsAndLoadBean(t, &activities_model.Action{
|
|
ActUserID: action.ActUserID,
|
|
UserID: 11,
|
|
RepoID: action.RepoID,
|
|
OpType: action.OpType,
|
|
})
|
|
}
|