code.gitea.io/gitea@v1.21.7/models/issues/issue_list_test.go (about) 1 // Copyright 2017 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package issues_test 5 6 import ( 7 "testing" 8 9 "code.gitea.io/gitea/models/db" 10 issues_model "code.gitea.io/gitea/models/issues" 11 "code.gitea.io/gitea/models/unittest" 12 "code.gitea.io/gitea/modules/setting" 13 14 "github.com/stretchr/testify/assert" 15 ) 16 17 func TestIssueList_LoadRepositories(t *testing.T) { 18 assert.NoError(t, unittest.PrepareTestDatabase()) 19 20 issueList := issues_model.IssueList{ 21 unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}), 22 unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2}), 23 unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 4}), 24 } 25 26 repos, err := issueList.LoadRepositories(db.DefaultContext) 27 assert.NoError(t, err) 28 assert.Len(t, repos, 2) 29 for _, issue := range issueList { 30 assert.EqualValues(t, issue.RepoID, issue.Repo.ID) 31 } 32 } 33 34 func TestIssueList_LoadAttributes(t *testing.T) { 35 assert.NoError(t, unittest.PrepareTestDatabase()) 36 setting.Service.EnableTimetracking = true 37 issueList := issues_model.IssueList{ 38 unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}), 39 unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 4}), 40 } 41 42 assert.NoError(t, issueList.LoadAttributes(db.DefaultContext)) 43 for _, issue := range issueList { 44 assert.EqualValues(t, issue.RepoID, issue.Repo.ID) 45 for _, label := range issue.Labels { 46 assert.EqualValues(t, issue.RepoID, label.RepoID) 47 unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: label.ID}) 48 } 49 if issue.PosterID > 0 { 50 assert.EqualValues(t, issue.PosterID, issue.Poster.ID) 51 } 52 if issue.AssigneeID > 0 { 53 assert.EqualValues(t, issue.AssigneeID, issue.Assignee.ID) 54 } 55 if issue.MilestoneID > 0 { 56 assert.EqualValues(t, issue.MilestoneID, issue.Milestone.ID) 57 } 58 if issue.IsPull { 59 assert.EqualValues(t, issue.ID, issue.PullRequest.IssueID) 60 } 61 for _, attachment := range issue.Attachments { 62 assert.EqualValues(t, issue.ID, attachment.IssueID) 63 } 64 for _, comment := range issue.Comments { 65 assert.EqualValues(t, issue.ID, comment.IssueID) 66 } 67 if issue.ID == int64(1) { 68 assert.Equal(t, int64(400), issue.TotalTrackedTime) 69 assert.NotNil(t, issue.Project) 70 assert.Equal(t, int64(1), issue.Project.ID) 71 } else { 72 assert.Nil(t, issue.Project) 73 } 74 } 75 }