diff options
author | Ethan Koenig <ethantkoenig@gmail.com> | 2017-12-25 18:25:16 -0500 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2017-12-26 01:25:16 +0200 |
commit | 4c9341f689e840df30db3e227498a30fdb5b88ef (patch) | |
tree | 6a619eee5cee0bc9e988019e0abd521acc57c184 /models/issue_test.go | |
parent | fabf3f2fc29e143dabefd504cda78d3f47807d2c (diff) | |
download | gitea-4c9341f689e840df30db3e227498a30fdb5b88ef.tar.gz gitea-4c9341f689e840df30db3e227498a30fdb5b88ef.zip |
Fix bugs in issue dashboard stats (#3073)
Diffstat (limited to 'models/issue_test.go')
-rw-r--r-- | models/issue_test.go | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/models/issue_test.go b/models/issue_test.go index 47bb4feeaa..851fe684fb 100644 --- a/models/issue_test.go +++ b/models/issue_test.go @@ -168,3 +168,114 @@ func TestUpdateIssueCols(t *testing.T) { assert.EqualValues(t, prevContent, updatedIssue.Content) AssertInt64InRange(t, now, then, int64(updatedIssue.UpdatedUnix)) } + +func TestIssues(t *testing.T) { + assert.NoError(t, PrepareTestDatabase()) + for _, test := range []struct { + Opts IssuesOptions + ExpectedIssueIDs []int64 + }{ + { + IssuesOptions{ + AssigneeID: 1, + SortType: "oldest", + }, + []int64{1, 6}, + }, + { + IssuesOptions{ + RepoIDs: []int64{1, 3}, + SortType: "oldest", + Page: 1, + PageSize: 4, + }, + []int64{1, 2, 3, 5}, + }, + { + IssuesOptions{ + Labels: "1,2", + Page: 1, + PageSize: 4, + }, + []int64{5, 2, 1}, + }, + } { + issues, err := Issues(&test.Opts) + assert.NoError(t, err) + if assert.Len(t, issues, len(test.ExpectedIssueIDs)) { + for i, issue := range issues { + assert.EqualValues(t, test.ExpectedIssueIDs[i], issue.ID) + } + } + } +} + +func TestGetUserIssueStats(t *testing.T) { + assert.NoError(t, PrepareTestDatabase()) + for _, test := range []struct { + Opts UserIssueStatsOptions + ExpectedIssueStats IssueStats + }{ + { + UserIssueStatsOptions{ + UserID: 1, + RepoID: 1, + FilterMode: FilterModeAll, + }, + IssueStats{ + YourRepositoriesCount: 0, + AssignCount: 1, + CreateCount: 1, + OpenCount: 0, + ClosedCount: 0, + }, + }, + { + UserIssueStatsOptions{ + UserID: 1, + FilterMode: FilterModeAssign, + }, + IssueStats{ + YourRepositoriesCount: 0, + AssignCount: 2, + CreateCount: 2, + OpenCount: 2, + ClosedCount: 0, + }, + }, + { + UserIssueStatsOptions{ + UserID: 1, + FilterMode: FilterModeCreate, + }, + IssueStats{ + YourRepositoriesCount: 0, + AssignCount: 2, + CreateCount: 2, + OpenCount: 2, + ClosedCount: 0, + }, + }, + { + UserIssueStatsOptions{ + UserID: 2, + UserRepoIDs: []int64{1, 2}, + FilterMode: FilterModeAll, + IsClosed: true, + }, + IssueStats{ + YourRepositoriesCount: 2, + AssignCount: 0, + CreateCount: 2, + OpenCount: 1, + ClosedCount: 2, + }, + }, + } { + stats, err := GetUserIssueStats(test.Opts) + if !assert.NoError(t, err) { + continue + } + assert.Equal(t, test.ExpectedIssueStats, *stats) + } +} |