summaryrefslogtreecommitdiff
path: root/internal/handlers/agent_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/handlers/agent_test.go')
-rw-r--r--internal/handlers/agent_test.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/internal/handlers/agent_test.go b/internal/handlers/agent_test.go
index 2893a13..ea661b1 100644
--- a/internal/handlers/agent_test.go
+++ b/internal/handlers/agent_test.go
@@ -13,6 +13,7 @@ import (
"task-dashboard/internal/config"
"task-dashboard/internal/models"
+ "task-dashboard/internal/store"
)
func TestHandleAgentAuthRequest(t *testing.T) {
@@ -833,6 +834,46 @@ func TestHandleAgentTaskWriteOperations(t *testing.T) {
})
}
+func TestHandleAgentTaskComplete_Gtasks_InvalidatesCache(t *testing.T) {
+ db, cleanup := setupTestDB(t)
+ defer cleanup()
+
+ if err := db.SaveGoogleTasks([]models.GoogleTask{
+ {ID: "g1", Title: "Renew passport", ListID: "list-a", UpdatedAt: time.Now()},
+ }); err != nil {
+ t.Fatal(err)
+ }
+ if err := db.UpdateCacheMetadata(store.CacheKeyGoogleTasks, 60); err != nil {
+ t.Fatal(err)
+ }
+
+ h := &Handler{store: db, googleTasksClient: &mockGoogleTasksClient{}, config: &config.Config{}}
+
+ session := &models.AgentSession{RequestToken: "rt", AgentName: "A", AgentID: "a-uuid", ExpiresAt: time.Now().Add(5 * time.Minute)}
+ db.CreateAgentSession(session)
+ db.ApproveAgentSession("rt", "st", time.Now().Add(time.Hour))
+
+ req := httptest.NewRequest(http.MethodPost, "/agent/tasks/g1/complete?source=gtasks&listId=list-a", nil)
+ req = req.WithContext(context.WithValue(req.Context(), agentSessionContextKey, session))
+ rctx := chi.NewRouteContext()
+ rctx.URLParams.Add("id", "g1")
+ req = req.WithContext(context.WithValue(req.Context(), chi.RouteCtxKey, rctx))
+ w := httptest.NewRecorder()
+
+ h.HandleAgentTaskComplete(w, req)
+
+ if w.Code != http.StatusOK {
+ t.Fatalf("status = %d, want 200, body=%s", w.Code, w.Body.String())
+ }
+ meta, err := db.GetCacheMetadata(store.CacheKeyGoogleTasks)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if meta != nil {
+ t.Error("expected gtasks cache metadata to be invalidated after agent-api completion, but it still exists")
+ }
+}
+
func TestHandleAgentCreateOperations(t *testing.T) {
db, cleanup := setupTestDB(t)
defer cleanup()