Browse Source

Unit tests for issue_list (#1209)

Ethan Koenig 2 years ago
parent
commit
1e3548b7e7
1 changed files with 65 additions and 0 deletions
  1. 65 0
      models/issue_list_test.go

+ 65 - 0
models/issue_list_test.go

@@ -0,0 +1,65 @@
1
+// Copyright 2017 The Gitea Authors. All rights reserved.
2
+// Use of this source code is governed by a MIT-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package models
6
+
7
+import (
8
+	"testing"
9
+
10
+	"github.com/stretchr/testify/assert"
11
+)
12
+
13
+func TestIssueList_LoadRepositories(t *testing.T) {
14
+	assert.NoError(t, PrepareTestDatabase())
15
+
16
+	issueList := IssueList{
17
+		AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue),
18
+		AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue),
19
+		AssertExistsAndLoadBean(t, &Issue{ID: 4}).(*Issue),
20
+	}
21
+
22
+	repos, err := issueList.LoadRepositories()
23
+	assert.NoError(t, err)
24
+	assert.Len(t, repos, 2)
25
+	for _, issue := range issueList {
26
+		assert.EqualValues(t, issue.RepoID, issue.Repo.ID)
27
+	}
28
+}
29
+
30
+func TestIssueList_LoadAttributes(t *testing.T) {
31
+	assert.NoError(t, PrepareTestDatabase())
32
+
33
+	issueList := IssueList{
34
+		AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue),
35
+		AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue),
36
+		AssertExistsAndLoadBean(t, &Issue{ID: 4}).(*Issue),
37
+	}
38
+
39
+	assert.NoError(t, issueList.LoadAttributes())
40
+	for _, issue := range issueList {
41
+		assert.EqualValues(t, issue.RepoID, issue.Repo.ID)
42
+		for _, label := range issue.Labels {
43
+			assert.EqualValues(t, issue.RepoID, label.RepoID)
44
+			AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label.ID})
45
+		}
46
+		if issue.PosterID > 0 {
47
+			assert.EqualValues(t, issue.PosterID, issue.Poster.ID)
48
+		}
49
+		if issue.AssigneeID > 0 {
50
+			assert.EqualValues(t, issue.AssigneeID, issue.Assignee.ID)
51
+		}
52
+		if issue.MilestoneID > 0 {
53
+			assert.EqualValues(t, issue.MilestoneID, issue.Milestone.ID)
54
+		}
55
+		if issue.IsPull {
56
+			assert.EqualValues(t, issue.ID, issue.PullRequest.IssueID)
57
+		}
58
+		for _, attachment := range issue.Attachments {
59
+			assert.EqualValues(t, issue.ID, attachment.IssueID)
60
+		}
61
+		for _, comment := range issue.Comments {
62
+			assert.EqualValues(t, issue.ID, comment.IssueID)
63
+		}
64
+	}
65
+}