2017-03-11 16:46:23 +08:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-28 02:20:29 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
2017-03-11 16:46:23 +08:00
|
|
|
|
2022-06-13 17:37:59 +08:00
|
|
|
package issues_test
|
2017-03-11 16:46:23 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-11-19 16:12:33 +08:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2022-06-13 17:37:59 +08:00
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
2021-11-12 22:36:47 +08:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2018-04-29 13:58:47 +08:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
|
2017-03-11 16:46:23 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIssueList_LoadRepositories(t *testing.T) {
|
2021-11-12 22:36:47 +08:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-03-11 16:46:23 +08:00
|
|
|
|
2022-06-13 17:37:59 +08:00
|
|
|
issueList := issues_model.IssueList{
|
2022-08-16 10:22:25 +08: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 16:46:23 +08:00
|
|
|
}
|
|
|
|
|
2022-11-19 16:12:33 +08:00
|
|
|
repos, err := issueList.LoadRepositories(db.DefaultContext)
|
2017-03-11 16:46:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, repos, 2)
|
|
|
|
for _, issue := range issueList {
|
|
|
|
assert.EqualValues(t, issue.RepoID, issue.Repo.ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIssueList_LoadAttributes(t *testing.T) {
|
2021-11-12 22:36:47 +08:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2018-04-29 13:58:47 +08:00
|
|
|
setting.Service.EnableTimetracking = true
|
2022-06-13 17:37:59 +08:00
|
|
|
issueList := issues_model.IssueList{
|
2022-08-16 10:22:25 +08:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}),
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 4}),
|
2017-03-11 16:46:23 +08:00
|
|
|
}
|
|
|
|
|
2023-07-22 22:14:27 +08:00
|
|
|
assert.NoError(t, issueList.LoadAttributes(db.DefaultContext))
|
2017-03-11 16:46:23 +08: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 17:37:59 +08:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: label.ID})
|
2017-03-11 16:46:23 +08: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 13:58:47 +08:00
|
|
|
if issue.ID == int64(1) {
|
|
|
|
assert.Equal(t, int64(400), issue.TotalTrackedTime)
|
2023-06-24 23:31:28 +08:00
|
|
|
assert.NotNil(t, issue.Project)
|
2023-07-12 22:10:35 +08:00
|
|
|
assert.Equal(t, int64(1), issue.Project.ID)
|
2023-06-24 23:31:28 +08:00
|
|
|
} else {
|
|
|
|
assert.Nil(t, issue.Project)
|
2018-04-29 13:58:47 +08:00
|
|
|
}
|
2017-03-11 16:46:23 +08:00
|
|
|
}
|
|
|
|
}
|