-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontext_test.go
More file actions
51 lines (43 loc) · 1.18 KB
/
Copy pathcontext_test.go
File metadata and controls
51 lines (43 loc) · 1.18 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
39
40
41
42
43
44
45
46
47
48
49
50
51
package botapi
import (
"context"
"testing"
)
func TestContextChatAndSender(t *testing.T) {
c := &Context{
Context: context.Background(),
Update: &Update{Message: &Message{
MessageID: 7,
Chat: Chat{ID: -100500, Type: ChatTypeSupergroup},
From: &User{ID: 11, Username: "ada"},
}},
}
chat, ok := c.Chat()
if !ok {
t.Fatal("Chat should be present")
}
if id, isInt := chat.(ChatIDInt); !isInt || int64(id) != -100500 {
t.Fatalf("Chat id = %v", chat)
}
if s := c.Sender(); s == nil || s.ID != 11 {
t.Fatalf("Sender = %+v", c.Sender())
}
}
func TestContextSenderFromCallback(t *testing.T) {
c := &Context{
Context: context.Background(),
Update: &Update{CallbackQuery: &CallbackQuery{From: User{ID: 99}}},
}
if s := c.Sender(); s == nil || s.ID != 99 {
t.Fatalf("callback sender = %+v", c.Sender())
}
}
func TestContextReplyWithoutMessage(t *testing.T) {
c := &Context{Context: context.Background(), Bot: newTestBot(t), Update: &Update{InlineQuery: &InlineQuery{}}}
if _, err := c.Reply("hi"); err == nil {
t.Fatal("Reply with no message should error")
}
if _, ok := c.Chat(); ok {
t.Fatal("inline-query-only update should have no chat")
}
}