feat: switch cli indexing to code-first identifiers
This commit is contained in:
@@ -170,20 +170,29 @@ func TestEssentialDelete_MissingProposal(t *testing.T) {
|
||||
|
||||
func TestEssentialList_JSONOutput(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "GET" || r.URL.Path != "/proposes/PRJ-001/essentials" {
|
||||
switch {
|
||||
case r.Method == "GET" && r.URL.Path == "/projects":
|
||||
w.WriteHeader(200)
|
||||
json.NewEncoder(w).Encode([]interface{}{map[string]interface{}{"id": 1, "project_code": "PROJ-001"}})
|
||||
case r.Method == "GET" && r.URL.Path == "/projects/PROJ-001/proposals/PRJ-001":
|
||||
w.WriteHeader(200)
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{"code": "PRJ-001", "project_code": "PROJ-001"})
|
||||
case r.Method == "GET" && r.URL.Path == "/projects/PROJ-001/proposals/PRJ-001/essentials":
|
||||
w.WriteHeader(200)
|
||||
json.NewEncoder(w).Encode([]interface{}{
|
||||
map[string]interface{}{
|
||||
"id": 1,
|
||||
"essential_code": "ESS-001",
|
||||
"proposal_id": 1,
|
||||
"type": "feature",
|
||||
"title": "Add login",
|
||||
"created_at": "2026-03-01",
|
||||
},
|
||||
})
|
||||
default:
|
||||
t.Errorf("unexpected request: %s %s", r.Method, r.URL.Path)
|
||||
w.WriteHeader(404)
|
||||
}
|
||||
w.WriteHeader(200)
|
||||
json.NewEncoder(w).Encode([]interface{}{
|
||||
map[string]interface{}{
|
||||
"id": 1,
|
||||
"essential_code": "ESS-001",
|
||||
"proposal_id": 1,
|
||||
"type": "feature",
|
||||
"title": "Add login",
|
||||
"created_at": "2026-03-01",
|
||||
},
|
||||
})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
@@ -204,16 +213,25 @@ func TestEssentialList_JSONOutput(t *testing.T) {
|
||||
|
||||
func TestEssentialCreate_Success(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "POST" {
|
||||
t.Errorf("expected POST; got: %s", r.Method)
|
||||
switch {
|
||||
case r.Method == "GET" && r.URL.Path == "/projects":
|
||||
w.WriteHeader(200)
|
||||
json.NewEncoder(w).Encode([]interface{}{map[string]interface{}{"id": 1, "project_code": "PROJ-001"}})
|
||||
case r.Method == "GET" && r.URL.Path == "/projects/PROJ-001/proposals/PRJ-001":
|
||||
w.WriteHeader(200)
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{"code": "PRJ-001", "project_code": "PROJ-001"})
|
||||
case r.Method == "POST" && r.URL.Path == "/projects/PROJ-001/proposals/PRJ-001/essentials":
|
||||
w.WriteHeader(200)
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"id": 1,
|
||||
"essential_code": "ESS-001",
|
||||
"title": "Add login",
|
||||
"type": "feature",
|
||||
})
|
||||
default:
|
||||
t.Errorf("unexpected request: %s %s", r.Method, r.URL.Path)
|
||||
w.WriteHeader(404)
|
||||
}
|
||||
w.WriteHeader(200)
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"id": 1,
|
||||
"essential_code": "ESS-001",
|
||||
"title": "Add login",
|
||||
"type": "feature",
|
||||
})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
@@ -234,11 +252,20 @@ func TestEssentialCreate_Success(t *testing.T) {
|
||||
|
||||
func TestEssentialUpdate_Success(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "PATCH" {
|
||||
t.Errorf("expected PATCH; got: %s", r.Method)
|
||||
switch {
|
||||
case r.Method == "GET" && r.URL.Path == "/projects":
|
||||
w.WriteHeader(200)
|
||||
json.NewEncoder(w).Encode([]interface{}{map[string]interface{}{"id": 1, "project_code": "PROJ-001"}})
|
||||
case r.Method == "GET" && r.URL.Path == "/projects/PROJ-001/proposals/PRJ-001":
|
||||
w.WriteHeader(200)
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{"code": "PRJ-001", "project_code": "PROJ-001"})
|
||||
case r.Method == "PATCH" && r.URL.Path == "/projects/PROJ-001/proposals/PRJ-001/essentials/ESS-001":
|
||||
w.WriteHeader(200)
|
||||
w.Write([]byte(`{}`))
|
||||
default:
|
||||
t.Errorf("unexpected request: %s %s", r.Method, r.URL.Path)
|
||||
w.WriteHeader(404)
|
||||
}
|
||||
w.WriteHeader(200)
|
||||
w.Write([]byte(`{}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
@@ -259,11 +286,20 @@ func TestEssentialUpdate_Success(t *testing.T) {
|
||||
|
||||
func TestEssentialDelete_Success(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "DELETE" {
|
||||
t.Errorf("expected DELETE; got: %s", r.Method)
|
||||
switch {
|
||||
case r.Method == "GET" && r.URL.Path == "/projects":
|
||||
w.WriteHeader(200)
|
||||
json.NewEncoder(w).Encode([]interface{}{map[string]interface{}{"id": 1, "project_code": "PROJ-001"}})
|
||||
case r.Method == "GET" && r.URL.Path == "/projects/PROJ-001/proposals/PRJ-001":
|
||||
w.WriteHeader(200)
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{"code": "PRJ-001", "project_code": "PROJ-001"})
|
||||
case r.Method == "DELETE" && r.URL.Path == "/projects/PROJ-001/proposals/PRJ-001/essentials/ESS-001":
|
||||
w.WriteHeader(200)
|
||||
w.Write([]byte(`{}`))
|
||||
default:
|
||||
t.Errorf("unexpected request: %s %s", r.Method, r.URL.Path)
|
||||
w.WriteHeader(404)
|
||||
}
|
||||
w.WriteHeader(200)
|
||||
w.Write([]byte(`{}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
@@ -306,20 +342,29 @@ func TestProposalAccept_MissingMilestone(t *testing.T) {
|
||||
|
||||
func TestProposalAccept_Success(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "POST" || r.URL.Path != "/proposes/PRJ-001/accept" {
|
||||
switch {
|
||||
case r.Method == "GET" && r.URL.Path == "/projects":
|
||||
w.WriteHeader(200)
|
||||
json.NewEncoder(w).Encode([]interface{}{map[string]interface{}{"id": 1, "project_code": "PROJ-001"}})
|
||||
case r.Method == "GET" && r.URL.Path == "/projects/PROJ-001/proposals/PRJ-001":
|
||||
w.WriteHeader(200)
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{"code": "PRJ-001", "project_code": "PROJ-001"})
|
||||
case r.Method == "POST" && r.URL.Path == "/projects/PROJ-001/proposals/PRJ-001/accept":
|
||||
var body map[string]interface{}
|
||||
json.NewDecoder(r.Body).Decode(&body)
|
||||
if body["milestone_code"] != "MS-001" {
|
||||
t.Errorf("expected milestone_code=MS-001; got: %v", body["milestone_code"])
|
||||
}
|
||||
w.WriteHeader(200)
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"code": "PRJ-001",
|
||||
"status": "Accepted",
|
||||
"tasks": []interface{}{},
|
||||
})
|
||||
default:
|
||||
t.Errorf("unexpected request: %s %s", r.Method, r.URL.Path)
|
||||
w.WriteHeader(404)
|
||||
}
|
||||
var body map[string]interface{}
|
||||
json.NewDecoder(r.Body).Decode(&body)
|
||||
if body["milestone_code"] != "MS-001" {
|
||||
t.Errorf("expected milestone_code=MS-001; got: %v", body["milestone_code"])
|
||||
}
|
||||
w.WriteHeader(200)
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"code": "PRJ-001",
|
||||
"status": "Accepted",
|
||||
"tasks": []interface{}{},
|
||||
})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
@@ -421,7 +466,7 @@ func TestTaskCreate_StoryTypeOnlyRestricted(t *testing.T) {
|
||||
|
||||
func TestProposalList_Success(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "GET" || r.URL.Path != "/proposes" {
|
||||
if r.Method != "GET" || r.URL.Path != "/projects/PROJ-001/proposals" {
|
||||
t.Errorf("unexpected request: %s %s", r.Method, r.URL.Path)
|
||||
}
|
||||
w.WriteHeader(200)
|
||||
@@ -444,7 +489,7 @@ func TestProposalList_Success(t *testing.T) {
|
||||
cliPath := filepath.Join(tmpDir, "hf")
|
||||
buildCLI(t, cliPath)
|
||||
|
||||
out, err := runCLIProposal(t, tmpDir, cliPath, "proposal", "list", "--token", "fake")
|
||||
out, err := runCLIProposal(t, tmpDir, cliPath, "proposal", "list", "--token", "fake", "--project", "PROJ-001")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v; out=%s", err, out)
|
||||
}
|
||||
@@ -455,6 +500,9 @@ func TestProposalList_Success(t *testing.T) {
|
||||
|
||||
func TestProposalList_JSONOutput(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "GET" || r.URL.Path != "/projects/PROJ-001/proposals" {
|
||||
t.Errorf("unexpected request: %s %s", r.Method, r.URL.Path)
|
||||
}
|
||||
w.WriteHeader(200)
|
||||
json.NewEncoder(w).Encode([]interface{}{
|
||||
map[string]interface{}{
|
||||
@@ -472,7 +520,7 @@ func TestProposalList_JSONOutput(t *testing.T) {
|
||||
cliPath := filepath.Join(tmpDir, "hf")
|
||||
buildCLI(t, cliPath)
|
||||
|
||||
out, err := runCLIProposal(t, tmpDir, cliPath, "--json", "proposal", "list", "--token", "fake")
|
||||
out, err := runCLIProposal(t, tmpDir, cliPath, "--json", "proposal", "list", "--token", "fake", "--project", "PROJ-001")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v; out=%s", err, out)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user