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:
Adam Van Ymeren
2025-06-27 20:03:37 -07:00
committed by GitHub
parent 0952df0244
commit 7a04f298d2
19264 changed files with 1539697 additions and 84 deletions
+83
View File
@@ -0,0 +1,83 @@
package peers
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
"go.mau.fi/mautrix-telegram/pkg/gotd/tgmock"
)
func TestManager_ImportInvite(t *testing.T) {
ctx := context.Background()
hash := "aboba"
expectCheck := func(m *tgmock.Mock) *tgmock.RequestBuilder {
return m.ExpectCall(&tg.MessagesCheckChatInviteRequest{
Hash: hash,
})
}
expectResult := func(m *tgmock.Mock, class tg.ChatInviteClass) *tgmock.Mock {
return expectCheck(m).ThenResult(class)
}
t.Run("CheckError", func(t *testing.T) {
a := require.New(t)
mock, m := testManager(t)
expectCheck(mock).ThenRPCErr(getTestError())
_, err := m.ImportInvite(ctx, hash)
a.Error(err)
})
t.Run("ChatInviteAlready", func(t *testing.T) {
a := require.New(t)
mock, m := testManager(t)
testChat := getTestChannel()
expectResult(mock, &tg.ChatInviteAlready{
Chat: testChat,
})
r, err := m.ImportInvite(ctx, hash)
a.NoError(err)
a.Equal(testChat.ID, r.ID())
})
testImport := func(testChat *tg.Chat, invite tg.ChatInviteClass) func(t *testing.T) {
return func(t *testing.T) {
a := require.New(t)
mock, m := testManager(t)
expectResult(mock, invite).ExpectCall(&tg.MessagesImportChatInviteRequest{
Hash: hash,
}).ThenRPCErr(getTestError())
_, err := m.ImportInvite(ctx, hash)
a.Error(err)
expectResult(mock, invite).ExpectCall(&tg.MessagesImportChatInviteRequest{
Hash: hash,
}).ThenResult(&tg.Updates{
Chats: []tg.ChatClass{testChat},
})
r, err := m.ImportInvite(ctx, hash)
a.NoError(err)
a.Equal(testChat.ID, r.ID())
}
}
testChat := getTestChat()
t.Run("ChatInvite", testImport(testChat, &tg.ChatInvite{
Channel: false,
Broadcast: false,
Public: false,
Megagroup: false,
RequestNeeded: false,
Title: testChat.Title,
About: "",
Photo: &tg.PhotoEmpty{},
ParticipantsCount: testChat.ParticipantsCount,
}))
t.Run("ChatInvitePeek", testImport(testChat, &tg.ChatInvitePeek{
Chat: testChat,
}))
}