-
-
Notifications
You must be signed in to change notification settings - Fork 225
Expand file tree
/
Copy pathrss2.enclosure.test.ts
More file actions
114 lines (98 loc) · 3.17 KB
/
Copy pathrss2.enclosure.test.ts
File metadata and controls
114 lines (98 loc) · 3.17 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { Feed } from "../feed";
test("RSS2 uses explicit enclosure.type when provided", () => {
const feed = new Feed({
title: "t",
id: "https://example.com",
link: "https://example.com",
copyright: "c",
});
// Proxy URL with no file extension -> auto-detection would fail
const proxied = "https://wsrv.nl/?url=https%3A%2F%2Fexample.com%2Fimg.jpg&w=1000";
feed.addItem({
title: "post",
id: "https://example.com/p",
link: "https://example.com/p",
date: new Date("2025-01-01"),
image: { url: proxied, type: "image/jpeg" }, // <— explicit type
});
const xml = feed.rss2();
expect(xml).toContain(`<enclosure`);
expect(xml).toContain(`url="${proxied}"`);
expect(xml).toContain(`type="image/jpeg"`);
});
test("RSS2 falls back to auto-detection when no type provided", () => {
const feed = new Feed({
title: "t",
id: "https://example.com",
link: "https://example.com",
copyright: "c",
});
feed.addItem({
title: "post",
id: "https://example.com/p",
link: "https://example.com/p",
date: new Date("2025-01-01"),
image: { url: "https://example.com/image.png", length: 12345 }, // no explicit type
});
const xml = feed.rss2();
expect(xml).toContain(`<enclosure`);
expect(xml).toContain(`url="https://example.com/image.png"`);
expect(xml).toContain(`type="image/png"`); // auto-detected from URL
});
test("RSS2 handles empty string type by falling back to auto-detection", () => {
const feed = new Feed({
title: "t",
id: "https://example.com",
link: "https://example.com",
copyright: "c",
});
feed.addItem({
title: "post",
id: "https://example.com/p",
link: "https://example.com/p",
date: new Date("2025-01-01"),
image: { url: "https://example.com/image.webp", type: "" }, // empty type
});
const xml = feed.rss2();
expect(xml).toContain(`<enclosure`);
expect(xml).toContain(`url="https://example.com/image.webp"`);
expect(xml).toContain(`type="image/webp"`); // auto-detected from URL
});
test("RSS2 handles video enclosures with explicit type", () => {
const feed = new Feed({
title: "t",
id: "https://example.com",
link: "https://example.com",
copyright: "c",
});
feed.addItem({
title: "post",
id: "https://example.com/p",
link: "https://example.com/p",
date: new Date("2025-01-01"),
video: { url: "https://example.com/video.mov", type: "video/quicktime" },
});
const xml = feed.rss2();
expect(xml).toContain(`<enclosure`);
expect(xml).toContain(`url="https://example.com/video.mov"`);
expect(xml).toContain(`type="video/quicktime"`);
});
test("RSS2 handles audio enclosures with explicit type", () => {
const feed = new Feed({
title: "t",
id: "https://example.com",
link: "https://example.com",
copyright: "c",
});
feed.addItem({
title: "post",
id: "https://example.com/p",
link: "https://example.com/p",
date: new Date("2025-01-01"),
audio: { url: "https://example.com/audio.ogg", type: "audio/ogg" },
});
const xml = feed.rss2();
expect(xml).toContain(`<enclosure`);
expect(xml).toContain(`url="https://example.com/audio.ogg"`);
expect(xml).toContain(`type="audio/ogg"`);
});