-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathfeed.test.js
More file actions
128 lines (118 loc) · 3.86 KB
/
Copy pathfeed.test.js
File metadata and controls
128 lines (118 loc) · 3.86 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const { Parser } = require('xml2js');
const test = require('node:test');
const assert = require('node:assert/strict');
const { renderCloudFeed } = require('./feed');
function reparse(xml) {
return new Parser({ explicitArray: false }).parseStringPromise(xml);
}
const CLOUD = {
domain: 'localhost',
port: 5337,
path: '/RPC2',
registerProcedure: 'rssCloud.pleaseNotify',
protocol: 'xml-rpc'
};
test('renders a channel with the cloud element and an item', async() => {
const xml = renderCloudFeed({
title: 'Test Feed',
link: 'http://sub.example:9000/rss-01.xml',
description: 'Test feed for rssCloud',
cloud: CLOUD,
items: [
{
title: 'Update one',
description: 'first',
pubDate: new Date('2026-01-02T03:04:05Z'),
guid: 'rss-01-0'
}
]
});
const { rss } = await reparse(xml);
assert.equal(rss.$.version, '2.0');
assert.equal(rss.channel.title, 'Test Feed');
assert.equal(rss.channel.link, 'http://sub.example:9000/rss-01.xml');
assert.deepEqual(rss.channel.cloud.$, {
domain: 'localhost',
port: '5337',
path: '/RPC2',
registerProcedure: 'rssCloud.pleaseNotify',
protocol: 'xml-rpc'
});
assert.equal(rss.channel.item.title, 'Update one');
assert.equal(rss.channel.item.guid, 'rss-01-0');
assert.equal(rss.channel.item.pubDate, 'Fri, 02 Jan 2026 03:04:05 GMT');
});
test('advertises a WebSub hub via atom:link rel=hub and rel=self', async() => {
const xml = renderCloudFeed({
title: 'Test Feed',
link: 'http://sub.example:9000/rss-01.xml',
description: 'Test feed for rssCloud',
cloud: CLOUD,
hub: 'http://localhost:5337/websub',
items: [
{
title: 'Update one',
description: 'first',
pubDate: new Date('2026-01-02T03:04:05Z'),
guid: 'rss-01-0'
}
]
});
const { rss } = await reparse(xml);
assert.equal(rss.$['xmlns:atom'], 'http://www.w3.org/2005/Atom');
assert.deepEqual(
rss.channel['atom:link'].map(link => link.$),
[
{ rel: 'hub', href: 'http://localhost:5337/websub' },
{ rel: 'self', href: 'http://sub.example:9000/rss-01.xml' }
]
);
// the rssCloud <cloud> element is still emitted alongside the hub links
assert.equal(rss.channel.cloud.$.protocol, 'xml-rpc');
});
test('omits the atom namespace and links when no hub is given', async() => {
const xml = renderCloudFeed({
title: 'Test Feed',
link: 'http://sub.example:9000/rss-01.xml',
description: 'Test feed for rssCloud',
cloud: CLOUD,
items: [
{
title: 'Update one',
description: 'first',
pubDate: new Date('2026-01-02T03:04:05Z'),
guid: 'rss-01-0'
}
]
});
const { rss } = await reparse(xml);
assert.equal(rss.$['xmlns:atom'], undefined);
assert.equal(rss.channel['atom:link'], undefined);
});
test('renders multiple items in order', async() => {
const xml = renderCloudFeed({
title: 'Test Feed',
link: 'http://sub.example:9000/rss-01.xml',
description: 'Test feed for rssCloud',
cloud: CLOUD,
items: [
{
title: 'one',
description: 'a',
pubDate: new Date('2026-01-02T00:00:00Z'),
guid: 'g0'
},
{
title: 'two',
description: 'b',
pubDate: new Date('2026-01-03T00:00:00Z'),
guid: 'g1'
}
]
});
const { rss } = await reparse(xml);
assert.deepEqual(
rss.channel.item.map(i => i.title),
['one', 'two']
);
});