mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-06 08:26:41 -04:00
81692ceafa
Add ability to add and remove multiple projects per issue and pull request. Resolve #12974 --------- Signed-off-by: Icy Avocado <avocado@ovacoda.com> Co-authored-by: Tyrone Yeh <siryeh@gmail.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: OpenCode (gpt-5.2-codex) <opencode@openai.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Claude (Opus 4.7) <noreply@anthropic.com>
75 lines
2.2 KiB
Go
75 lines
2.2 KiB
Go
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package issues_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
|
"code.gitea.io/gitea/models/unittest"
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestIssueList_LoadRepositories(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
issueList := issues_model.IssueList{
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}),
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2}),
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 4}),
|
|
}
|
|
|
|
repos, err := issueList.LoadRepositories(t.Context())
|
|
assert.NoError(t, err)
|
|
assert.Len(t, repos, 2)
|
|
for _, issue := range issueList {
|
|
assert.Equal(t, issue.RepoID, issue.Repo.ID)
|
|
}
|
|
}
|
|
|
|
func TestIssueList_LoadAttributes(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
setting.Service.EnableTimetracking = true
|
|
issueList := issues_model.IssueList{
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}),
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 4}),
|
|
}
|
|
|
|
assert.NoError(t, issueList.LoadAttributes(t.Context()))
|
|
for _, issue := range issueList {
|
|
assert.Equal(t, issue.RepoID, issue.Repo.ID)
|
|
for _, label := range issue.Labels {
|
|
assert.Equal(t, issue.RepoID, label.RepoID)
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: label.ID})
|
|
}
|
|
if issue.PosterID > 0 {
|
|
assert.Equal(t, issue.PosterID, issue.Poster.ID)
|
|
}
|
|
if issue.AssigneeID > 0 {
|
|
assert.Equal(t, issue.AssigneeID, issue.Assignee.ID)
|
|
}
|
|
if issue.MilestoneID > 0 {
|
|
assert.Equal(t, issue.MilestoneID, issue.Milestone.ID)
|
|
}
|
|
if issue.IsPull {
|
|
assert.Equal(t, issue.ID, issue.PullRequest.IssueID)
|
|
}
|
|
for _, attachment := range issue.Attachments {
|
|
assert.Equal(t, issue.ID, attachment.IssueID)
|
|
}
|
|
for _, comment := range issue.Comments {
|
|
assert.Equal(t, issue.ID, comment.IssueID)
|
|
}
|
|
if issue.ID == int64(1) {
|
|
assert.Equal(t, int64(400), issue.TotalTrackedTime)
|
|
assert.NotEmpty(t, issue.Projects)
|
|
assert.Equal(t, int64(1), issue.Projects[0].ID)
|
|
} else {
|
|
assert.Empty(t, issue.Projects)
|
|
}
|
|
}
|
|
}
|