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,99 @@
|
||||
package peers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
||||
)
|
||||
|
||||
func getTestBroadcast() *tg.Channel {
|
||||
testChannel := getTestChannel()
|
||||
testChannel.ID *= 3
|
||||
testChannel.Broadcast = true
|
||||
testChannel.Megagroup = false
|
||||
return testChannel
|
||||
}
|
||||
|
||||
func TestBroadcast_SetDiscussionGroup(t *testing.T) {
|
||||
a := require.New(t)
|
||||
ctx := context.Background()
|
||||
mock, m := testManager(t)
|
||||
|
||||
b := m.Channel(getTestSuperGroup())
|
||||
|
||||
s, ok := m.Channel(getTestBroadcast()).ToBroadcast()
|
||||
a.True(ok)
|
||||
|
||||
mock.ExpectCall(&tg.ChannelsSetDiscussionGroupRequest{
|
||||
Broadcast: s.InputChannel(),
|
||||
Group: b.InputChannel(),
|
||||
}).ThenRPCErr(getTestError())
|
||||
a.Error(s.SetDiscussionGroup(ctx, b.InputChannel()))
|
||||
|
||||
mock.ExpectCall(&tg.ChannelsSetDiscussionGroupRequest{
|
||||
Broadcast: s.InputChannel(),
|
||||
Group: b.InputChannel(),
|
||||
}).ThenTrue()
|
||||
a.NoError(s.SetDiscussionGroup(ctx, b.InputChannel()))
|
||||
}
|
||||
|
||||
func TestBroadcast_ToggleSignatures(t *testing.T) {
|
||||
a := require.New(t)
|
||||
ctx := context.Background()
|
||||
mock, m := testManager(t)
|
||||
|
||||
ch := m.Channel(getTestBroadcast())
|
||||
|
||||
s, ok := ch.ToBroadcast()
|
||||
a.True(ok)
|
||||
|
||||
mock.ExpectCall(&tg.ChannelsToggleSignaturesRequest{
|
||||
Channel: s.InputChannel(),
|
||||
SignaturesEnabled: true,
|
||||
}).ThenRPCErr(getTestError())
|
||||
a.Error(s.ToggleSignatures(ctx, true))
|
||||
|
||||
mock.ExpectCall(&tg.ChannelsToggleSignaturesRequest{
|
||||
Channel: s.InputChannel(),
|
||||
SignaturesEnabled: true,
|
||||
}).ThenResult(&tg.Updates{})
|
||||
a.NoError(s.ToggleSignatures(ctx, true))
|
||||
}
|
||||
|
||||
func TestBroadcast_DiscussionGroup(t *testing.T) {
|
||||
a := require.New(t)
|
||||
ctx := context.Background()
|
||||
mock, m := testManager(t)
|
||||
|
||||
linkedChat := getTestChat()
|
||||
linkedSupergroup := getTestSuperGroup()
|
||||
linkedChat.SetMigratedTo(linkedSupergroup.AsInput())
|
||||
ch := m.Channel(getTestBroadcast())
|
||||
|
||||
s, ok := ch.ToBroadcast()
|
||||
a.True(ok)
|
||||
|
||||
mock.ExpectCall(&tg.ChannelsGetFullChannelRequest{
|
||||
Channel: s.InputChannel(),
|
||||
}).ThenRPCErr(getTestError())
|
||||
_, ok, err := s.DiscussionGroup(ctx)
|
||||
a.False(ok)
|
||||
a.Error(err)
|
||||
|
||||
full := getTestChannelFull()
|
||||
full.SetLinkedChatID(linkedChat.ID)
|
||||
|
||||
mock.ExpectCall(&tg.ChannelsGetFullChannelRequest{
|
||||
Channel: s.InputChannel(),
|
||||
}).ThenResult(&tg.MessagesChatFull{
|
||||
FullChat: full,
|
||||
Chats: []tg.ChatClass{linkedChat, linkedSupergroup},
|
||||
})
|
||||
d, ok, err := s.DiscussionGroup(ctx)
|
||||
a.True(ok)
|
||||
a.NoError(err)
|
||||
a.Equal(linkedSupergroup.ID, d.ID())
|
||||
}
|
||||
Reference in New Issue
Block a user