From 46d198c2c0e9db167cf5bffc5678e20efb801867 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Thu, 28 Dec 2023 14:27:47 +0000 Subject: [PATCH] Fix feeds template / notify state not reflecting in the UI (#866) * Ensure connection state always explicitly states all keys, even if some are undefined. * changelog * Fix type * fix test types --- changelog.d/866.bugfix | 1 + src/Connections/FeedConnection.ts | 10 ++++++---- src/Connections/GenericHook.ts | 6 +++--- tests/connections/FeedTest.spec.ts | 21 ++++++++++----------- tests/connections/GenericHookTest.ts | 9 +++++++-- 5 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 changelog.d/866.bugfix diff --git a/changelog.d/866.bugfix b/changelog.d/866.bugfix new file mode 100644 index 000000000..e56c22023 --- /dev/null +++ b/changelog.d/866.bugfix @@ -0,0 +1 @@ +Fix feed widget not showing the true values for template / notify on failure. \ No newline at end of file diff --git a/src/Connections/FeedConnection.ts b/src/Connections/FeedConnection.ts index fe2d520c5..19fb12edc 100644 --- a/src/Connections/FeedConnection.ts +++ b/src/Connections/FeedConnection.ts @@ -26,10 +26,10 @@ export interface LastResultFail { export interface FeedConnectionState extends IConnectionState { - url: string; - label?: string; - template?: string; - notifyOnFailure?: boolean; + url: string; + label: string|undefined; + template: string|undefined; + notifyOnFailure: boolean|undefined; } export interface FeedConnectionSecrets { @@ -136,6 +136,8 @@ export class FeedConnection extends BaseConnection implements IConnection { config: { url: this.feedUrl, label: this.state.label, + template: this.state.template, + notifyOnFailure: this.state.notifyOnFailure, }, secrets: { lastResults: this.lastResults, diff --git a/src/Connections/GenericHook.ts b/src/Connections/GenericHook.ts index eb8ca6c63..5aa87de04 100644 --- a/src/Connections/GenericHook.ts +++ b/src/Connections/GenericHook.ts @@ -21,11 +21,11 @@ export interface GenericHookConnectionState extends IConnectionState { * The name given in the provisioning UI and displaynames. */ name: string; - transformationFunction?: string; + transformationFunction: string|undefined; /** * Should the webhook only respond on completion. */ - waitForComplete?: boolean; + waitForComplete: boolean|undefined; } export interface GenericHookSecrets { @@ -145,7 +145,7 @@ export class GenericHookConnection extends BaseConnection implements IConnection } return { name, - ...(transformationFunction && {transformationFunction}), + transformationFunction: transformationFunction || undefined, waitForComplete, }; } diff --git a/tests/connections/FeedTest.spec.ts b/tests/connections/FeedTest.spec.ts index 6db0a1cd1..6bb268411 100644 --- a/tests/connections/FeedTest.spec.ts +++ b/tests/connections/FeedTest.spec.ts @@ -22,11 +22,17 @@ const FEED_ENTRY_DEFAULTS: FeedEntry = { } function createFeed( - state: FeedConnectionState = { url: FEED_URL } + state: Partial = { } ): [FeedConnection, IntentMock] { const as = AppserviceMock.create(); const intent = as.getIntentForUserId('@webhooks:example.test'); - const connection = new FeedConnection(ROOM_ID, "foobar", state, intent); + const connection = new FeedConnection(ROOM_ID, "foobar", { + label: undefined, + template: undefined, + notifyOnFailure: undefined, + url: FEED_URL, + ...state + }, intent); return [connection, intent]; } describe("FeedConnection", () => { @@ -55,9 +61,7 @@ describe("FeedConnection", () => { 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({ - url: FEED_URL, - }); + const [connection, intent] = createFeed(); await connection.handleFeedEntry({ ...FEED_ENTRY_DEFAULTS, title: null, @@ -68,9 +72,7 @@ describe("FeedConnection", () => { 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({ - url: FEED_URL, - }); + const [connection, intent] = createFeed(); await connection.handleFeedEntry({ ...FEED_ENTRY_DEFAULTS, link: null, @@ -82,7 +84,6 @@ describe("FeedConnection", () => { }); it("will handle simple feed message with all the template options possible ", async () => { const [connection, intent] = createFeed({ - url: FEED_URL, template: `$FEEDNAME $FEEDURL $FEEDTITLE $TITLE $LINK $AUTHOR $DATE $SUMMARY` }); await connection.handleFeedEntry({ @@ -95,7 +96,6 @@ describe("FeedConnection", () => { }); it("will handle html in the feed summary ", async () => { const [connection, intent] = createFeed({ - url: FEED_URL, template: `$FEEDNAME $SUMMARY` }); await connection.handleFeedEntry({ @@ -109,7 +109,6 @@ describe("FeedConnection", () => { }); it("will handle partial html in the feed summary ", async () => { const [connection, intent] = createFeed({ - url: FEED_URL, template: `$FEEDNAME $SUMMARY` }); await connection.handleFeedEntry({ diff --git a/tests/connections/GenericHookTest.ts b/tests/connections/GenericHookTest.ts index 3832c7f0d..007c880d6 100644 --- a/tests/connections/GenericHookTest.ts +++ b/tests/connections/GenericHookTest.ts @@ -32,7 +32,7 @@ async function testSimpleWebhook(connection: GenericHookConnection, mq: LocalMQ, } function createGenericHook( - state: GenericHookConnectionState = { name: "some-name" }, + state: Partial = { }, config: BridgeGenericWebhooksConfigYAML = { enabled: true, urlPrefix: "https://example.com/webhookurl"} ) { const mq = new LocalMQ(); @@ -40,7 +40,12 @@ function createGenericHook( const messageClient = new MessageSenderClient(mq); const as = AppserviceMock.create(); const intent = as.getIntentForUserId('@webhooks:example.test'); - const connection = new GenericHookConnection(ROOM_ID, state, "foobar", "foobar", messageClient, new BridgeConfigGenericWebhooks(config), as, intent); + const connection = new GenericHookConnection(ROOM_ID, { + name: "some-name", + transformationFunction: undefined, + waitForComplete: undefined, + ...state, + }, "foobar", "foobar", messageClient, new BridgeConfigGenericWebhooks(config), as, intent); return [connection, mq, as, intent]; }