diff options
Diffstat (limited to 'internal/handlers/handlers_test.go')
| -rw-r--r-- | internal/handlers/handlers_test.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.go index d14f71b..3658e0e 100644 --- a/internal/handlers/handlers_test.go +++ b/internal/handlers/handlers_test.go @@ -3,9 +3,11 @@ package handlers import ( "context" "encoding/json" + "html/template" "net/http" "net/http/httptest" "os" + "path/filepath" "testing" "time" @@ -58,6 +60,30 @@ func setupTestDB(t *testing.T) (*store.Store, func()) { return db, cleanup } +// loadTestTemplates loads templates for testing from project root +func loadTestTemplates(t *testing.T) *template.Template { + t.Helper() + + // Get path relative to project root + tmpl, err := template.ParseGlob(filepath.Join("web", "templates", "*.html")) + if err != nil { + // Try from internal/handlers (2 levels up) + tmpl, err = template.ParseGlob(filepath.Join("..", "..", "web", "templates", "*.html")) + if err != nil { + t.Logf("Warning: failed to parse templates: %v", err) + return nil + } + } + + // Parse partials + tmpl, err = tmpl.ParseGlob(filepath.Join("web", "templates", "partials", "*.html")) + if err != nil { + tmpl, _ = tmpl.ParseGlob(filepath.Join("..", "..", "web", "templates", "partials", "*.html")) + } + + return tmpl +} + // mockTodoistClient creates a mock Todoist client for testing type mockTodoistClient struct { tasks []models.Task @@ -457,6 +483,7 @@ func TestHandleCompleteAtom_Todoist(t *testing.T) { store: db, todoistClient: mockTodoist, config: &config.Config{}, + templates: loadTestTemplates(t), } // Create request @@ -523,6 +550,7 @@ func TestHandleCompleteAtom_Trello(t *testing.T) { store: db, trelloClient: mockTrello, config: &config.Config{}, + templates: loadTestTemplates(t), } // Create request |
