mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 13:17:08 +00:00

* Update dependencies * Node 22 is now the new minimum version. * changelog. * Begin porting eslint to new config format. * Make linter happy. * Update reqwest to fix SSL issue? * Fix test types * quick check on ubuntu LTS 24.04 * Change cache key * update rust action * revert mocha due to esminess * Remove the only usage of pqueue * Use babel for TS transformations to get around ESM import bug. * Dependency bundle upgrade * Drop babel, not actually used. * lint * lint * update default config (mostly sections moving around)
129 lines
5.1 KiB
TypeScript
129 lines
5.1 KiB
TypeScript
import { AppserviceMock } from "../utils/AppserviceMock";
|
|
import { FeedConnection, FeedConnectionState } from "../../src/Connections";
|
|
import { FeedEntry } from "../../src/feeds/FeedReader";
|
|
import { IntentMock } from "../utils/IntentMock";
|
|
import { randomUUID } from "crypto";
|
|
import { expect } from "chai";
|
|
|
|
const ROOM_ID = "!foo:bar";
|
|
const FEED_URL = "https://example.com/feed.xml";
|
|
const FEED_ENTRY_DEFAULTS: FeedEntry = {
|
|
feed: {
|
|
title: "Test feed",
|
|
url: FEED_URL,
|
|
},
|
|
title: "Foo",
|
|
link: "foo/bar",
|
|
pubdate: "today!",
|
|
summary: "fibble fobble",
|
|
author: "Me!",
|
|
fetchKey: randomUUID(),
|
|
}
|
|
|
|
function createFeed(
|
|
state: Partial<FeedConnectionState> = { }
|
|
): [FeedConnection, IntentMock] {
|
|
const as = AppserviceMock.create();
|
|
const intent = as.getIntentForUserId('@webhooks:example.test');
|
|
const connection = new FeedConnection(ROOM_ID, "foobar", {
|
|
label: undefined,
|
|
template: undefined,
|
|
notifyOnFailure: undefined,
|
|
url: FEED_URL,
|
|
...state
|
|
}, intent);
|
|
return [connection, intent];
|
|
}
|
|
describe("FeedConnection", () => {
|
|
it("will handle simple feed message", async () => {
|
|
const [connection, intent] = createFeed();
|
|
await connection.handleFeedEntry({
|
|
...FEED_ENTRY_DEFAULTS,
|
|
});
|
|
const matrixEvt = intent.sentEvents[0];
|
|
expect(matrixEvt).to.not.be.undefined;
|
|
expect(matrixEvt.roomId).to.equal(ROOM_ID);
|
|
expect(matrixEvt.content.external_url).to.equal(FEED_ENTRY_DEFAULTS.link);
|
|
expect(matrixEvt.content.body).to.equal("New post in Test feed: [Foo](foo/bar)");
|
|
});
|
|
|
|
it("will handle simple feed message without a title and link ", async () => {
|
|
const [connection, intent] = createFeed();
|
|
await connection.handleFeedEntry({
|
|
...FEED_ENTRY_DEFAULTS,
|
|
title: null,
|
|
link: null,
|
|
});
|
|
const matrixEvt =intent.sentEvents[0];
|
|
expect(matrixEvt).to.not.be.undefined;
|
|
expect(matrixEvt.roomId).to.equal(ROOM_ID);
|
|
expect(matrixEvt.content.external_url).to.be.undefined;
|
|
expect(matrixEvt.content.body).to.equal("New post in Test feed");
|
|
});
|
|
|
|
it("will handle simple feed message with a missing title ", async () => {
|
|
const [connection, intent] = createFeed();
|
|
await connection.handleFeedEntry({
|
|
...FEED_ENTRY_DEFAULTS,
|
|
title: null,
|
|
});
|
|
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 Test feed: [foo/bar](foo/bar)");
|
|
});
|
|
|
|
it("will handle simple feed message with a missing link ", async () => {
|
|
const [connection, intent] = createFeed();
|
|
await connection.handleFeedEntry({
|
|
...FEED_ENTRY_DEFAULTS,
|
|
link: null,
|
|
});
|
|
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 Test feed: Foo");
|
|
});
|
|
|
|
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`
|
|
});
|
|
await connection.handleFeedEntry({
|
|
...FEED_ENTRY_DEFAULTS,
|
|
});
|
|
const matrixEvt =intent.sentEvents[0];
|
|
expect(matrixEvt).to.not.be.undefined;
|
|
expect(matrixEvt.roomId).to.equal(ROOM_ID);
|
|
expect(matrixEvt.content.body).to.equal("Test feed https://example.com/feed.xml Test feed Foo [Foo](foo/bar) Me! today! fibble fobble");
|
|
});
|
|
|
|
it("will handle html in the feed summary ", async () => {
|
|
const [connection, intent] = createFeed({
|
|
template: `$FEEDNAME $SUMMARY`
|
|
});
|
|
await connection.handleFeedEntry({
|
|
...FEED_ENTRY_DEFAULTS,
|
|
summary: "<p> Some HTML with <disallowed-elements> which should be ignored </disallowed-elements> and an <img src='mxc://fibble/fobble'></img> </p>"
|
|
});
|
|
const matrixEvt =intent.sentEvents[0];
|
|
expect(matrixEvt).to.not.be.undefined;
|
|
expect(matrixEvt.roomId).to.equal(ROOM_ID);
|
|
expect(matrixEvt.content.body).to.equal('Test feed <p> Some HTML with which should be ignored and an <img src="mxc://fibble/fobble"> </p>');
|
|
});
|
|
|
|
it("will handle partial html in the feed summary ", async () => {
|
|
const [connection, intent] = createFeed({
|
|
template: `$FEEDNAME $SUMMARY`
|
|
});
|
|
await connection.handleFeedEntry({
|
|
...FEED_ENTRY_DEFAULTS,
|
|
summary: "<p> Some HTML with <disallowed-elements> which should be ignored and an <img src='mxc://fibble/fobble'></img> </p>"
|
|
});
|
|
const matrixEvt =intent.sentEvents[0];
|
|
expect(matrixEvt).to.not.be.undefined;
|
|
expect(matrixEvt.roomId).to.equal(ROOM_ID);
|
|
expect(matrixEvt.content.body).to.equal('Test feed <p> Some HTML with which should be ignored and an <img src="mxc://fibble/fobble"> </p>');
|
|
});
|
|
})
|