100 lines
3.1 KiB
Go
100 lines
3.1 KiB
Go
package clientnotify
|
||
|
||
import (
|
||
"strings"
|
||
"testing"
|
||
"unicode/utf8"
|
||
)
|
||
|
||
func TestOrderCreatedSMSFitsOneSegment(t *testing.T) {
|
||
msg := OrderCreated("sms", "iPhone 13 · экран", "")
|
||
if n := utf8.RuneCountInString(msg); n > smsMaxLen {
|
||
t.Errorf("OrderCreated sms length = %d, want <= %d: %q", n, smsMaxLen, msg)
|
||
}
|
||
}
|
||
|
||
func TestOrderCreatedTelegramIsLongerAndFriendlier(t *testing.T) {
|
||
msg := OrderCreated("telegram", "iPhone 13 · экран", "")
|
||
if !strings.Contains(msg, "iPhone 13") {
|
||
t.Errorf("telegram message missing device label: %q", msg)
|
||
}
|
||
if utf8.RuneCountInString(msg) <= smsMaxLen {
|
||
t.Errorf("expected telegram variant to be allowed to exceed SMS length, got %q", msg)
|
||
}
|
||
}
|
||
|
||
func TestOrderCreatedIncludesTrackingURLWhenPresent(t *testing.T) {
|
||
for _, ch := range []string{"sms", "telegram"} {
|
||
msg := OrderCreated(ch, "iPhone 13", "https://x/track/abc")
|
||
if !strings.Contains(msg, "https://x/track/abc") {
|
||
t.Errorf("[%s] OrderCreated missing tracking URL: %q", ch, msg)
|
||
}
|
||
}
|
||
if sms := OrderCreated("sms", "iPhone 13", "https://x/track/abc"); utf8.RuneCountInString(sms) > smsMaxLen {
|
||
t.Errorf("OrderCreated sms with tracking URL too long: %q", sms)
|
||
}
|
||
}
|
||
|
||
func TestReadyMentionsDeviceOnBothChannels(t *testing.T) {
|
||
for _, ch := range []string{"sms", "telegram"} {
|
||
msg := Ready(ch, "iPhone 13", "https://x/track/abc")
|
||
if !strings.Contains(msg, "iPhone 13") {
|
||
t.Errorf("[%s] Ready message missing device: %q", ch, msg)
|
||
}
|
||
}
|
||
if sms := Ready("sms", "iPhone 13", "https://x/track/abc"); utf8.RuneCountInString(sms) > smsMaxLen {
|
||
t.Errorf("Ready sms too long: %q", sms)
|
||
}
|
||
}
|
||
|
||
func TestStatusChangedIncludesLabel(t *testing.T) {
|
||
msg := StatusChanged("telegram", "iPhone 13", "В ремонте", "")
|
||
if !strings.Contains(msg, "В ремонте") {
|
||
t.Errorf("missing status label: %q", msg)
|
||
}
|
||
}
|
||
|
||
func TestStatusChangedIncludesTrackingURLWhenPresent(t *testing.T) {
|
||
for _, ch := range []string{"sms", "telegram"} {
|
||
msg := StatusChanged(ch, "iPhone 13", "В ремонте", "https://x/track/abc")
|
||
if !strings.Contains(msg, "https://x/track/abc") {
|
||
t.Errorf("[%s] StatusChanged missing tracking URL: %q", ch, msg)
|
||
}
|
||
}
|
||
}
|
||
|
||
func TestWarrantyExpiringIncludesDate(t *testing.T) {
|
||
msg := WarrantyExpiring("sms", "iPhone 13", "15.09.2026")
|
||
if !strings.Contains(msg, "15.09.2026") {
|
||
t.Errorf("missing warranty date: %q", msg)
|
||
}
|
||
if utf8.RuneCountInString(msg) > smsMaxLen {
|
||
t.Errorf("WarrantyExpiring sms too long: %q", msg)
|
||
}
|
||
}
|
||
|
||
func TestLoyaltyAccruedIncludesPoints(t *testing.T) {
|
||
msg := LoyaltyAccrued("sms", 150)
|
||
if !strings.Contains(msg, "150") {
|
||
t.Errorf("missing points: %q", msg)
|
||
}
|
||
}
|
||
|
||
func TestSanitizeStripsControlCharacters(t *testing.T) {
|
||
got := sanitize("Готово\r\nзабирайте\t!")
|
||
if strings.ContainsAny(got, "\r\n\t") {
|
||
t.Errorf("sanitize left control chars: %q", got)
|
||
}
|
||
}
|
||
|
||
func TestTruncateRespectsRuneBoundaries(t *testing.T) {
|
||
long := strings.Repeat("б", 100)
|
||
got := truncate(long, 70)
|
||
if n := utf8.RuneCountInString(got); n != 70 {
|
||
t.Errorf("truncate length = %d, want 70", n)
|
||
}
|
||
if !utf8.ValidString(got) {
|
||
t.Errorf("truncate produced invalid UTF-8: %q", got)
|
||
}
|
||
}
|