-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbusiness_context_test.go
More file actions
120 lines (90 loc) · 3.37 KB
/
Copy pathbusiness_context_test.go
File metadata and controls
120 lines (90 loc) · 3.37 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package botapi
import (
"context"
"testing"
"github.com/gotd/td/tg"
)
func TestBusinessContextConnectionID(t *testing.T) {
bc := newMockBot(newMockInvoker()).Business("bc9")
if bc.ConnectionID() != "bc9" {
t.Fatalf("connection id = %q", bc.ConnectionID())
}
}
func TestBusinessContextSetNameScopesConnection(t *testing.T) {
inv := newMockInvoker()
inv.reply(tg.InvokeWithBusinessConnectionRequestTypeID, &tg.User{ID: 10})
if err := newMockBot(inv).Business("bc9").SetName(context.Background(), "First", "Last"); err != nil {
t.Fatalf("SetName: %v", err)
}
wrapper := tg.InvokeWithBusinessConnectionRequest{Query: &tg.AccountUpdateProfileRequest{}}
inv.decode(t, tg.InvokeWithBusinessConnectionRequestTypeID, &wrapper)
if wrapper.ConnectionID != "bc9" {
t.Fatalf("connection id = %q", wrapper.ConnectionID)
}
profile, ok := wrapper.Query.(*tg.AccountUpdateProfileRequest)
if !ok {
t.Fatalf("query = %#v", wrapper.Query)
}
if first, _ := profile.GetFirstName(); first != "First" {
t.Fatalf("first name = %q", first)
}
}
func TestBusinessContextStarBalance(t *testing.T) {
inv := newMockInvoker()
inv.reply(tg.InvokeWithBusinessConnectionRequestTypeID, &tg.PaymentsStarsStatus{
Balance: &tg.StarsAmount{Amount: 7},
})
got, err := newMockBot(inv).Business("bc9").StarBalance(context.Background())
if err != nil {
t.Fatalf("StarBalance: %v", err)
}
if got.Amount != 7 {
t.Fatalf("balance = %#v", got)
}
}
func TestBusinessContextDeleteMessages(t *testing.T) {
inv := newMockInvoker()
inv.reply(tg.InvokeWithBusinessConnectionRequestTypeID, &tg.MessagesAffectedMessages{})
if err := newMockBot(inv).Business("bc9").DeleteMessages(context.Background(), []int{1, 2}); err != nil {
t.Fatalf("DeleteMessages: %v", err)
}
wrapper := tg.InvokeWithBusinessConnectionRequest{Query: &tg.MessagesDeleteMessagesRequest{}}
inv.decode(t, tg.InvokeWithBusinessConnectionRequestTypeID, &wrapper)
del, ok := wrapper.Query.(*tg.MessagesDeleteMessagesRequest)
if !ok || len(del.ID) != 2 {
t.Fatalf("query = %#v", wrapper.Query)
}
}
func TestBusinessContextConnection(t *testing.T) {
inv := newMockInvoker()
inv.reply(tg.AccountGetBotBusinessConnectionRequestTypeID, &tg.Updates{
Updates: []tg.UpdateClass{
&tg.UpdateBotBusinessConnect{Connection: tg.BotBusinessConnection{ConnectionID: "bc9", UserID: 10}},
},
Users: []tg.UserClass{&tg.User{ID: 10, FirstName: "Biz"}},
})
conn, err := newMockBot(inv).Business("bc9").Connection(context.Background())
if err != nil {
t.Fatalf("Connection: %v", err)
}
if conn.ID != "bc9" {
t.Fatalf("conn = %#v", conn)
}
var req tg.AccountGetBotBusinessConnectionRequest
inv.decode(t, tg.AccountGetBotBusinessConnectionRequestTypeID, &req)
if req.ConnectionID != "bc9" {
t.Fatalf("requested connection id = %q", req.ConnectionID)
}
}
func TestBusinessContextRemoveProfilePhoto(t *testing.T) {
inv := newMockInvoker()
inv.reply(tg.InvokeWithBusinessConnectionRequestTypeID, &tg.PhotosPhoto{Photo: &tg.PhotoEmpty{}})
if err := newMockBot(inv).Business("bc9").RemoveProfilePhoto(context.Background(), false); err != nil {
t.Fatalf("RemoveProfilePhoto: %v", err)
}
wrapper := tg.InvokeWithBusinessConnectionRequest{Query: &tg.PhotosUpdateProfilePhotoRequest{}}
inv.decode(t, tg.InvokeWithBusinessConnectionRequestTypeID, &wrapper)
if wrapper.ConnectionID != "bc9" {
t.Fatalf("connection id = %q", wrapper.ConnectionID)
}
}