running and cancel all commands
This commit is contained in:
1 parent
917a361370
commit
af249326e8
7 files changed
+145
-6
No files matched your search
@@ -164,6 +164,44 @@ func TestInFlightIsForSuperUsers(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunningAndCancelAll(t *testing.T) {
|
||||
h := newTurnHarness(t)
|
||||
b := h.bot()
|
||||
cancelled := map[string]bool{}
|
||||
for _, ts := range []string{"1.0", "2.0", "3.0"} {
|
||||
_ = h.c.Store.PutTurn(&model.Turn{Channel: "C1", ThreadTS: ts, MessageTS: ts, ReplyTS: ts + "1", User: "UANA",
|
||||
Text: "task " + ts, StartedAt: time.Now()})
|
||||
}
|
||||
_ = h.c.Store.PutTurn(&model.Turn{Channel: "C2", ThreadTS: "4.0", MessageTS: "4.0", ReplyTS: "4.01", Text: "elsewhere", StartedAt: time.Now()})
|
||||
for _, key := range []string{"C1/1.01", "C1/2.01", "C2/4.01"} {
|
||||
b.running.Store(key, context.CancelFunc(func() { cancelled[key] = true }))
|
||||
}
|
||||
m := incoming{user: "UANA", channel: "C1", ts: "9.0"}
|
||||
|
||||
reply, ok := b.runCommand(h.c.Ctx, m, "running", "", false)
|
||||
if !ok || !strings.Contains(reply, "task 1.0") || !strings.Contains(reply, "task 3.0") || strings.Contains(reply, "elsewhere") ||
|
||||
!strings.Contains(reply, "getting the container ready") {
|
||||
t.Fatalf("running lists this channel's replies: %q %v", reply, ok)
|
||||
}
|
||||
|
||||
agent := m
|
||||
agent.threadTS = "1.0"
|
||||
if reply, _ := b.runCommand(h.c.Ctx, agent, "cancel", "all", true); !strings.Contains(reply, "Cancelled 1 reply") ||
|
||||
cancelled["C1/1.01"] || !cancelled["C1/2.01"] {
|
||||
t.Fatalf("the agent cancels every other reply but its own: %q %v", reply, cancelled)
|
||||
}
|
||||
if reply, _ := b.runCommand(h.c.Ctx, m, "cancel", "all", false); !strings.Contains(reply, "Cancelled 2 replies") ||
|
||||
!strings.Contains(reply, "still getting ready: 1 reply") || !cancelled["C1/1.01"] || cancelled["C2/4.01"] {
|
||||
t.Fatalf("cancel all stops this channel's replies only: %q %v", reply, cancelled)
|
||||
}
|
||||
if _, ok := b.runCommand(h.c.Ctx, m, "cancel", "all the meetings", false); ok {
|
||||
t.Fatal("a sentence that starts with cancel goes to the agent")
|
||||
}
|
||||
if reply, _ := b.runCommand(h.c.Ctx, incoming{user: "UANA", channel: "C3"}, "running", "", false); reply != "Nothing is running here right now." {
|
||||
t.Fatalf("empty channel: %q", reply)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInFlightCommandIsPrivate(t *testing.T) {
|
||||
h := newTurnHarness(t)
|
||||
b := h.bot()
|
||||
|
||||
Reference in new issue
Block a user