41 lines
1.4 KiB
Go
41 lines
1.4 KiB
Go
package dingtalk
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.zheromiku.top/Weknora/dobotai-platform/internal/outboundimage"
|
|
)
|
|
|
|
type diagFetcher struct{}
|
|
|
|
func (diagFetcher) Fetch(ctx context.Context, ref string) ([]byte, string, error) {
|
|
return []byte("PNGDATA"), "image/png", nil
|
|
}
|
|
|
|
type diagPublisher struct{}
|
|
|
|
func (diagPublisher) Publish(ctx context.Context, data []byte, contentType string) (string, error) {
|
|
return "https://weknora-api-test.dobot.cn/dingtalk/i/a87f73b8-15cb-546e-ba53-bf93dade916f", nil
|
|
}
|
|
|
|
// The outbound rewrite must publish a resource image and keep it in the card
|
|
// body. A reference whose handle contains "_x" (…ZM_pltQ) used to be mangled by
|
|
// the math normalizer, which made the image unpublishable and the sanitizer
|
|
// drop the whole line.
|
|
func TestRewriteOutboundContentKeepsPublishedImage(t *testing.T) {
|
|
content := "\n\n公式:$r = \\sqrt{X^2 + Y^2}$\n"
|
|
h := &Handler{
|
|
outboundRewriter: outboundimage.NewRewriter(diagFetcher{}, diagPublisher{}, 50),
|
|
groupTablesFinal: true,
|
|
}
|
|
out := h.rewriteOutboundContent(context.Background(), content)
|
|
if !strings.Contains(out, " {
|
|
t.Fatalf("published image missing from card content: %q", out)
|
|
}
|
|
if !strings.Contains(out, "r = √(X² + Y²)") {
|
|
t.Fatalf("formula not converted: %q", out)
|
|
}
|
|
}
|