1
0
Fork 0
forked from forgejo/forgejo

Fix incorrect oldest sort in project list (#25806) (#25835)

Backport #25806 by @yp05327

sort type `oldest` should be `Asc`.
Added a test for this.

I see we have `SearchOrderBy` in db model, but we are using many
different ways to define the sort type.
~Maybe we can improve this later.~
↑ Improved in this PR

Co-authored-by: yp05327 <576951401@qq.com>
This commit is contained in:
Giteabot 2023-07-12 01:22:17 -04:00 committed by GitHub
parent c1a10be07e
commit 052e65e63f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 64 additions and 15 deletions

View file

@ -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)
}
}
}
}