29 lines
969 B
Go
29 lines
969 B
Go
package domain
|
|
|
|
import (
|
|
"testing"
|
|
"unicode/utf16"
|
|
)
|
|
|
|
func TestOfficialWelcomeMessageLinksUpdatesChannel(t *testing.T) {
|
|
for _, method := range []string{"phone number", "email"} {
|
|
msg, err := OfficialWelcomeMessage(1780243200, method, 1_700_000_000)
|
|
if err != nil {
|
|
t.Fatalf("method %q: %v", method, err)
|
|
}
|
|
if len(msg.Entities) != 1 {
|
|
t.Fatalf("method %q: entities = %+v, want one mention", method, 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)
|
|
}
|
|
}
|
|
}
|