Files
wx-win-agent/control-plane/send_text_payload_test.go
T
rogee edba7d0d38
Build web service image / build (push) Successful in 1m15s
feat: support long text and safe attachment batches
2026-09-30 09:16:36 +08:00

40 lines
1.2 KiB
Go

package controlplane
import (
"encoding/json"
"strings"
"testing"
)
func TestValidSendTextPayloadSupportsBoundedLongText(t *testing.T) {
cases := []struct {
name string
text string
confirmed bool
want bool
}{
{name: "single message", text: "hello", confirmed: true, want: true},
{name: "long text", text: strings.Repeat("中", 20_000), confirmed: true, want: true},
{name: "over limit", text: strings.Repeat("中", 20_001), confirmed: true, want: false},
{name: "unpaired input", text: "hello\x00world", confirmed: true, want: false},
{name: "blank", text: " \n\t", confirmed: true, want: false},
{name: "not confirmed", text: "hello", confirmed: false, want: false},
}
for _, test := range cases {
t.Run(test.name, func(t *testing.T) {
payload, err := json.Marshal(struct {
TargetID string `json:"target_id"`
Text string `json:"text"`
Confirmed bool `json:"confirmed"`
}{TargetID: "test-session", Text: test.text, Confirmed: test.confirmed})
if err != nil {
t.Fatal(err)
}
if got := validSendTextPayload(json.RawMessage(payload)); got != test.want {
t.Fatalf("validSendTextPayload() = %v, want %v", got, test.want)
}
})
}
}