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,86 @@
|
||||
package fileid
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
||||
)
|
||||
|
||||
func TestFromDocument(t *testing.T) {
|
||||
doc := func(attrs ...tg.DocumentAttributeClass) *tg.Document {
|
||||
return &tg.Document{
|
||||
ID: 1,
|
||||
AccessHash: 2,
|
||||
FileReference: []byte{3},
|
||||
DCID: 4,
|
||||
Attributes: attrs,
|
||||
}
|
||||
}
|
||||
fileID := func(typ Type) FileID {
|
||||
return FileID{
|
||||
Type: typ,
|
||||
ID: 1,
|
||||
AccessHash: 2,
|
||||
FileReference: []byte{3},
|
||||
DC: 4,
|
||||
}
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
doc *tg.Document
|
||||
want FileID
|
||||
}{
|
||||
{"File", doc(), fileID(DocumentAsFile)},
|
||||
{"Animation", doc(&tg.DocumentAttributeAnimated{}), fileID(Animation)},
|
||||
{"Sticker", doc(&tg.DocumentAttributeSticker{}), fileID(Sticker)},
|
||||
{"Video", doc(&tg.DocumentAttributeVideo{}), fileID(Video)},
|
||||
{"VideoNote", doc(&tg.DocumentAttributeVideo{RoundMessage: true}), fileID(VideoNote)},
|
||||
{"Audio", doc(&tg.DocumentAttributeAudio{}), fileID(Audio)},
|
||||
{"Voice", doc(&tg.DocumentAttributeAudio{Voice: true}), fileID(Voice)},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
require.Equal(t, tt.want, FromDocument(tt.doc))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromPhoto(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
photo *tg.Photo
|
||||
size rune
|
||||
want FileID
|
||||
}{
|
||||
{
|
||||
"Photo",
|
||||
&tg.Photo{
|
||||
ID: 1,
|
||||
AccessHash: 2,
|
||||
FileReference: []byte{3},
|
||||
DCID: 4,
|
||||
},
|
||||
'x',
|
||||
FileID{
|
||||
Type: Photo,
|
||||
ID: 1,
|
||||
AccessHash: 2,
|
||||
FileReference: []byte{3},
|
||||
DC: 4,
|
||||
PhotoSizeSource: PhotoSizeSource{
|
||||
Type: PhotoSizeSourceThumbnail,
|
||||
FileType: Photo,
|
||||
ThumbnailType: 'x',
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
require.Equal(t, tt.want, FromPhoto(tt.photo, tt.size))
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user