From 8abc63efdbc0bb96cd6c9aa99d6e9166e0bcabae Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Sun, 22 Mar 2026 23:45:19 +0000 Subject: chore: unify and centralize agent configuration in .agent/ --- internal/api/todoist_test.go | 166 ++++--------------------------------------- 1 file changed, 14 insertions(+), 152 deletions(-) (limited to 'internal/api/todoist_test.go') diff --git a/internal/api/todoist_test.go b/internal/api/todoist_test.go index 2204469..99b9e80 100644 --- a/internal/api/todoist_test.go +++ b/internal/api/todoist_test.go @@ -14,7 +14,6 @@ import ( func newTestTodoistClient(baseURL, apiKey string) *TodoistClient { client := NewTodoistClient(apiKey) client.BaseURL = baseURL - client.syncClient.BaseURL = baseURL return client } @@ -220,9 +219,11 @@ func TestTodoistClient_GetProjects(t *testing.T) { } // Return mock response - response := []todoistProjectResponse{ - {ID: "proj-1", Name: "Project 1"}, - {ID: "proj-2", Name: "Project 2"}, + response := todoistProjectsPage{ + Results: []todoistProjectResponse{ + {ID: "proj-1", Name: "Project 1"}, + {ID: "proj-2", Name: "Project 2"}, + }, } w.Header().Set("Content-Type", "application/json") @@ -265,17 +266,21 @@ func TestTodoistClient_GetTasks(t *testing.T) { // GetTasks also calls GetProjects internally if r.URL.Path == "/projects" { - response := []todoistProjectResponse{ - {ID: "proj-1", Name: "Project 1"}, + response := todoistProjectsPage{ + Results: []todoistProjectResponse{ + {ID: "proj-1", Name: "Project 1"}, + }, } json.NewEncoder(w).Encode(response) return } if r.URL.Path == "/tasks" { - response := []todoistTaskResponse{ - {ID: "task-1", Content: "Task 1", ProjectID: "proj-1", CreatedAt: time.Now().Format(time.RFC3339)}, - {ID: "task-2", Content: "Task 2", ProjectID: "proj-1", CreatedAt: time.Now().Format(time.RFC3339)}, + response := todoistTasksPage{ + Results: []todoistTaskResponse{ + {ID: "task-1", Content: "Task 1", ProjectID: "proj-1", CreatedAt: time.Now().Format(time.RFC3339)}, + {ID: "task-2", Content: "Task 2", ProjectID: "proj-1", CreatedAt: time.Now().Format(time.RFC3339)}, + }, } json.NewEncoder(w).Encode(response) return @@ -345,146 +350,3 @@ func TestTodoistClient_UpdateTask(t *testing.T) { } } -func TestTodoistClient_Sync(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) - } - if r.URL.Path != "/sync" { - t.Errorf("Expected path /sync, got %s", r.URL.Path) - } - - response := TodoistSyncResponse{ - SyncToken: "new-sync-token", - FullSync: true, - Items: []SyncItemResponse{ - {ID: "item-1", Content: "Item 1", ProjectID: "proj-1"}, - }, - Projects: []SyncProjectResponse{ - {ID: "proj-1", Name: "Project 1"}, - }, - } - - w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(response) - })) - defer server.Close() - - client := newTestTodoistClient(server.URL, "test-key") - resp, err := client.Sync(context.Background(), "*") - if err != nil { - t.Fatalf("Sync failed: %v", err) - } - - if resp.SyncToken != "new-sync-token" { - t.Errorf("Expected sync token 'new-sync-token', got '%s'", resp.SyncToken) - } - if len(resp.Items) != 1 { - t.Errorf("Expected 1 item, got %d", len(resp.Items)) - } -} - -func TestConvertSyncItemsToTasks(t *testing.T) { - projects := map[string]string{ - "proj-1": "Project 1", - } - - items := []SyncItemResponse{ - { - ID: "item-1", - Content: "Task 1", - Description: "Description 1", - ProjectID: "proj-1", - Priority: 3, - Labels: []string{"label1"}, - }, - { - ID: "item-2", - Content: "Completed Task", - ProjectID: "proj-1", - IsCompleted: true, - }, - } - - tasks := ConvertSyncItemsToTasks(items, projects) - - // Should skip completed task - if len(tasks) != 1 { - t.Errorf("Expected 1 task (excluding completed), got %d", len(tasks)) - } - - if tasks[0].ID != "item-1" { - t.Errorf("Expected task ID 'item-1', got '%s'", tasks[0].ID) - } - if tasks[0].ProjectName != "Project 1" { - t.Errorf("Expected project name 'Project 1', got '%s'", tasks[0].ProjectName) - } -} - -func TestConvertSyncItemToTask(t *testing.T) { - projects := map[string]string{"proj-1": "Project 1"} - - t.Run("active item returns task and true", func(t *testing.T) { - item := SyncItemResponse{ - ID: "item-1", - Content: "Active Task", - Description: "desc", - ProjectID: "proj-1", - Priority: 2, - Labels: []string{"work"}, - AddedAt: "2026-01-01T00:00:00Z", - } - task, ok := ConvertSyncItemToTask(item, projects) - if !ok { - t.Fatal("expected ok=true for active item") - } - if task.ID != "item-1" { - t.Errorf("expected ID 'item-1', got '%s'", task.ID) - } - if task.Content != "Active Task" { - t.Errorf("expected Content 'Active Task', got '%s'", task.Content) - } - if task.ProjectName != "Project 1" { - t.Errorf("expected ProjectName 'Project 1', got '%s'", task.ProjectName) - } - if task.Completed { - t.Error("expected Completed=false") - } - if task.URL != "https://todoist.com/app/task/item-1" { - t.Errorf("unexpected URL: %s", task.URL) - } - }) - - t.Run("completed item returns false", func(t *testing.T) { - item := SyncItemResponse{ID: "item-2", Content: "Done", ProjectID: "proj-1", IsCompleted: true} - _, ok := ConvertSyncItemToTask(item, projects) - if ok { - t.Error("expected ok=false for completed item") - } - }) - - t.Run("deleted item returns false", func(t *testing.T) { - item := SyncItemResponse{ID: "item-3", Content: "Gone", ProjectID: "proj-1", IsDeleted: true} - _, ok := ConvertSyncItemToTask(item, projects) - if ok { - t.Error("expected ok=false for deleted item") - } - }) -} - -func TestBuildProjectMapFromSync(t *testing.T) { - projects := []SyncProjectResponse{ - {ID: "proj-1", Name: "Project 1"}, - {ID: "proj-2", Name: "Project 2"}, - } - - projectMap := BuildProjectMapFromSync(projects) - - if len(projectMap) != 2 { - t.Errorf("Expected 2 projects in map, got %d", len(projectMap)) - } - - if projectMap["proj-1"] != "Project 1" { - t.Errorf("Expected 'Project 1', got '%s'", projectMap["proj-1"]) - } -} -- cgit v1.2.3