yao/integrations/telegram/message_test.go
Max ea9e070f29 Enhance robot integration with Telegram and improve event handling
- Add Telegram integration support by introducing a dispatcher for handling Telegram events and messages.
- Implement event notifications for robot configuration changes (creation, update, deletion) to facilitate integration with external services.
- Refactor the robot initialization process to load robots into cache and start the dispatcher, improving the overall system setup.
- Update the delivery event structure to include additional metadata for better context during message handling.
- Enhance logging capabilities for better observability during robot execution and event processing.
2026-03-01 22:03:25 +08:00

64 lines
1.6 KiB
Go

package telegram
import (
"testing"
)
func TestDetectMediaType(t *testing.T) {
cases := []struct {
mime string
expected MediaType
}{
{"image/jpeg", MediaPhoto},
{"image/png", MediaPhoto},
{"IMAGE/PNG", MediaPhoto},
{"image/gif", MediaAnimation},
{"image/webp", MediaSticker},
{"video/mp4", MediaVideo},
{"video/webm", MediaVideo},
{"audio/mpeg", MediaAudio},
{"audio/mp3", MediaAudio},
{"audio/ogg", MediaVoice},
{"audio/ogg; codecs=opus", MediaVoice},
{"application/pdf", MediaDocument},
{"application/octet-stream", MediaDocument},
{"text/plain", MediaDocument},
{"", MediaDocument},
}
for _, tc := range cases {
got := DetectMediaType(tc.mime)
if got != tc.expected {
t.Errorf("DetectMediaType(%q) = %q, want %q", tc.mime, got, tc.expected)
}
}
}
func TestParseWrapper(t *testing.T) {
cases := []struct {
input string
manager string
fileID string
wantErr bool
}{
{"__yao.attachment://abc123", "__yao.attachment", "abc123", false},
{"__custom.uploader://xyz", "__custom.uploader", "xyz", false},
{"no-separator", "", "", true},
{"://empty-manager", "", "empty-manager", false},
}
for _, tc := range cases {
manager, fileID, err := parseWrapper(tc.input)
if tc.wantErr {
if err == nil {
t.Errorf("parseWrapper(%q) expected error, got nil", tc.input)
}
continue
}
if err != nil {
t.Errorf("parseWrapper(%q) unexpected error: %v", tc.input, err)
continue
}
if manager != tc.manager || fileID != tc.fileID {
t.Errorf("parseWrapper(%q) = (%q, %q), want (%q, %q)", tc.input, manager, fileID, tc.manager, tc.fileID)
}
}
}