mirror of
https://github.com/usememos/memos.git
synced 2024-12-25 04:13:07 +03:00
c5a1f4c839
* feat: format message from telegram and download documents * fix: remove bool in expression * refactor: convert to markdown * refactor: resolve remarks and add support new message types * refactor: resolve remarks * feat: add test for mime type --------- Co-authored-by: Александр Тумайкин <AATumaykin@tsum.ru>
84 lines
1.5 KiB
Go
84 lines
1.5 KiB
Go
package telegram
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGetMimeType(t *testing.T) {
|
|
tests := []struct {
|
|
mimeType string
|
|
fileName string
|
|
expected string
|
|
}{
|
|
{
|
|
fileName: "file.jpg",
|
|
mimeType: "image/jpeg",
|
|
expected: "image/jpeg",
|
|
},
|
|
{
|
|
fileName: "file.png",
|
|
mimeType: "image/png",
|
|
expected: "image/png",
|
|
},
|
|
{
|
|
fileName: "file.pdf",
|
|
mimeType: "application/pdf",
|
|
expected: "application/pdf",
|
|
},
|
|
{
|
|
fileName: "file.php",
|
|
mimeType: "application/x-php",
|
|
expected: "application/x-php",
|
|
},
|
|
{
|
|
fileName: "file.xlsx",
|
|
mimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
expected: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
},
|
|
{
|
|
fileName: "file.oga",
|
|
mimeType: "audio/ogg",
|
|
expected: "audio/ogg",
|
|
},
|
|
{
|
|
fileName: "file.jpg",
|
|
expected: "image/jpeg",
|
|
},
|
|
{
|
|
fileName: "file.png",
|
|
expected: "image/png",
|
|
},
|
|
{
|
|
fileName: "file.mp4",
|
|
expected: "video/mp4",
|
|
},
|
|
{
|
|
fileName: "file.pdf",
|
|
expected: "application/octet-stream",
|
|
},
|
|
{
|
|
fileName: "file.oga",
|
|
expected: "audio/ogg",
|
|
},
|
|
{
|
|
fileName: "file.xlsx",
|
|
expected: "application/octet-stream",
|
|
},
|
|
{
|
|
fileName: "file.txt",
|
|
expected: "application/octet-stream",
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
attachment := Attachment{
|
|
FileName: test.fileName,
|
|
MimeType: test.mimeType,
|
|
}
|
|
|
|
require.Equal(t, test.expected, attachment.GetMimeType())
|
|
}
|
|
}
|