move gotd fork into repo. (#111)
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
package peers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
||||
)
|
||||
|
||||
func TestReport(t *testing.T) {
|
||||
a := require.New(t)
|
||||
ctx := context.Background()
|
||||
mock, m := testManager(t)
|
||||
|
||||
reason := &tg.InputReportReasonSpam{}
|
||||
message := "message"
|
||||
peers := []Peer{
|
||||
m.User(getTestUser()),
|
||||
m.Chat(getTestChat()),
|
||||
m.Channel(getTestChannel()),
|
||||
}
|
||||
|
||||
for _, p := range peers {
|
||||
req := &tg.AccountReportPeerRequest{
|
||||
Peer: p.InputPeer(),
|
||||
Reason: reason,
|
||||
Message: message,
|
||||
}
|
||||
|
||||
mock.ExpectCall(req).ThenRPCErr(getTestError())
|
||||
a.Error(p.Report(ctx, reason, message))
|
||||
|
||||
mock.ExpectCall(req).ThenTrue()
|
||||
a.NoError(p.Report(ctx, reason, message))
|
||||
}
|
||||
}
|
||||
|
||||
func TestManager_FromInputPeer(t *testing.T) {
|
||||
testUser := getTestUser()
|
||||
testChat := getTestChat()
|
||||
testChannel := getTestChannel()
|
||||
|
||||
getUser := func(input tg.InputUserClass) *tg.UsersGetUsersRequest {
|
||||
return &tg.UsersGetUsersRequest{
|
||||
ID: []tg.InputUserClass{input},
|
||||
}
|
||||
}
|
||||
getChannel := func(input tg.InputChannelClass) *tg.ChannelsGetChannelsRequest {
|
||||
return &tg.ChannelsGetChannelsRequest{
|
||||
ID: []tg.InputChannelClass{input},
|
||||
}
|
||||
}
|
||||
var tests = []struct {
|
||||
input tg.InputPeerClass
|
||||
expect bin.Encoder
|
||||
result bin.Encoder
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
&tg.InputPeerSelf{},
|
||||
getUser(&tg.InputUserSelf{}),
|
||||
&tg.UserClassVector{Elems: []tg.UserClass{getTestSelf()}},
|
||||
false,
|
||||
},
|
||||
{
|
||||
testUser.AsInputPeer(),
|
||||
getUser(testUser.AsInput()),
|
||||
&tg.UserClassVector{Elems: []tg.UserClass{testUser}},
|
||||
false,
|
||||
},
|
||||
{
|
||||
&tg.InputPeerUserFromMessage{
|
||||
Peer: getTestChannel().AsInputPeer(),
|
||||
MsgID: 10,
|
||||
UserID: testUser.ID,
|
||||
},
|
||||
getUser(&tg.InputUserFromMessage{
|
||||
Peer: getTestChannel().AsInputPeer(),
|
||||
MsgID: 10,
|
||||
UserID: testUser.ID,
|
||||
}),
|
||||
&tg.UserClassVector{Elems: []tg.UserClass{testUser}},
|
||||
false,
|
||||
},
|
||||
{
|
||||
testChannel.AsInputPeer(),
|
||||
getChannel(testChannel.AsInput()),
|
||||
&tg.MessagesChats{Chats: []tg.ChatClass{testChannel}},
|
||||
false,
|
||||
},
|
||||
{
|
||||
&tg.InputPeerChannelFromMessage{
|
||||
Peer: getTestChannel().AsInputPeer(),
|
||||
MsgID: 10,
|
||||
ChannelID: testChannel.ID,
|
||||
},
|
||||
getChannel(&tg.InputChannelFromMessage{
|
||||
Peer: getTestChannel().AsInputPeer(),
|
||||
MsgID: 10,
|
||||
ChannelID: testChannel.ID,
|
||||
}),
|
||||
&tg.MessagesChats{Chats: []tg.ChatClass{testChannel}},
|
||||
false,
|
||||
},
|
||||
{
|
||||
&tg.InputPeerChat{
|
||||
ChatID: testChat.ID,
|
||||
},
|
||||
&tg.MessagesGetChatsRequest{
|
||||
ID: []int64{testChat.ID},
|
||||
},
|
||||
&tg.MessagesChats{Chats: []tg.ChatClass{testChat}},
|
||||
false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(fmt.Sprintf("%T", tt.input), func(t *testing.T) {
|
||||
a := require.New(t)
|
||||
ctx := context.Background()
|
||||
mock, m := testManager(t)
|
||||
|
||||
mock.ExpectCall(tt.expect).ThenRPCErr(getTestError())
|
||||
_, err := m.FromInputPeer(ctx, tt.input)
|
||||
a.Error(err)
|
||||
|
||||
mock.ExpectCall(tt.expect).ThenResult(tt.result)
|
||||
p, err := m.FromInputPeer(ctx, tt.input)
|
||||
if tt.wantErr {
|
||||
a.Error(err)
|
||||
return
|
||||
}
|
||||
a.NoError(err)
|
||||
a.NotZero(p)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user