package dingtalk import ( "testing" "github.com/Tencent/WeKnora/internal/im" ) func TestParseDingTalkStreamPayloadPicture(t *testing.T) { messageType, content, fileKey := parseDingTalkStreamPayload("picture", map[string]interface{}{ "downloadCode": "stream-download-code", }, "ignored text") if messageType != im.MessageTypeImage { t.Fatalf("MessageType = %q, want image", messageType) } if content != "" { t.Fatalf("content = %q, want empty", content) } if fileKey != "stream-download-code" { t.Fatalf("fileKey = %q", fileKey) } } func TestParseDingTalkStreamPayloadText(t *testing.T) { messageType, content, fileKey := parseDingTalkStreamPayload("text", nil, " hello ") if messageType != im.MessageTypeText || content != "hello" || fileKey != "" { t.Fatalf("got type=%q content=%q fileKey=%q", messageType, content, fileKey) } } func TestParseDingTalkStreamPayloadPictureJSONString(t *testing.T) { messageType, _, fileKey := parseDingTalkStreamPayload("picture", `{"downloadCode":"string-code"}`, "") if messageType != im.MessageTypeImage || fileKey != "string-code" { t.Fatalf("got type=%q fileKey=%q", messageType, fileKey) } }