diff options
author | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2022-03-15 00:57:03 +0300 |
---|---|---|
committer | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2022-03-15 00:57:03 +0300 |
commit | 976abf68ce101a4fe6508effde72234951efeea5 (patch) | |
tree | b9395e677cbee28e8af97ed66301ceba165beaa0 /telegram/utils_test.go | |
parent | d6b3ed3aaa518c5f80f7eceddede507af592a45c (diff) |
Fetch previews for files
Diffstat (limited to 'telegram/utils_test.go')
-rw-r--r-- | telegram/utils_test.go | 57 |
1 files changed, 48 insertions, 9 deletions
diff --git a/telegram/utils_test.go b/telegram/utils_test.go index 5caf2c5..43634c9 100644 --- a/telegram/utils_test.go +++ b/telegram/utils_test.go @@ -130,7 +130,7 @@ func TestFormatMessageMultilinePreview(t *testing.T) { } } -func TestFormatContent(t *testing.T) { +func TestFormatFile(t *testing.T) { file := client.File{ Size: 23899, Local: &client.LocalFile{ @@ -146,12 +146,34 @@ func TestFormatContent(t *testing.T) { }, } - content := c.formatFile(&file) + content := c.formatFile(&file, false) if content != ". (23 kbytes) | " { t.Errorf("Wrong file label: %v", content) } } +func TestFormatPreview(t *testing.T) { + file := client.File{ + Size: 23899, + Local: &client.LocalFile{ + Path: "c:/pron/smokovnica_vhsrip.mov", + }, + Remote: &client.RemoteFile{ + UniqueId: "aZaZaZ", + }, + } + c := Client{ + content: &config.TelegramContentConfig{ + Link: "localhvost", + }, + } + + content := c.formatFile(&file, true) + if content != "" { + t.Errorf("Wrong preview label: %v", content) + } +} + func TestMessageToTextSticker(t *testing.T) { sticker := client.Message{ Content: &client.MessageSticker{ @@ -361,7 +383,7 @@ func TestMessageToPrefix1(t *testing.T) { }, }, } - prefix := (&Client{Session: &persistence.Session{}}).messageToPrefix(&message, "") + prefix := (&Client{Session: &persistence.Session{}}).messageToPrefix(&message, "", "") if prefix != "➡ 42 | fwd: ziz" { t.Errorf("Wrong prefix: %v", prefix) } @@ -376,8 +398,8 @@ func TestMessageToPrefix2(t *testing.T) { }, }, } - prefix := (&Client{Session: &persistence.Session{}}).messageToPrefix(&message, "") - if prefix != "⬅ 56 | fwd: (zaz)" { + prefix := (&Client{Session: &persistence.Session{}}).messageToPrefix(&message, "y.jpg", "") + if prefix != "⬅ 56 | fwd: (zaz) | preview: y.jpg" { t.Errorf("Wrong prefix: %v", prefix) } } @@ -386,11 +408,13 @@ func TestMessageToPrefix3(t *testing.T) { message := client.Message{ Id: 56, ForwardInfo: &client.MessageForwardInfo{ - Origin: &client.MessageForwardOriginChannel{}, + Origin: &client.MessageForwardOriginChannel{ + AuthorSignature: "zuz", + }, }, } - prefix := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "a.jpg") - if prefix != "< 56 | fwd: | file: a.jpg" { + prefix := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "", "a.jpg") + if prefix != "< 56 | fwd: (zuz) | file: a.jpg" { t.Errorf("Wrong prefix: %v", prefix) } } @@ -400,8 +424,23 @@ func TestMessageToPrefix4(t *testing.T) { Id: 23, IsOutgoing: true, } - prefix := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "") + prefix := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "", "") if prefix != "> 23" { t.Errorf("Wrong prefix: %v", prefix) } } + +func TestMessageToPrefix5(t *testing.T) { + message := client.Message{ + Id: 560, + ForwardInfo: &client.MessageForwardInfo{ + Origin: &client.MessageForwardOriginChat{ + AuthorSignature: "zyz", + }, + }, + } + prefix := (&Client{Session: &persistence.Session{AsciiArrows: true}}).messageToPrefix(&message, "h.jpg", "a.jpg") + if prefix != "< 560 | fwd: (zyz) | preview: h.jpg | file: a.jpg" { + t.Errorf("Wrong prefix: %v", prefix) + } +} |