-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbusiness_read_test.go
More file actions
75 lines (56 loc) · 2.15 KB
/
Copy pathbusiness_read_test.go
File metadata and controls
75 lines (56 loc) · 2.15 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
package botapi
import (
"context"
"testing"
"github.com/gotd/td/bin"
"github.com/gotd/td/tg"
)
func TestReadBusinessMessage(t *testing.T) {
inv := newMockInvoker()
inv.reply(tg.InvokeWithBusinessConnectionRequestTypeID, &tg.MessagesAffectedMessages{})
if err := newMockBot(inv).ReadBusinessMessage(context.Background(), "bc1", userRef(10, 20), 77); err != nil {
t.Fatalf("ReadBusinessMessage: %v", err)
}
wrapper := tg.InvokeWithBusinessConnectionRequest{Query: &tg.MessagesReadHistoryRequest{}}
inv.decode(t, tg.InvokeWithBusinessConnectionRequestTypeID, &wrapper)
if wrapper.ConnectionID != "bc1" {
t.Fatalf("connection id = %q", wrapper.ConnectionID)
}
rh, ok := wrapper.Query.(*tg.MessagesReadHistoryRequest)
if !ok || rh.MaxID != 77 {
t.Fatalf("query = %#v", wrapper.Query)
}
}
func TestTransferBusinessAccountStars(t *testing.T) {
inv := newMockInvoker()
// The transfer makes two business-wrapped calls under the same outer type:
// getPaymentForm then sendStarsForm. Respond by call order.
calls := 0
inv.handle(tg.InvokeWithBusinessConnectionRequestTypeID, func(*bin.Buffer) (bin.Encoder, error) {
calls++
if calls == 1 {
return &tg.PaymentsPaymentFormStars{FormID: 555, Invoice: tg.Invoice{Currency: "XTR"}}, nil
}
return &tg.PaymentsPaymentResult{Updates: &tg.Updates{}}, nil
})
if err := newMockBot(inv).TransferBusinessAccountStars(context.Background(), "bc2", 100); err != nil {
t.Fatalf("TransferBusinessAccountStars: %v", err)
}
// The last wrapped call is sendStarsForm.
wrapper := tg.InvokeWithBusinessConnectionRequest{Query: &tg.PaymentsSendStarsFormRequest{}}
inv.decode(t, tg.InvokeWithBusinessConnectionRequestTypeID, &wrapper)
if wrapper.ConnectionID != "bc2" {
t.Fatalf("connection id = %q", wrapper.ConnectionID)
}
send, ok := wrapper.Query.(*tg.PaymentsSendStarsFormRequest)
if !ok || send.FormID != 555 {
t.Fatalf("query = %#v", wrapper.Query)
}
invoice, ok := send.Invoice.(*tg.InputInvoiceBusinessBotTransferStars)
if !ok || invoice.Stars != 100 {
t.Fatalf("invoice = %#v", send.Invoice)
}
if _, ok := invoice.Bot.(*tg.InputUserSelf); !ok {
t.Fatalf("bot = %#v, want self", invoice.Bot)
}
}