owpengram-server/internal/rpc/external_media_rpc_test.go

41 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package rpc
import (
"context"
"testing"
"github.com/iamxvbaba/td/tg"
"github.com/iamxvbaba/td/tgerr"
"telesrv/internal/domain"
)
// TestResolveInputMediaExternal 验证 inputMediaPhoto/DocumentExternal 路由到 Files
// 外链抓取,并把结果投影为 photo/document 媒体;空 URLfakeFiles 拒)→ MEDIA_INVALID。
func TestResolveInputMediaExternal(t *testing.T) {
r := &Router{deps: Deps{Files: &fakeFiles{}}}
ctx := context.Background()
// 外链图片。
media, err := r.resolveInputMedia(ctx, 1001, &tg.InputMediaPhotoExternal{URL: "https://example.com/cat.png", Spoiler: true})
if err != nil {
t.Fatalf("photo external: %v", err)
}
if media == nil || media.Kind != domain.MessageMediaKindPhoto || media.Photo == nil || !media.Spoiler {
t.Fatalf("photo external media = %+v, want spoiler photo", media)
}
// 外链文档。
media, err = r.resolveInputMedia(ctx, 1001, &tg.InputMediaDocumentExternal{URL: "https://example.com/doc.pdf"})
if err != nil {
t.Fatalf("document external: %v", err)
}
if media == nil || media.Kind != domain.MessageMediaKindDocument || media.Document == nil {
t.Fatalf("document external media = %+v, want document", media)
}
// 空 URL抓取失败→ MEDIA_INVALID。
if _, err := r.resolveInputMedia(ctx, 1001, &tg.InputMediaPhotoExternal{URL: ""}); !tgerr.Is(err, "MEDIA_INVALID") {
t.Fatalf("empty url photo err = %v, want MEDIA_INVALID", err)
}
}