Add tests for reader and connection to check mastodon feeds.

This commit is contained in:
Half-Shot 2024-02-06 09:51:07 +00:00
parent 3bb6724fe9
commit 08f022aa6a
2 changed files with 47 additions and 0 deletions

View File

@ -250,4 +250,34 @@ describe("FeedReader", () => {
feedReader.stop();
expect(events).to.have.lengthOf(1);
});
it("should handle feed entries without a title", async () => {
const { mq, feedReader, httpServer } = await constructFeedReader(() => ({
headers: {}, data: `<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:webfeeds="http://webfeeds.org/rss/1.0" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<title>Example Feed</title>
<item>
<guid isPermaLink="true">http://example.org/123456</guid>
<link>http://example.org/123456</link>
<pubDate>Sun, 04 Feb 2024 20:10:08 +0000</pubDate>
<description>Some text.</description>
</item>
</channel>
</rss>
`
}));
after(() => httpServer.close());
const event: MessageQueueMessage<FeedEntry> = await new Promise((resolve) => {
mq.on('pushed', (data) => { resolve(data); feedReader.stop() });
});
expect(event.eventName).to.equal('feed.entry');
expect(event.data.feed.title).to.equal('Example Feed');
expect(event.data.title).to.be.null;
expect(event.data.author).to.be.null;
expect(event.data.summary).to.equal('Some text.');
expect(event.data.link).to.equal('http://example.org/123456');
expect(event.data.pubdate).to.equal('Sun, 04 Feb 2024 20:10:08 +0000');
console.log(event.data);
});
});

View File

@ -82,6 +82,23 @@ describe("FeedConnection", () => {
expect(matrixEvt.roomId).to.equal(ROOM_ID);
expect(matrixEvt.content.body).to.equal("New post in Test feed: Foo");
});
// https://github.com/matrix-org/matrix-hookshot/issues/888
it("will handle a mastodon-style rss feed ", async () => {
const [connection, intent] = createFeed();
await connection.handleFeedEntry({
feed: { title: 'Example Feed', url: 'http://127.0.0.1:35339/' },
title: null,
pubdate: 'Sun, 04 Feb 2024 20:10:08 +0000',
summary: 'Some text.',
author: null,
link: 'http://example.org/123456',
fetchKey: randomUUID(),
});
const matrixEvt =intent.sentEvents[0];
expect(matrixEvt).to.not.be.undefined;
expect(matrixEvt.roomId).to.equal(ROOM_ID);
expect(matrixEvt.content.body).to.equal("New post in Example Feed: [http://example.org/123456](http://example.org/123456)");
});
it("will handle simple feed message with all the template options possible ", async () => {
const [connection, intent] = createFeed({
template: `$FEEDNAME $FEEDURL $FEEDTITLE $TITLE $LINK $AUTHOR $DATE $SUMMARY`