Files
creator-hub/internal/controlplane/api/creator_route_validation_test.go
T
rogee 6cd4cdc57f refactor(platform): 平台收敛为抖音——移除小红书全链路,监控账号新增画像字段与卡片列表
- 移除小红书:internal/platform/xiaohongshu、controlplane XHS 分支与路由、
  browser_gateway XHS 平台模块与处理器、前端平台选项;migration 038 清理
  XHS 数据并将 creator_* 平台 CHECK 收紧为 douyin
- creator_competitor 新增 follower_count/following_count/aweme_count(仅
  接口定义返回,暂不采集回填);列表接口返回 work_count 与
  latest_published_at(creator_work_source 聚合 MAX(published_at))
- 导入页账号名称列展示作者头像(share job 列表带出 avatar_url)
- 监控账号页改 antd Listy 卡片列表(头像+粉丝/关注/作品/最近发布/同步状态);
  AccountManagementList 收敛为 owned 专用
- 环境模块清理 browser_version 遗留:migration 034 补齐删列,修复 store.go
  中 hub 别名悬空引用,测试 fixture 对齐新 schema
2026-09-24 19:30:28 +08:00

86 lines
3.2 KiB
Go

package api
import (
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
"github.com/gofiber/fiber/v3"
)
func TestCreatorUpdatesStreamStopsOnRequestCancellation(t *testing.T) {
app := fiber.New()
registerCreatorWithServices(app, nil, nil, nil, nil, nil, nil)
request := httptest.NewRequest(http.MethodGet, "/api/creator/updates", http.NoBody)
response, err := app.Test(request, fiber.TestConfig{
Timeout: 200 * time.Millisecond,
FailOnTimeout: false,
})
if err != nil {
t.Fatal(err)
}
defer response.Body.Close()
body, readErr := io.ReadAll(response.Body)
if readErr != nil && !strings.Contains(readErr.Error(), "unexpected EOF") {
t.Fatalf("read stream response: %v", readErr)
}
if response.StatusCode != http.StatusOK {
t.Fatalf("stream status = %d", response.StatusCode)
}
if !strings.Contains(string(body), "retry: 5000") {
t.Fatalf("stream body = %q", body)
}
}
func TestCreatorWriteRoutesRejectMalformedInputBeforeStoreAccess(t *testing.T) {
app := fiber.New()
registerCreatorWithServices(app, nil, nil, nil, nil, nil, nil)
routes := []struct {
method string
path string
}{
{method: http.MethodPut, path: "/api/creator/settings"},
{method: http.MethodPut, path: "/api/creator/accounts/account-1/profile"},
{method: http.MethodPut, path: "/api/creator/accounts/account-1/tags"},
{method: http.MethodPost, path: "/api/creator/accounts/account-1/login-result"},
{method: http.MethodPost, path: "/api/creator/accounts/account-1/big-account"},
{method: http.MethodPost, path: "/api/creator/relations"},
{method: http.MethodPost, path: "/api/creator/accounts/account-1/strategies"},
{method: http.MethodPut, path: "/api/creator/strategies/strategy-1"},
{method: http.MethodPost, path: "/api/creator/competitor-share-jobs"},
{method: http.MethodPut, path: "/api/creator/competitors/competitor-1"},
{method: http.MethodPost, path: "/api/creator/competitors/competitor-1/sync"},
{method: http.MethodPost, path: "/api/creator/test/works"},
{method: http.MethodPost, path: "/api/creator/works/work-1/metrics"},
{method: http.MethodPost, path: "/api/creator/works/work-1/material/rewrite/confirm"},
{method: http.MethodPut, path: "/api/creator/works/work-1/material/rewrite"},
{method: http.MethodPost, path: "/api/creator/test/comments"},
{method: http.MethodPost, path: "/api/creator/rules"},
{method: http.MethodPut, path: "/api/creator/rules/rule-1"},
{method: http.MethodPost, path: "/api/creator/comments/analyze"},
{method: http.MethodPost, path: "/api/creator/comments/comment-1/analyze"},
{method: http.MethodPost, path: "/api/creator/test/events"},
{method: http.MethodPost, path: "/api/creator/events/process"},
{method: http.MethodPost, path: "/api/creator/messages"},
}
for _, route := range routes {
route := route
t.Run(route.method+" "+route.path, func(t *testing.T) {
request := httptest.NewRequest(route.method, route.path, strings.NewReader("{"))
request.Header.Set("Content-Type", "application/json")
response, err := app.Test(request)
if err != nil {
t.Fatal(err)
}
if response.StatusCode != http.StatusBadRequest && response.StatusCode != http.StatusConflict {
t.Fatalf("malformed request status = %d", response.StatusCode)
}
})
}
}