f99010fae1
CI / lint (push) Failing after 1s
CI / frontend (push) Failing after 1s
CI / scripts (push) Failing after 1s
CI / Go Test (ubuntu-latest) (push) Failing after 0s
CI / frontend-node-25 (push) Failing after 1s
CI / docs (push) Failing after 0s
CI / coverage (push) Failing after 0s
CI / e2e (push) Failing after 0s
Docker / build-and-push (push) Failing after 1s
CI / integration (push) Failing after 4m43s
CI / Go Test (windows-latest) (push) Has been cancelled
CI / Desktop Unit Tests (Windows) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux (arm64)) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Windows) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (aarch64)) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (x86_64)) (push) Has been cancelled
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package server_test
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"go.kenn.io/agentsview/internal/db"
|
|
)
|
|
|
|
func orderedSessionIDs(sessions []db.Session) []string {
|
|
ids := make([]string, len(sessions))
|
|
for i, s := range sessions {
|
|
ids[i] = s.ID
|
|
}
|
|
return ids
|
|
}
|
|
|
|
// TestListSessions_OrderBy exercises the ?order_by / ?descending query params
|
|
// and rejection of an out-of-enum value.
|
|
func TestListSessions_OrderBy(t *testing.T) {
|
|
te := setup(t)
|
|
te.seedSession(t, "s-lo", "p", 2)
|
|
te.seedSession(t, "s-hi", "p", 9)
|
|
|
|
// order_by=messages defaults to ascending.
|
|
w := te.get(t, "/api/v1/sessions?order_by=messages")
|
|
assertStatus(t, w, http.StatusOK)
|
|
resp := decode[sessionListResponse](t, w)
|
|
assert.Equal(t, []string{"s-lo", "s-hi"}, orderedSessionIDs(resp.Sessions))
|
|
|
|
// descending=true flips the order.
|
|
w = te.get(t, "/api/v1/sessions?order_by=messages&descending=true")
|
|
assertStatus(t, w, http.StatusOK)
|
|
resp = decode[sessionListResponse](t, w)
|
|
assert.Equal(t, []string{"s-hi", "s-lo"}, orderedSessionIDs(resp.Sessions))
|
|
|
|
// An out-of-enum order_by is rejected (Huma 422 remapped to 400).
|
|
w = te.get(t, "/api/v1/sessions?order_by=bogus")
|
|
assertStatus(t, w, http.StatusBadRequest)
|
|
}
|