forked from gotd/botapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanswer_guest_test.go
More file actions
60 lines (45 loc) · 1.61 KB
/
Copy pathanswer_guest_test.go
File metadata and controls
60 lines (45 loc) · 1.61 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
52
53
54
55
56
57
58
59
60
package botapi
import (
"context"
"testing"
"github.com/gotd/td/tg"
)
func TestAnswerGuestQuery(t *testing.T) {
mid := &tg.InputBotInlineMessageID64{DCID: 2, OwnerID: 1, ID: 9, AccessHash: 42}
inv := newMockInvoker()
inv.reply(tg.MessagesSetBotGuestChatResultRequestTypeID, mid)
result := &InlineQueryResultArticle{
ID: "r1",
Title: "Title",
InputMessageContent: &InputTextMessageContent{MessageText: "hi"},
}
got, err := newMockBot(inv).AnswerGuestQuery(context.Background(), "12345", result)
if err != nil {
t.Fatalf("AnswerGuestQuery: %v", err)
}
decoded, err := decodeInlineMessageID(got.InlineMessageID)
if err != nil {
t.Fatalf("decode inline message id: %v", err)
}
if decoded.String() != mid.String() {
t.Fatalf("inline message id = %#v, want %#v", decoded, mid)
}
var req tg.MessagesSetBotGuestChatResultRequest
inv.decode(t, tg.MessagesSetBotGuestChatResultRequestTypeID, &req)
if req.QueryID != 12345 {
t.Fatalf("query id = %d", req.QueryID)
}
if _, ok := req.Result.(*tg.InputBotInlineResult); !ok {
t.Fatalf("result = %#v, want inline result", req.Result)
}
}
func TestAnswerGuestQueryInvalid(t *testing.T) {
inv := newMockInvoker()
if _, err := newMockBot(inv).AnswerGuestQuery(context.Background(), "12345", nil); err == nil {
t.Fatal("expected error for nil result")
}
if _, err := newMockBot(inv).AnswerGuestQuery(context.Background(), "notanumber",
&InlineQueryResultArticle{ID: "r1", Title: "T", InputMessageContent: &InputTextMessageContent{MessageText: "x"}}); err == nil {
t.Fatal("expected error for invalid guest_query_id")
}
}