all repos

rss-tools @ 63e22ef23f74cc61b571d71b3c938c26bbdc105f

get rss feed from sources that(i need and) dont provide one

rss-tools/sources/telegram/telegram_test.go (view raw)

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
telegram: fetch links title, 1 month ago
1
package telegram
2
3
import (
4
	"strings"
5
	"testing"
6
	"time"
7
8
	"olexsmir.xyz/x/is"
9
)
10
11
func TestFeedEntryFromMessageWithImage(t *testing.T) {
12
	msg := &Message{
13
		MessageID:     42,
14
		Caption:       "hello <world>",
15
		Date:          time.Date(2026, 4, 22, 19, 38, 0, 0, time.UTC).Unix(),
16
		PhotoBase64:   "YWJj",
17
		PhotoMIMEType: "image/png",
18
	}
19
20
	entry := feedEntryFromMessage(msg)
21
	is.Equal(t, "🖼️ [2026-04-22]", entry.Title)
22
	is.Equal(t, "html", entry.ContentType)
23
	if !strings.Contains(entry.Content, "<p>hello &lt;world&gt;</p>") {
24
		t.Fatalf("expected escaped text in image entry: %s", entry.Content)
25
	}
26
	if !strings.Contains(entry.Content, `src="data:image/png;base64,YWJj"`) {
27
		t.Fatalf("expected image data URI in image entry: %s", entry.Content)
28
	}
29
}
30
31
func TestFeedEntryFromMessageTextOnly(t *testing.T) {
32
	msg := &Message{
33
		MessageID: 11,
34
		Text:      "plain text",
35
		Date:      time.Date(2026, 4, 22, 19, 38, 0, 0, time.UTC).Unix(),
36
	}
37
38
	entry := feedEntryFromMessage(msg)
39
	is.Equal(t, "plain text", entry.Title)
40
	is.Equal(t, "", entry.ContentType)
41
	is.Equal(t, "plain text", entry.Content)
42
}
43
44
func TestFeedEntryFromMessageLinkifiesAndAddsAtomLinks(t *testing.T) {
45
	msg := &Message{
46
		MessageID: 15,
47
		Text:      "watch https://example.com and https://youtu.be/dQw4w9WgXcQ.",
48
		Date:      time.Date(2026, 4, 23, 11, 0, 0, 0, time.UTC).Unix(),
49
	}
50
51
	entry := feedEntryFromMessage(msg)
52
	is.Equal(t, "html", entry.ContentType)
53
	if !strings.Contains(entry.Content, `<a href="https://example.com">https://example.com</a>`) {
54
		t.Fatalf("expected generic link in content: %s", entry.Content)
55
	}
56
	if !strings.Contains(entry.Content, `<a href="https://youtu.be/dQw4w9WgXcQ">https://youtu.be/dQw4w9WgXcQ</a>`) {
57
		t.Fatalf("expected youtube link in content: %s", entry.Content)
58
	}
59
60
	is.Equal(t, 2, len(entry.Links))
61
	is.Equal(t, "https://example.com", entry.Links[0].Href)
62
	is.Equal(t, "https://www.youtube.com/watch?v=dQw4w9WgXcQ", entry.Links[1].Href)
63
	is.Equal(t, "yt:video:dQw4w9WgXcQ", entry.ID)
64
}
65
66
func TestFeedEntryFromMessageUsesStoredLinkTitleForSingleLink(t *testing.T) {
67
	msg := &Message{
68
		MessageID: 16,
69
		Text:      "https://example.com/post",
70
		Date:      time.Date(2026, 4, 23, 11, 0, 0, 0, time.UTC).Unix(),
71
		LinkTitles: map[string]string{
72
			"https://example.com/post": "Example Post Title",
73
		},
74
	}
75
76
	entry := feedEntryFromMessage(msg)
77
	is.Equal(t, "Example Post Title", entry.Title)
78
}