package server_test import ( "bytes" "encoding/json" "fmt" "net/http" "net/http/httptest" "testing" "time" "unicode/utf8" "github.com/jackc/pgx/v5/pgxpool" "chat-agent-system/internal/projectworkflow" ) func TestProjectCreate_PG_ChineseNameViaHTTP(t *testing.T) { pool := openPGPoolWithMigrations(t) if pool == nil { return } defer pool.Close() handler, _ := setupPGGovernanceServer(t, pool) token := loginTestUser(t, handler, "zhanggong", "123456") body, _ := json.Marshal(projectworkflow.CreateProjectInput{ Name: fmt.Sprintf("PG Phase5 治理链中文名称测试 %d", time.Now().UnixNano()), DeviceType: "超声手术设备", IntendedUse: "软组织切除", TargetMarket: "NMPA 三类", }) req := httptest.NewRequest(http.MethodPost, "/api/v1/projects", bytes.NewReader(body)) withBearerAuth(req, token) rec := httptest.NewRecorder() handler.ServeHTTP(rec, req) if rec.Code != http.StatusCreated { t.Fatalf("create project with Chinese name: %d %s", rec.Code, rec.Body.String()) } var proj projectworkflow.Project if err := json.Unmarshal(rec.Body.Bytes(), &proj); err != nil { t.Fatalf("decode project: %v", err) } if !utf8.ValidString(proj.Code) { t.Fatalf("project code invalid UTF-8: %q", proj.Code) } t.Cleanup(func() { cleanupProject(t, pool, proj.ID) }) } func cleanupProject(t *testing.T, pool *pgxpool.Pool, projectID int64) { t.Helper() if pool == nil || projectID <= 0 { return } _, _ = pool.Exec(t.Context(), `DELETE FROM projects WHERE id = $1`, projectID) }