mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-07 09:47:35 +08:00
fix(cron): ensure reminders keep delivery channel target
This commit is contained in:
39
pkg/tools/remind_test.go
Normal file
39
pkg/tools/remind_test.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"clawgo/pkg/cron"
|
||||
)
|
||||
|
||||
func TestRemindTool_UsesToolContextForDeliveryTarget(t *testing.T) {
|
||||
storePath := filepath.Join(t.TempDir(), "jobs.json")
|
||||
cs := cron.NewCronService(storePath, nil)
|
||||
tool := NewRemindTool(cs)
|
||||
tool.SetContext("telegram", "chat-123")
|
||||
|
||||
_, err := tool.Execute(context.Background(), map[string]interface{}{
|
||||
"message": "喝水",
|
||||
"time_expr": "10m",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Execute returned error: %v", err)
|
||||
}
|
||||
|
||||
jobs := cs.ListJobs(true)
|
||||
if len(jobs) != 1 {
|
||||
t.Fatalf("expected 1 job, got %d", len(jobs))
|
||||
}
|
||||
|
||||
if !jobs[0].Payload.Deliver {
|
||||
t.Fatalf("expected deliver=true")
|
||||
}
|
||||
if jobs[0].Payload.Channel != "telegram" {
|
||||
t.Fatalf("expected channel telegram, got %q", jobs[0].Payload.Channel)
|
||||
}
|
||||
if jobs[0].Payload.To != "chat-123" {
|
||||
t.Fatalf("expected to chat-123, got %q", jobs[0].Payload.To)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user