c9a4404052
- 公开前端 SPA(根路径 /):首页大搜索框、检索结果、只读商品详情、贡献档案表单 - 公开写入端点 POST /api/public/submissions(无需登录,基础频率限流),投稿进入 submission 待审核队列,不直接写 product - 迁移 0006:submission 投稿表 + community 来源(trust=0.50) - 后台审核队列:列表(待审核/已通过/已驳回) → 查看投稿 → 通过(创建/补全商品 + 记 source=community + 字段级溯源 + 审计 + 重算质量分) / 驳回(记原因) - 公开只读 api 服务内嵌公开 SPA;Dockerfile.prod 增加 node 构建阶段 + 内嵌 dist Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package handler
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestHealthz(t *testing.T) {
|
|
req := httptest.NewRequest(http.MethodGet, "/healthz", nil)
|
|
rec := httptest.NewRecorder()
|
|
|
|
New(nil, nil).Router().ServeHTTP(rec, req)
|
|
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("expected status %d, got %d", http.StatusOK, rec.Code)
|
|
}
|
|
|
|
var body map[string]string
|
|
if err := json.NewDecoder(rec.Body).Decode(&body); err != nil {
|
|
t.Fatalf("failed to decode body: %v", err)
|
|
}
|
|
if body["status"] != "ok" {
|
|
t.Fatalf("expected status ok, got %q", body["status"])
|
|
}
|
|
}
|
|
|
|
func TestPageParams(t *testing.T) {
|
|
cases := []struct {
|
|
query string
|
|
wantPage, wantSz int
|
|
}{
|
|
{"", 1, defaultPageSize},
|
|
{"page=3&size=10", 3, 10},
|
|
{"page=0&size=-5", 1, defaultPageSize},
|
|
{"size=1000", 1, maxPageSize},
|
|
{"page=abc", 1, defaultPageSize},
|
|
}
|
|
for _, c := range cases {
|
|
req := httptest.NewRequest(http.MethodGet, "/?"+c.query, nil)
|
|
page, size := pageParams(req)
|
|
if page != c.wantPage || size != c.wantSz {
|
|
t.Errorf("query %q: got page=%d size=%d, want page=%d size=%d",
|
|
c.query, page, size, c.wantPage, c.wantSz)
|
|
}
|
|
}
|
|
}
|