Merge pull request #2797 from wucm667/feat/account-list-created-at-column

feat(admin): 账号管理列表新增创建时间列
This commit is contained in:
Wesley Liddick
2026-05-27 22:10:21 +08:00
committed by GitHub
5 changed files with 135 additions and 1 deletions
@@ -0,0 +1,52 @@
package admin
import (
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/require"
)
func setupAccountListRouter() (*gin.Engine, *stubAdminService) {
gin.SetMode(gin.TestMode)
router := gin.New()
adminSvc := newStubAdminService()
handler := NewAccountHandler(adminSvc, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)
router.GET("/api/v1/admin/accounts", handler.List)
return router, adminSvc
}
func TestAccountHandlerListIncludesCreatedAt(t *testing.T) {
router, adminSvc := setupAccountListRouter()
rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/api/v1/admin/accounts?page=1&page_size=20&sort_by=created_at&sort_order=desc", nil)
router.ServeHTTP(rec, req)
require.Equal(t, http.StatusOK, rec.Code)
require.Equal(t, "created_at", adminSvc.lastListAccounts.sortBy)
var payload struct {
Data struct {
Items []struct {
ID int64 `json:"id"`
CreatedAt string `json:"created_at"`
} `json:"items"`
} `json:"data"`
}
require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &payload))
require.Len(t, payload.Data.Items, 1)
createdAt := payload.Data.Items[0].CreatedAt
require.NotEmpty(t, createdAt)
require.True(t, strings.HasSuffix(createdAt, "Z"), "created_at should be serialized as UTC")
parsed, err := time.Parse(time.RFC3339Nano, createdAt)
require.NoError(t, err)
_, offset := parsed.Zone()
require.Equal(t, 0, offset)
}