-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathrss-activity.js
58 lines (48 loc) · 1.59 KB
/
rss-activity.js
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
/**
* Tests the RSS Activity monitor
*/
/* global describe, it */
const {fetchRSS} = require("../lib/rss-activity");
const { MockAgent, setGlobalDispatcher, getGlobalDispatcher } = require('undici');
const fs = require("fs").promises;
const assert = require("assert");
const origDispatcher = getGlobalDispatcher();
const agent = new MockAgent();
let counter = 0;
const testUrl = () => {
counter++;
return new URL(`https://example.test/feed${counter}.rss`);
}
describe('The RSS Activity monitor', function () {
before(() => {
setGlobalDispatcher(agent);
agent.disableNetConnect();
});
it('detects activity in an RSS feed', async function() {
const feed = await fs.readFile('test/mock-content/feed.rss', 'utf-8');
const u = testUrl();
agent
.get(u.origin)
.intercept({path: u.pathname, method: "GET"})
.reply(200, feed);
const { items: data} = await fetchRSS(u.href);
assert.equal(data.length, 1, 'RSS Feed has one item');
assert.equal(data[0].isoDate, '2023-11-10T13:24:37.000Z', 'RSS feed item date correctly identified');
});
it("returns an error when the feed doesn't exist", async function() {
const u = testUrl();
agent
.get(u.origin)
.intercept({path: u.pathname, method: "GET"})
.reply(404);
const err = await fetchRSS(u.href);
assert.equal(err, `Error fetching ${u}: Error: HTTP error 404 while fetching ${u}`, 'Error when hitting 404');
});
afterEach(() => {
agent.assertNoPendingInterceptors();
});
after(async () => {
await agent.close();
setGlobalDispatcher(origDispatcher);
});
});