From 465093343ddd398ce5f6377fc9c472d8251c618b Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Fri, 23 Jan 2026 21:37:18 -1000 Subject: Refactor: reduce code duplication with shared abstractions - Add BaseClient HTTP abstraction (internal/api/http.go) to eliminate duplicated HTTP boilerplate across Todoist, Trello, and PlanToEat clients - Add response helpers (internal/handlers/response.go) for JSON/HTML responses - Add generic cache wrapper (internal/handlers/cache.go) using Go generics - Consolidate HandleCompleteAtom/HandleUncompleteAtom into handleAtomToggle - Merge TabsHandler into Handler, delete tabs.go - Extract sortTasksByUrgency and filterAndSortTrelloTasks helpers - Update tests to work with new BaseClient structure Co-Authored-By: Claude Opus 4.5 --- internal/api/todoist_test.go | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) (limited to 'internal/api/todoist_test.go') diff --git a/internal/api/todoist_test.go b/internal/api/todoist_test.go index 56b1484..88f94f8 100644 --- a/internal/api/todoist_test.go +++ b/internal/api/todoist_test.go @@ -10,6 +10,14 @@ import ( "time" ) +// newTestTodoistClient creates a TodoistClient for testing with custom base URL +func newTestTodoistClient(baseURL, apiKey string) *TodoistClient { + client := NewTodoistClient(apiKey) + client.BaseClient.BaseURL = baseURL + client.syncClient.BaseURL = baseURL + return client +} + func TestTodoistClient_CreateTask(t *testing.T) { // Mock server server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -59,11 +67,7 @@ func TestTodoistClient_CreateTask(t *testing.T) { defer server.Close() // Create client with mock server URL - client := &TodoistClient{ - apiKey: "test-key", - baseURL: server.URL, - httpClient: &http.Client{}, - } + client := newTestTodoistClient(server.URL, "test-key") // Test CreateTask ctx := context.Background() @@ -122,11 +126,7 @@ func TestTodoistClient_CreateTask_WithDueDate(t *testing.T) { defer server.Close() // Create client - client := &TodoistClient{ - apiKey: "test-key", - baseURL: server.URL, - httpClient: &http.Client{}, - } + client := newTestTodoistClient(server.URL, "test-key") // Test CreateTask with due date ctx := context.Background() @@ -170,11 +170,7 @@ func TestTodoistClient_CompleteTask(t *testing.T) { defer server.Close() // Create client - client := &TodoistClient{ - apiKey: "test-key", - baseURL: server.URL, - httpClient: &http.Client{}, - } + client := newTestTodoistClient(server.URL, "test-key") // Test CompleteTask ctx := context.Background() @@ -194,11 +190,7 @@ func TestTodoistClient_CompleteTask_Error(t *testing.T) { defer server.Close() // Create client - client := &TodoistClient{ - apiKey: "test-key", - baseURL: server.URL, - httpClient: &http.Client{}, - } + client := newTestTodoistClient(server.URL, "test-key") // Test CompleteTask with error ctx := context.Background() @@ -235,11 +227,7 @@ func TestTodoistClient_GetProjects(t *testing.T) { defer server.Close() // Create client - client := &TodoistClient{ - apiKey: "test-key", - baseURL: server.URL, - httpClient: &http.Client{}, - } + client := newTestTodoistClient(server.URL, "test-key") // Test GetProjects ctx := context.Background() -- cgit v1.2.3