895b23d2da
The finished-reply notification now carries up to 1000 characters of the reply (was 200), keeping its paragraph breaks for the app's expanded notification; ntfy still gets it on one line within its 2048-byte limit.
27 lines
884 B
Go
27 lines
884 B
Go
package server
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"unicode/utf8"
|
|
)
|
|
|
|
func TestReplyNotificationKeepsParagraphs(t *testing.T) {
|
|
got := paragraphs(" First line \r\n\r\n\n\n Second paragraph \nthird\x00 line\n\n")
|
|
if want := "First line\n\nSecond paragraph\nthird line"; got != want {
|
|
t.Fatalf("paragraphs = %q, want %q", got, want)
|
|
}
|
|
_, body := chatReplyText("Chat", "One\n\nTwo")
|
|
if body != "One\n\nTwo" {
|
|
t.Fatalf("app body should keep paragraph breaks, got %q", body)
|
|
}
|
|
// ntfy gets the same text on one line.
|
|
if flat := singleLine(body); strings.Contains(flat, "\n") || flat != "One Two" {
|
|
t.Fatalf("ntfy body = %q", flat)
|
|
}
|
|
long := truncateRunes(strings.Repeat("a", 1500), chatReplyBodyRunes)
|
|
if n := utf8.RuneCountInString(long); n != chatReplyBodyRunes+1 || chatReplyBodyRunes != 1000 {
|
|
t.Fatalf("excerpt is %d runes (limit %d)", n, chatReplyBodyRunes)
|
|
}
|
|
}
|