Skip to content

Commit 5de6d15

Browse files
committed
chore: remove comments and update tests
1 parent 20319dc commit 5de6d15

File tree

2 files changed

+62
-34
lines changed

2 files changed

+62
-34
lines changed

internal/hbmcp/projects.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,6 @@ func handleListProjects(ctx context.Context, client *hbapi.Client, req mcp.CallT
216216
return mcp.NewToolResultError(fmt.Sprintf("Failed to list projects: %v", err)), nil
217217
}
218218

219-
// Include API tokens in response to allow LLM configuration
220-
221219
// Return JSON response
222220
jsonBytes, err := json.Marshal(response)
223221
if err != nil {
@@ -238,8 +236,6 @@ func handleGetProject(ctx context.Context, client *hbapi.Client, req mcp.CallToo
238236
return mcp.NewToolResultError(fmt.Sprintf("Failed to get project: %v", err)), nil
239237
}
240238

241-
// Include API tokens in response to allow LLM configuration
242-
243239
// Return JSON response
244240
jsonBytes, err := json.Marshal(project)
245241
if err != nil {
@@ -289,8 +285,6 @@ func handleCreateProject(ctx context.Context, client *hbapi.Client, req mcp.Call
289285
return mcp.NewToolResultError(fmt.Sprintf("Failed to create project: %v", err)), nil
290286
}
291287

292-
// Include API tokens in response to allow LLM configuration
293-
294288
// Return JSON response
295289
jsonBytes, err := json.Marshal(project)
296290
if err != nil {
@@ -464,5 +458,3 @@ func handleGetProjectReport(ctx context.Context, client *hbapi.Client, req mcp.C
464458

465459
return mcp.NewToolResultText(string(jsonBytes)), nil
466460
}
467-
468-

internal/hbmcp/projects_test.go

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,23 @@ func TestHandleListProjects(t *testing.T) {
6666
t.Fatal("expected successful result, got error")
6767
}
6868

69-
// Check that tokens are now included in response
69+
// Verify the response can be unmarshaled as a projects list response
7070
resultText := getResultText(result)
71-
if !strings.Contains(resultText, "secret123") {
72-
t.Error("Token should be included in response")
71+
var response hbapi.ProjectsResponse
72+
if err := json.Unmarshal([]byte(resultText), &response); err != nil {
73+
t.Errorf("Response should be valid JSON projects list response: %v", err)
74+
}
75+
76+
if len(response.Results) != 2 {
77+
t.Errorf("expected 2 projects, got %d", len(response.Results))
7378
}
7479

75-
// Check that project data is still present
76-
if !strings.Contains(resultText, "Project 1") {
77-
t.Error("Project name should be present in response")
80+
if response.Results[0].Name != "Project 1" {
81+
t.Errorf("expected first project name 'Project 1', got %s", response.Results[0].Name)
82+
}
83+
84+
if response.Results[1].Name != "Project 2" {
85+
t.Errorf("expected second project name 'Project 2', got %s", response.Results[1].Name)
7886
}
7987
}
8088

@@ -135,7 +143,6 @@ func TestHandleListProjects_WithAccountID(t *testing.T) {
135143
WithBaseURL(server.URL).
136144
WithAuthToken("test-token")
137145

138-
// Test with account_id parameter
139146
req := mcp.CallToolRequest{
140147
Params: mcp.CallToolParams{
141148
Arguments: map[string]interface{}{
@@ -153,15 +160,23 @@ func TestHandleListProjects_WithAccountID(t *testing.T) {
153160
t.Fatal("expected successful result, got error")
154161
}
155162

156-
// Check that tokens are now included in response
163+
// Verify the response can be unmarshaled as a projects list response
157164
resultText := getResultText(result)
158-
if !strings.Contains(resultText, "secret123") {
159-
t.Error("Token should be included in response")
165+
var response hbapi.ProjectsResponse
166+
if err := json.Unmarshal([]byte(resultText), &response); err != nil {
167+
t.Errorf("Response should be valid JSON projects list response: %v", err)
160168
}
161169

162-
// Check that project data is still present
163-
if !strings.Contains(resultText, "Project 1") {
164-
t.Error("Project name should be present in response")
170+
if len(response.Results) != 1 {
171+
t.Errorf("expected 1 project, got %d", len(response.Results))
172+
}
173+
174+
if response.Results[0].Name != "Project 1" {
175+
t.Errorf("expected project name 'Project 1', got %s", response.Results[0].Name)
176+
}
177+
178+
if response.Results[0].ID != 1 {
179+
t.Errorf("expected project ID 1, got %d", response.Results[0].ID)
165180
}
166181
}
167182

@@ -202,14 +217,23 @@ func TestHandleGetProject(t *testing.T) {
202217
t.Fatal("expected successful result, got error")
203218
}
204219

205-
// Check that token is now included in response
206-
if !strings.Contains(getResultText(result), "secret123") {
207-
t.Error("Token should be included in response")
220+
// Verify the response can be unmarshaled as a project
221+
resultText := getResultText(result)
222+
var project hbapi.Project
223+
if err := json.Unmarshal([]byte(resultText), &project); err != nil {
224+
t.Errorf("Response should be valid JSON project: %v", err)
208225
}
209226

210-
// Check that project data is still present
211-
if !strings.Contains(getResultText(result), "Test Project") {
212-
t.Error("Project name should be present in response")
227+
if project.ID != 123 {
228+
t.Errorf("expected project ID 123, got %d", project.ID)
229+
}
230+
231+
if project.Name != "Test Project" {
232+
t.Errorf("expected project name 'Test Project', got %s", project.Name)
233+
}
234+
235+
if !project.Active {
236+
t.Error("expected project to be active")
213237
}
214238
}
215239

@@ -318,14 +342,27 @@ func TestHandleCreateProject(t *testing.T) {
318342
t.Fatal("expected successful result, got error")
319343
}
320344

321-
// Check that API key is now included in response
322-
if !strings.Contains(getResultText(result), "secret789") {
323-
t.Error("API key should be included in response")
345+
// Verify the response can be unmarshaled as a project
346+
resultText := getResultText(result)
347+
var project hbapi.Project
348+
if err := json.Unmarshal([]byte(resultText), &project); err != nil {
349+
t.Errorf("Response should be valid JSON project: %v", err)
350+
}
351+
352+
if project.ID != 456 {
353+
t.Errorf("expected project ID 456, got %d", project.ID)
324354
}
325355

326-
// Check that project data is still present
327-
if !strings.Contains(getResultText(result), "New Project") {
328-
t.Error("Project name should be present in response")
356+
if project.Name != "New Project" {
357+
t.Errorf("expected project name 'New Project', got %s", project.Name)
358+
}
359+
360+
if !project.Active {
361+
t.Error("expected created project to be active")
362+
}
363+
364+
if project.Owner.Email != "user@example.com" {
365+
t.Errorf("expected owner email 'user@example.com', got %s", project.Owner.Email)
329366
}
330367
}
331368

@@ -616,7 +653,6 @@ func TestHandleDeleteProject_Error(t *testing.T) {
616653
}
617654
}
618655

619-
620656
func TestHandleGetProjectReport(t *testing.T) {
621657
mockResponse := `[["RuntimeError", 8347], ["SocketError", 4651]]`
622658

0 commit comments

Comments
 (0)