2017-03-11 08:46:23 +00:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2017-03-11 08:46:23 +00:00
|
|
|
|
2022-06-13 09:37:59 +00:00
|
|
|
package issues_test
|
2017-03-11 08:46:23 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-11-19 08:12:33 +00:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2022-06-13 09:37:59 +00:00
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
2021-11-12 14:36:47 +00:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2024-07-29 09:56:50 +00:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2018-04-29 05:58:47 +00:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
|
2017-03-11 08:46:23 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2024-07-29 09:56:50 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2017-03-11 08:46:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestIssueList_LoadRepositories(t *testing.T) {
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2017-03-11 08:46:23 +00:00
|
|
|
|
2022-06-13 09:37:59 +00:00
|
|
|
issueList := issues_model.IssueList{
|
2022-08-16 02:22:25 +00:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}),
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2}),
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 4}),
|
2017-03-11 08:46:23 +00:00
|
|
|
}
|
|
|
|
|
2022-11-19 08:12:33 +00:00
|
|
|
repos, err := issueList.LoadRepositories(db.DefaultContext)
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, err)
|
2017-03-11 08:46:23 +00:00
|
|
|
assert.Len(t, repos, 2)
|
|
|
|
for _, issue := range issueList {
|
|
|
|
assert.EqualValues(t, issue.RepoID, issue.Repo.ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIssueList_LoadAttributes(t *testing.T) {
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2018-04-29 05:58:47 +00:00
|
|
|
setting.Service.EnableTimetracking = true
|
2022-06-13 09:37:59 +00:00
|
|
|
issueList := issues_model.IssueList{
|
2022-08-16 02:22:25 +00:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}),
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 4}),
|
2017-03-11 08:46:23 +00:00
|
|
|
}
|
|
|
|
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, issueList.LoadAttributes(db.DefaultContext))
|
2017-03-11 08:46:23 +00:00
|
|
|
for _, issue := range issueList {
|
|
|
|
assert.EqualValues(t, issue.RepoID, issue.Repo.ID)
|
|
|
|
for _, label := range issue.Labels {
|
|
|
|
assert.EqualValues(t, issue.RepoID, label.RepoID)
|
2022-06-13 09:37:59 +00:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: label.ID})
|
2017-03-11 08:46:23 +00:00
|
|
|
}
|
|
|
|
if issue.PosterID > 0 {
|
|
|
|
assert.EqualValues(t, issue.PosterID, issue.Poster.ID)
|
|
|
|
}
|
|
|
|
if issue.AssigneeID > 0 {
|
|
|
|
assert.EqualValues(t, issue.AssigneeID, issue.Assignee.ID)
|
|
|
|
}
|
|
|
|
if issue.MilestoneID > 0 {
|
|
|
|
assert.EqualValues(t, issue.MilestoneID, issue.Milestone.ID)
|
|
|
|
}
|
|
|
|
if issue.IsPull {
|
|
|
|
assert.EqualValues(t, issue.ID, issue.PullRequest.IssueID)
|
|
|
|
}
|
|
|
|
for _, attachment := range issue.Attachments {
|
|
|
|
assert.EqualValues(t, issue.ID, attachment.IssueID)
|
|
|
|
}
|
|
|
|
for _, comment := range issue.Comments {
|
|
|
|
assert.EqualValues(t, issue.ID, comment.IssueID)
|
|
|
|
}
|
2018-04-29 05:58:47 +00:00
|
|
|
if issue.ID == int64(1) {
|
|
|
|
assert.Equal(t, int64(400), issue.TotalTrackedTime)
|
2023-06-24 15:31:28 +00:00
|
|
|
assert.NotNil(t, issue.Project)
|
2023-07-12 14:10:35 +00:00
|
|
|
assert.Equal(t, int64(1), issue.Project.ID)
|
2023-06-24 15:31:28 +00:00
|
|
|
} else {
|
|
|
|
assert.Nil(t, issue.Project)
|
2018-04-29 05:58:47 +00:00
|
|
|
}
|
2017-03-11 08:46:23 +00:00
|
|
|
}
|
2024-04-08 13:16:40 +00:00
|
|
|
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, issueList.LoadIsRead(db.DefaultContext, 1))
|
2024-04-08 13:16:40 +00:00
|
|
|
for _, issue := range issueList {
|
|
|
|
assert.Equal(t, issue.ID == 1, issue.IsRead, "unexpected is_read value for issue[%d]", issue.ID)
|
|
|
|
}
|
2017-03-11 08:46:23 +00:00
|
|
|
}
|
2024-07-29 09:56:50 +00:00
|
|
|
|
|
|
|
func TestIssueListLoadUser(t *testing.T) {
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2024-07-29 09:56:50 +00:00
|
|
|
|
|
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{})
|
|
|
|
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
|
|
|
|
|
|
|
for _, testCase := range []struct {
|
|
|
|
poster int64
|
|
|
|
user *user_model.User
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
poster: user_model.ActionsUserID,
|
|
|
|
user: user_model.NewActionsUser(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
poster: user_model.GhostUserID,
|
|
|
|
user: user_model.NewGhostUser(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
poster: doer.ID,
|
|
|
|
user: doer,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
poster: 0,
|
|
|
|
user: user_model.NewGhostUser(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
poster: -200,
|
|
|
|
user: user_model.NewGhostUser(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
poster: 200,
|
|
|
|
user: user_model.NewGhostUser(),
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run(testCase.user.Name, func(t *testing.T) {
|
|
|
|
list := issues_model.IssueList{issue}
|
|
|
|
|
|
|
|
issue.PosterID = testCase.poster
|
|
|
|
issue.Poster = nil
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, list.LoadPosters(db.DefaultContext))
|
2024-07-29 09:56:50 +00:00
|
|
|
require.NotNil(t, issue.Poster)
|
|
|
|
assert.Equal(t, testCase.user.ID, issue.Poster.ID)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|