主流程

This commit is contained in:
2026-06-10 17:53:09 +08:00
parent c6f239f424
commit b20435c027
66 changed files with 2779 additions and 1181 deletions
+53 -2
View File
@@ -34,9 +34,9 @@ func mountFullHandler(t *testing.T, ownerToken string, ownerID uuid.UUID) (*fake
pSvc := NewProjectService(repo, nil)
rSvc := NewRequirementService(repo, nil)
iSvc := NewIssueService(repo, nil)
protoSvc := NewPrototypeService(repo, nil)
artSvc := NewArtifactService(repo, nil)
resolver := &fakeResolver{valid: map[string]uuid.UUID{ownerToken: ownerID}}
h := NewHandler(pSvc, rSvc, iSvc, protoSvc, resolver, fakeAdmin{})
h := NewHandler(pSvc, rSvc, iSvc, artSvc, resolver, fakeAdmin{})
r := chi.NewRouter()
r.Use(middleware.RequestID)
h.Mount(r)
@@ -214,3 +214,54 @@ func TestHandler_Requirement_PATCH_WorkspaceID_TriState(t *testing.T) {
t.Cleanup(func() { _ = resp5.Body.Close() })
require.Equal(t, http.StatusBadRequest, resp5.StatusCode)
}
// TestHandler_Artifacts_Routes 验证 artifacts 三条路由:创建 201、list 裸数组 +
// ?phase= 过滤、{phase}/{version} 获取、非法 phase 400。
func TestHandler_Artifacts_Routes(t *testing.T) {
owner := uuid.New()
tok := "tok"
_, h := mountFullHandler(t, tok, owner)
checkStatus(t, h, "POST", "/api/v1/projects/", tok, map[string]any{"slug": "demo", "name": "Demo"}, http.StatusCreated)
checkStatus(t, h, "POST", "/api/v1/projects/demo/requirements", tok, map[string]any{"title": "R"}, http.StatusCreated)
// 创建 planning v1(带 source_message_id)+ auditing v1
resp := doJSON(t, h, "POST", "/api/v1/projects/demo/requirements/1/artifacts", tok,
map[string]any{"phase": "planning", "content": "# plan", "note": "n1", "source_message_id": 7})
require.Equal(t, http.StatusCreated, resp.StatusCode)
created := decodeBodyMap(t, resp)
require.Equal(t, "planning", created["phase"])
require.Equal(t, float64(1), created["version"])
require.Equal(t, float64(7), created["source_message_id"])
checkStatus(t, h, "POST", "/api/v1/projects/demo/requirements/1/artifacts", tok,
map[string]any{"phase": "auditing", "content": "# audit"}, http.StatusCreated)
// 非法 phase → 400
checkStatus(t, h, "POST", "/api/v1/projects/demo/requirements/1/artifacts", tok,
map[string]any{"phase": "implementing", "content": "x"}, http.StatusBadRequest)
// list 裸数组:全量 2 条;?phase=planning 过滤 1 条
respList := doJSON(t, h, "GET", "/api/v1/projects/demo/requirements/1/artifacts", tok, nil)
t.Cleanup(func() { _ = respList.Body.Close() })
require.Equal(t, http.StatusOK, respList.StatusCode)
var all []map[string]any
require.NoError(t, json.NewDecoder(respList.Body).Decode(&all))
require.Len(t, all, 2)
respPlanning := doJSON(t, h, "GET", "/api/v1/projects/demo/requirements/1/artifacts?phase=planning", tok, nil)
t.Cleanup(func() { _ = respPlanning.Body.Close() })
require.Equal(t, http.StatusOK, respPlanning.StatusCode)
var planning []map[string]any
require.NoError(t, json.NewDecoder(respPlanning.Body).Decode(&planning))
require.Len(t, planning, 1)
require.Equal(t, "# plan", planning[0]["content"])
// get by {phase}/{version}
respGet := doJSON(t, h, "GET", "/api/v1/projects/demo/requirements/1/artifacts/planning/1", tok, nil)
got := decodeBodyMap(t, respGet)
require.Equal(t, http.StatusOK, respGet.StatusCode)
require.Equal(t, "# plan", got["content"])
// get 非法 phase → 400;不存在版本 → 404
checkStatus(t, h, "GET", "/api/v1/projects/demo/requirements/1/artifacts/bogus/1", tok, nil, http.StatusBadRequest)
checkStatus(t, h, "GET", "/api/v1/projects/demo/requirements/1/artifacts/planning/9", tok, nil, http.StatusNotFound)
}