mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-23 05:42:33 +09:00
Adds `sort` and `order` query parameters to all action job list API
endpoints (`/admin/actions/jobs`, `/repos/{owner}/{repo}/actions/jobs`,
`/repos/{owner}/{repo}/actions/runs/{run}/jobs`, `/user/actions/jobs`),
following the existing `OrderByMap` pattern used by repo/user search
endpoints.
- Default is `id` / `asc` (backwards compatible — matches previous DB
natural order)
- Only `id` sort field for now; the map is extensible for future fields
- Returns 422 for invalid sort/order values
- `ToOrders()` returns empty string when `OrderBy` is unset, so internal
callers (webhook dispatch, concurrency checks) are unaffected
Closes: #37666
Supersedes: #37667
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: silverwind <me@silverwind.io>
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package utils
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
"code.gitea.io/gitea/services/contexttest"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestResolveSortOrder(t *testing.T) {
|
|
m := map[string]map[string]db.SearchOrderBy{
|
|
"asc": {"id": "id ASC"},
|
|
"desc": {"id": "id DESC"},
|
|
}
|
|
defaultOrder := db.SearchOrderBy("default")
|
|
|
|
cases := []struct {
|
|
path string
|
|
wantOK bool
|
|
wantOrder db.SearchOrderBy
|
|
wantStatus int
|
|
}{
|
|
{"GET /", true, defaultOrder, 0},
|
|
{"GET /?sort=id", true, "id ASC", 0},
|
|
{"GET /?sort=id&order=desc", true, "id DESC", 0},
|
|
{"GET /?sort=bogus", false, "", http.StatusUnprocessableEntity},
|
|
{"GET /?sort=id&order=bogus", false, "", http.StatusUnprocessableEntity},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.path, func(t *testing.T) {
|
|
ctx, _ := contexttest.MockAPIContext(t, tc.path)
|
|
got, ok := ResolveSortOrder(ctx, m, defaultOrder)
|
|
assert.Equal(t, tc.wantOK, ok)
|
|
assert.Equal(t, tc.wantOrder, got)
|
|
assert.Equal(t, tc.wantStatus, ctx.Resp.WrittenStatus())
|
|
})
|
|
}
|
|
}
|