welcome message: link @zio with a mention entity
This commit is contained in:
parent
4d781a52bb
commit
d4fe056854
2 changed files with 62 additions and 2 deletions
|
|
@ -3,6 +3,7 @@ package domain
|
|||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
"unicode/utf16"
|
||||
)
|
||||
|
||||
func TestWelcomeMessageContentAndFingerprint(t *testing.T) {
|
||||
|
|
@ -52,3 +53,25 @@ func TestNextWelcomeRevision(t *testing.T) {
|
|||
t.Fatalf("zero revision err = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOfficialWelcomeMessageLinksUpdatesChannel(t *testing.T) {
|
||||
body := "Welcome! Join " + officialUpdatesChannelMention + " for updates."
|
||||
msg, err := OfficialWelcomeMessage(1780243200, body, 1_700_000_000)
|
||||
if err != nil {
|
||||
t.Fatalf("body %q: %v", body, err)
|
||||
}
|
||||
if len(msg.Entities) != 1 {
|
||||
t.Fatalf("body %q: entities = %+v, want one mention", body, msg.Entities)
|
||||
}
|
||||
ent := msg.Entities[0]
|
||||
if ent.Type != MessageEntityMention {
|
||||
t.Fatalf("entity type = %q, want mention", ent.Type)
|
||||
}
|
||||
units := utf16.Encode([]rune(msg.Body))
|
||||
if ent.Offset < 0 || ent.Length <= 0 || ent.Offset+ent.Length > len(units) {
|
||||
t.Fatalf("entity %+v out of bounds for body of %d utf16 units", ent, len(units))
|
||||
}
|
||||
if got := string(utf16.Decode(units[ent.Offset : ent.Offset+ent.Length])); got != officialUpdatesChannelMention {
|
||||
t.Fatalf("entity spans %q, want %q", got, officialUpdatesChannelMention)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue