7a04f298d2
- 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
134 lines
2.5 KiB
Go
134 lines
2.5 KiB
Go
package messages
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/tg"
|
|
)
|
|
|
|
func Test_getDocFilename(t *testing.T) {
|
|
date := time.Now()
|
|
f := date.Format(dateLayout)
|
|
|
|
tests := []struct {
|
|
name string
|
|
args *tg.Document
|
|
want string
|
|
}{
|
|
{
|
|
"Doc",
|
|
&tg.Document{
|
|
Date: int(date.Unix()),
|
|
Attributes: []tg.DocumentAttributeClass{
|
|
&tg.DocumentAttributeFilename{FileName: "10.jpg"},
|
|
},
|
|
},
|
|
"10.jpg",
|
|
},
|
|
{
|
|
"Gif",
|
|
&tg.Document{
|
|
Date: int(date.Unix()),
|
|
Attributes: []tg.DocumentAttributeClass{
|
|
&tg.DocumentAttributeAnimated{},
|
|
},
|
|
},
|
|
"doc0_" + f + ".gif",
|
|
},
|
|
{
|
|
"Video",
|
|
&tg.Document{
|
|
Date: int(date.Unix()),
|
|
Attributes: []tg.DocumentAttributeClass{
|
|
&tg.DocumentAttributeVideo{},
|
|
},
|
|
},
|
|
"doc0_" + f + ".mp4",
|
|
},
|
|
{
|
|
"Photo",
|
|
&tg.Document{
|
|
Date: int(date.Unix()),
|
|
Attributes: []tg.DocumentAttributeClass{
|
|
&tg.DocumentAttributeImageSize{},
|
|
},
|
|
},
|
|
"doc0_" + f + ".jpg",
|
|
},
|
|
{
|
|
"Audio",
|
|
&tg.Document{
|
|
Date: int(date.Unix()),
|
|
Attributes: []tg.DocumentAttributeClass{
|
|
&tg.DocumentAttributeAudio{},
|
|
},
|
|
},
|
|
"doc0_" + f + ".mp3",
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
require.Equal(t, tt.want, getDocFilename(tt.args))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestElem_File(t *testing.T) {
|
|
type results struct {
|
|
file, doc, photo bool
|
|
}
|
|
tests := []struct {
|
|
Name string
|
|
Msg tg.NotEmptyMessage
|
|
results
|
|
}{
|
|
{"EmptyMessage", &tg.Message{}, results{}},
|
|
{"ServiceMessage", &tg.MessageService{}, results{}},
|
|
{"EmptyPhoto", &tg.Message{
|
|
Media: &tg.MessageMediaPhoto{
|
|
Photo: &tg.PhotoEmpty{},
|
|
},
|
|
}, results{}},
|
|
{"EmptyDoc", &tg.Message{
|
|
Media: &tg.MessageMediaDocument{
|
|
Document: &tg.DocumentEmpty{},
|
|
},
|
|
}, results{}},
|
|
{"Photo", &tg.Message{
|
|
Media: &tg.MessageMediaPhoto{
|
|
Photo: &tg.Photo{
|
|
Sizes: []tg.PhotoSizeClass{
|
|
&tg.PhotoSize{
|
|
Type: "cock",
|
|
W: 10,
|
|
H: 10,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}, results{file: true, photo: true}},
|
|
{"Document", &tg.Message{
|
|
Media: &tg.MessageMediaDocument{
|
|
Document: &tg.Document{},
|
|
},
|
|
}, results{file: true, doc: true}},
|
|
}
|
|
for _, test := range tests {
|
|
t.Run(test.Name, func(t *testing.T) {
|
|
a := require.New(t)
|
|
var ok bool
|
|
|
|
elem := Elem{Msg: test.Msg}
|
|
_, ok = elem.File()
|
|
a.Equal(test.file, ok)
|
|
_, ok = elem.Document()
|
|
a.Equal(test.doc, ok)
|
|
_, ok = elem.Photo()
|
|
a.Equal(test.photo, ok)
|
|
})
|
|
}
|
|
}
|