aboutsummaryrefslogtreecommitdiffstats
path: root/models/project/project_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/project/project_test.go')
-rw-r--r--models/project/project_test.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/models/project/project_test.go b/models/project/project_test.go
index 71ceda7aa5..d1a4715653 100644
--- a/models/project/project_test.go
+++ b/models/project/project_test.go
@@ -82,3 +82,42 @@ func TestProject(t *testing.T) {
assert.True(t, projectFromDB.IsClosed)
}
+
+func TestProjectsSort(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+
+ tests := []struct {
+ sortType string
+ wants []int64
+ }{
+ {
+ sortType: "default",
+ wants: []int64{1, 3, 2, 4},
+ },
+ {
+ sortType: "oldest",
+ wants: []int64{4, 2, 3, 1},
+ },
+ {
+ sortType: "recentupdate",
+ wants: []int64{1, 3, 2, 4},
+ },
+ {
+ sortType: "leastupdate",
+ wants: []int64{4, 2, 3, 1},
+ },
+ }
+
+ for _, tt := range tests {
+ projects, count, err := FindProjects(db.DefaultContext, SearchOptions{
+ OrderBy: GetSearchOrderByBySortType(tt.sortType),
+ })
+ assert.NoError(t, err)
+ assert.EqualValues(t, int64(4), count)
+ if assert.Len(t, projects, 4) {
+ for i := range projects {
+ assert.EqualValues(t, tt.wants[i], projects[i].ID)
+ }
+ }
+ }
+}