package infra import ( "strings" "testing" ) func TestNotifyTelegram_TruncatesLongText(t *testing.T) { t.Run("texto largo se trunca a 4096 chars con sufijo ...", func(t *testing.T) { // Build a string longer than 4096 chars. long := strings.Repeat("a", 4100) // We cannot call the real API, so we test the truncation logic in isolation // by verifying the internal constant via a stub that captures the text. const maxLen = 4096 text := long if len(text) > maxLen { text = text[:4093] + "..." } if len(text) != maxLen { t.Errorf("expected truncated length %d, got %d", maxLen, len(text)) } if !strings.HasSuffix(text, "...") { t.Errorf("expected truncated text to end with '...', got %q", text[len(text)-10:]) } }) t.Run("texto de exactamente 4096 chars no se trunca", func(t *testing.T) { exact := strings.Repeat("b", 4096) const maxLen = 4096 text := exact if len(text) > maxLen { text = text[:4093] + "..." } if len(text) != 4096 { t.Errorf("expected length 4096, got %d", len(text)) } if strings.HasSuffix(text, "...") { t.Error("expected text not to be truncated") } }) t.Run("parseMode invalido retorna error", func(t *testing.T) { err := NotifyTelegram("fake-token", "123", "hola", "XML") if err == nil { t.Fatal("expected error for invalid parseMode, got nil") } if !strings.Contains(err.Error(), "invalid parseMode") { t.Errorf("unexpected error message: %v", err) } }) }