Skip to content

Commit

Permalink
Fix feeds template / notify state not reflecting in the UI (#866)
Browse files Browse the repository at this point in the history
* Ensure connection state always explicitly states all keys, even if some are undefined.

* changelog

* Fix type

* fix test types
  • Loading branch information
Half-Shot authored Dec 28, 2023
1 parent 76a4209 commit 46d198c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
1 change: 1 addition & 0 deletions changelog.d/866.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix feed widget not showing the true values for template / notify on failure.
10 changes: 6 additions & 4 deletions src/Connections/FeedConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/Connections/GenericHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -145,7 +145,7 @@ export class GenericHookConnection extends BaseConnection implements IConnection
}
return {
name,
...(transformationFunction && {transformationFunction}),
transformationFunction: transformationFunction || undefined,
waitForComplete,
};
}
Expand Down
21 changes: 10 additions & 11 deletions tests/connections/FeedTest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ const FEED_ENTRY_DEFAULTS: FeedEntry = {
}

function createFeed(
state: FeedConnectionState = { url: FEED_URL }
state: Partial<FeedConnectionState> = { }
): [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", () => {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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({
Expand All @@ -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({
Expand All @@ -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({
Expand Down
9 changes: 7 additions & 2 deletions tests/connections/GenericHookTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,20 @@ async function testSimpleWebhook(connection: GenericHookConnection, mq: LocalMQ,
}

function createGenericHook(
state: GenericHookConnectionState = { name: "some-name" },
state: Partial<GenericHookConnectionState> = { },
config: BridgeGenericWebhooksConfigYAML = { enabled: true, urlPrefix: "https://example.com/webhookurl"}
) {
const mq = new LocalMQ();
mq.subscribe('*');
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];
}

Expand Down

0 comments on commit 46d198c

Please sign in to comment.