Skip to content

Commit a4268c0

Browse files
committed
feat: E2E telegramify test
1 parent 4bbb409 commit a4268c0

5 files changed

Lines changed: 30 additions & 4 deletions

File tree

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export TEST_BOT_TOKEN=
2+
export RECEIVER_PEER_ID=

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module github.com/ai-shift/tgmd
22

33
go 1.24.3
44

5-
require github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b
6-
7-
require github.com/yuin/goldmark v1.7.12 // indirect
5+
require (
6+
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1
7+
github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b
8+
)

go.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
2+
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
13
github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b h1:EY/KpStFl60qA17CptGXhwfZ+k1sFNJIUNR8DdbcuUk=
24
github.com/gomarkdown/markdown v0.0.0-20250311123330-531bef5e742b/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
3-
github.com/yuin/goldmark v1.7.12/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=

tgmd_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"slices"
77
"strings"
88
"testing"
9+
"strconv"
10+
11+
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
912
)
1013

1114
func init() {
@@ -25,3 +28,21 @@ func TestRenderTelegram(t *testing.T) {
2528
}
2629
}
2730
}
31+
32+
func TestRenderE2E(t *testing.T) {
33+
bot, err := tgbotapi.NewBotAPI(os.Getenv("TEST_BOT_TOKEN"))
34+
receiverID, _ := strconv.ParseInt(os.Getenv("RECEIVER_PEER_ID"), 10, 64)
35+
if err != nil {
36+
t.Errorf("failed to create bot API with %s", err)
37+
t.Fatal()
38+
}
39+
40+
input, _ := os.ReadFile("_testdata/input1.md")
41+
got := Telegramify(string(input))
42+
msg := tgbotapi.NewMessage(receiverID, got)
43+
msg.ParseMode = "MarkdownV2"
44+
_, err = bot.Send(msg)
45+
if err != nil {
46+
t.Errorf("failed to send telegram messge with %s\nMessage: %s", err, got)
47+
}
48+
}

0 commit comments

Comments
 (0)