aboutsummaryrefslogtreecommitdiffstats
path: root/models/issue_list_test.go
blob: 958e074662a865a1d4e75dc01f59e3828726129b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// 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"

	"github.com/stretchr/testify/assert"
)

func TestIssueList_LoadRepositories(t *testing.T) {
	assert.NoError(t, PrepareTestDatabase())

	issueList := IssueList{
		AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue),
		AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue),
		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, PrepareTestDatabase())

	issueList := IssueList{
		AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue),
		AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue),
		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)
			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)
		}
	}
}