aboutsummaryrefslogtreecommitdiff
path: root/cmds/rss_test.go
blob: 5ff3405e06cc28071605e2858ee2d34eb0cce6ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Golden test for the RSS renderer: fixed runs in, exact XML out. Also
// pins batch ordering (newest first) and XML escaping of item text.
package cmds

import (
	"testing"
	"time"

	"fluxrec/core"
)

func TestRenderRSSGolden(t *testing.T) {
	at := func(day, h, m int) time.Time {
		return time.Date(2024, 3, day, h, m, 0, 0, time.UTC)
	}
	med := 0.55 // over all scored entries in the first batch, not just kept
	runs := []core.RunRow{
		{
			RanAt: at(1, 6, 0), EntriesSeen: 40, ScoreMedian: &med,
			Kept: []core.KeptItem{
				{EntryID: 101, URL: "https://example.com/a?x=1&y=2", Title: "Alpha & Omega",
					FeedTitle: "Feed A", PublishedAt: at(1, 5, 0),
					Content: "x < y", Score: 0.9, Kind: core.KindRanked},
				{EntryID: 102, URL: "https://example.com/b", Title: "Beta",
					FeedTitle:   "A Feed With An Extremely Long And Descriptive Title Here",
					PublishedAt: at(1, 5, 30),
					Content:     "second body", Score: 0.2, Kind: core.KindRandom},
			},
		},
		{
			RanAt: at(1, 12, 0), EntriesSeen: 12, // nil median: pre-field run row
			Kept: []core.KeptItem{
				{EntryID: 103, URL: "https://example.com/c", Title: "Gamma",
					FeedTitle: "Feed A", PublishedAt: at(1, 11, 0),
					Content: "", Score: 0.8, Kind: core.KindRunnerUp},
			},
		},
	}

	got, err := RenderRSS(runs)
	if err != nil {
		t.Fatalf("RenderRSS: %v", err)
	}
	want := `<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Fluxrecs</title>
    <description>Top-scored Miniflux entries, refreshed on a schedule.</description>
    <item>
      <title>Gamma — Feed A</title>
      <link>https://example.com/c</link>
      <guid isPermaLink="false">mf:103</guid>
      <pubDate>Fri, 01 Mar 2024 11:00:00 +0000</pubDate>
      <description>&lt;p&gt;&lt;em&gt;Feed A · score 0.80&lt;/em&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Alpha &amp; Omega — Feed A</title>
      <link>https://example.com/a?x=1&amp;y=2</link>
      <guid isPermaLink="false">mf:101</guid>
      <pubDate>Fri, 01 Mar 2024 05:00:00 +0000</pubDate>
      <description>&lt;p&gt;&lt;em&gt;Feed A · score 0.90 · batch median 0.55&lt;/em&gt;&lt;/p&gt;&#xA;x &lt; y</description>
    </item>
    <item>
      <title>Beta — A Feed With An Extremely Long And Descri…</title>
      <link>https://example.com/b</link>
      <guid isPermaLink="false">mf:102</guid>
      <pubDate>Fri, 01 Mar 2024 05:30:00 +0000</pubDate>
      <description>&lt;p&gt;&lt;em&gt;A Feed With An Extremely Long And Descriptive Title Here · score 0.20 · batch median 0.55&lt;/em&gt;&lt;/p&gt;&#xA;second body</description>
    </item>
  </channel>
</rss>`
	if string(got) != want {
		t.Errorf("RSS mismatch.\ngot:\n%s", got)
	}
}