Jobmaker-LdPost/shared/telegram/bot_test.go
Ricardo Carneiro ea532659b0 feat: pipeline inicial ldpost-squad (6 agentes)
Pipeline completo de publicação no LinkedIn:
evaluator → redator → editor → art → director → publisher

- Seed com 37 posts em _sugestoes.md
- Sorteio de formato com N=3 bloqueados (format-history)
- Reciclagem mensal de posts com rotação de formato
- Revisão via Telegram com chat livre (Gemini 2.5 Flash)
- Publicação via LinkedIn API (OAuth2)
- Makefile com targets para Windows/Linux/ARM64

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 18:55:39 -03:00

77 lines
2.0 KiB
Go

package telegram_test
import (
"testing"
"ldpost/shared/telegram"
)
func TestEscapeMarkdown(t *testing.T) {
// All MarkdownV2 special chars must be escaped with backslash
special := []rune{'_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!'}
for _, ch := range special {
input := string(ch)
got := telegram.EscapeMarkdown(input)
want := "\\" + input
if got != want {
t.Errorf("EscapeMarkdown(%q) = %q, want %q", input, got, want)
}
}
}
func TestEscapeMarkdown_PlainText(t *testing.T) {
cases := []struct {
input string
want string
}{
{"hello world", "hello world"},
{"", ""},
{"abc123", "abc123"},
}
for _, c := range cases {
got := telegram.EscapeMarkdown(c.input)
if got != c.want {
t.Errorf("EscapeMarkdown(%q) = %q, want %q", c.input, got, c.want)
}
}
}
func TestEscapeMarkdown_MixedContent(t *testing.T) {
input := "Hello, world! How are you?"
got := telegram.EscapeMarkdown(input)
// '!' and '.' and '?' (not in special) — only '!' should be escaped
// ',' not special, '!' is special, '.' is special, '?' not special
// expected: "Hello, world\! How are you?"
want := `Hello, world\! How are you?`
if got != want {
t.Errorf("EscapeMarkdown(%q)\n got: %q\n want: %q", input, got, want)
}
}
func TestEscapeMarkdown_CodeBlock(t *testing.T) {
// Typical tech content
input := "Use fmt.Println(\"hello\") in Go"
got := telegram.EscapeMarkdown(input)
// '.' is special → escaped
// '(' and ')' are special → escaped
// '"' is not special
want := `Use fmt\.Println\("hello"\) in Go`
if got != want {
t.Errorf("EscapeMarkdown(%q)\n got: %q\n want: %q", input, got, want)
}
}
func TestNewBot(t *testing.T) {
bot := telegram.NewBot("test-token", "123456")
if bot == nil {
t.Fatal("NewBot retornou nil")
}
if bot.Token != "test-token" {
t.Errorf("Token: got %q, want %q", bot.Token, "test-token")
}
if bot.ChatID != "123456" {
t.Errorf("ChatID: got %q, want %q", bot.ChatID, "123456")
}
}