-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdm_test.go
More file actions
38 lines (34 loc) · 1.41 KB
/
Copy pathdm_test.go
File metadata and controls
38 lines (34 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"context"
"testing"
"github.com/mymmrac/telego"
)
func privMsg(text string) telego.Update {
return telego.Update{Message: &telego.Message{Chat: telego.Chat{Type: "private"}, Text: text}}
}
// TestDMRouting verifies which private-chat messages reach a command handler (privateNonStart
// returns false) versus get the unified auto-reply (true): every member command and the
// /start deep link are handled; admin/moderation commands and plain text get the auto-reply.
func TestDMRouting(t *testing.T) {
handled := []string{
"/pkg vim", "/use vim", "/bug 1", "/news", "/wiki x", "/bbs x",
"/pkgs firefox", "/distro firefox", "/arm htop", "/armpkgs htop",
"/help", "/ping", "/stats", "/start", "/start verify", "/pkg@GentooZhVerifyBot vim",
}
for _, m := range handled {
if privateNonStart(context.TODO(), privMsg(m)) {
t.Errorf("%q should reach its handler, not the auto-reply", m)
}
}
autoReply := []string{"/sb", "/ban", "/warn", "/clearwarn", "/bc", "/rich", "/autodel", "/stop", "hello", "随便聊聊"}
for _, m := range autoReply {
if !privateNonStart(context.TODO(), privMsg(m)) {
t.Errorf("%q should get the auto-reply", m)
}
}
// a non-private chat never matches privateNonStart
if privateNonStart(context.TODO(), telego.Update{Message: &telego.Message{Chat: telego.Chat{Type: "supergroup"}, Text: "/pkg x"}}) {
t.Errorf("group message should not match privateNonStart")
}
}