mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-25 20:04:08 +01:00
a4bfef265d
* Move db related basic functions to models/db * Fix lint * Fix lint * Fix test * Fix lint * Fix lint * revert unnecessary change * Fix test * Fix wrong replace string * Use *Context * Correct committer spelling and fix wrong replaced words Co-authored-by: zeripath <art27@cantab.net>
72 lines
2.1 KiB
Go
72 lines
2.1 KiB
Go
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package models
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestIssueList_LoadRepositories(t *testing.T) {
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
|
|
|
issueList := IssueList{
|
|
db.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue),
|
|
db.AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue),
|
|
db.AssertExistsAndLoadBean(t, &Issue{ID: 4}).(*Issue),
|
|
}
|
|
|
|
repos, err := issueList.LoadRepositories()
|
|
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) {
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
|
setting.Service.EnableTimetracking = true
|
|
issueList := IssueList{
|
|
db.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue),
|
|
db.AssertExistsAndLoadBean(t, &Issue{ID: 4}).(*Issue),
|
|
}
|
|
|
|
assert.NoError(t, issueList.LoadAttributes())
|
|
for _, issue := range issueList {
|
|
assert.EqualValues(t, issue.RepoID, issue.Repo.ID)
|
|
for _, label := range issue.Labels {
|
|
assert.EqualValues(t, issue.RepoID, label.RepoID)
|
|
db.AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label.ID})
|
|
}
|
|
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)
|
|
}
|
|
if issue.ID == int64(1) {
|
|
assert.Equal(t, int64(400), issue.TotalTrackedTime)
|
|
} else if issue.ID == int64(2) {
|
|
assert.Equal(t, int64(3682), issue.TotalTrackedTime)
|
|
}
|
|
}
|
|
}
|