-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchat_join_query_test.go
More file actions
70 lines (54 loc) · 1.91 KB
/
Copy pathchat_join_query_test.go
File metadata and controls
70 lines (54 loc) · 1.91 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
61
62
63
64
65
66
67
68
69
70
package botapi
import (
"context"
"testing"
"github.com/gotd/td/tg"
)
func TestAnswerChatJoinRequestQuery(t *testing.T) {
for _, c := range []struct {
result string
want tg.JoinChatBotResultClass
}{
{"approve", &tg.JoinChatBotResultApproved{}},
{"decline", &tg.JoinChatBotResultDeclined{}},
{"queue", &tg.JoinChatBotResultQueued{}},
} {
t.Run(c.result, func(t *testing.T) {
inv := newMockInvoker()
inv.reply(tg.BotsSetJoinChatResultsRequestTypeID, &tg.BoolTrue{})
if err := newMockBot(inv).AnswerChatJoinRequestQuery(context.Background(), "123", c.result); err != nil {
t.Fatalf("AnswerChatJoinRequestQuery: %v", err)
}
var req tg.BotsSetJoinChatResultsRequest
inv.decode(t, tg.BotsSetJoinChatResultsRequestTypeID, &req)
if req.QueryID != 123 {
t.Fatalf("query id = %d", req.QueryID)
}
if req.Result.TypeID() != c.want.TypeID() {
t.Fatalf("result = %#v, want %#v", req.Result, c.want)
}
})
}
}
func TestAnswerChatJoinRequestQueryInvalid(t *testing.T) {
inv := newMockInvoker()
if err := newMockBot(inv).AnswerChatJoinRequestQuery(context.Background(), "123", "maybe"); err == nil {
t.Fatal("expected error for invalid result")
}
if err := newMockBot(inv).AnswerChatJoinRequestQuery(context.Background(), "notanumber", "approve"); err == nil {
t.Fatal("expected error for invalid query id")
}
}
func TestSendChatJoinRequestWebApp(t *testing.T) {
inv := newMockInvoker()
inv.reply(tg.BotsSetJoinChatResultsRequestTypeID, &tg.BoolTrue{})
if err := newMockBot(inv).SendChatJoinRequestWebApp(context.Background(), "456", "https://example.com/app"); err != nil {
t.Fatalf("SendChatJoinRequestWebApp: %v", err)
}
var req tg.BotsSetJoinChatResultsRequest
inv.decode(t, tg.BotsSetJoinChatResultsRequestTypeID, &req)
wv, ok := req.Result.(*tg.JoinChatBotResultWebView)
if !ok || wv.URL != "https://example.com/app" {
t.Fatalf("result = %#v", req.Result)
}
}