From d7b9419b18c1677676c5d10c7c8867185acb7022 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Mon, 23 Dec 2024 17:13:32 +0000 Subject: [PATCH] add a test --- spec/generic-hooks.spec.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/spec/generic-hooks.spec.ts b/spec/generic-hooks.spec.ts index 8b1f266b4..bf9880e57 100644 --- a/spec/generic-hooks.spec.ts +++ b/spec/generic-hooks.spec.ts @@ -116,4 +116,32 @@ describe('Inbound (Generic) Webhooks', () => { error: "This hook has expired", }); }); + + it('should allow disabling hook data in matrix events.', async () => { + jest.useFakeTimers(); + const user = testEnv.getUser('user'); + const roomId = await user.createRoom({ name: 'My Test Webhooks room'}); + const okMsg = user.waitForRoomEvent({ eventType: "m.room.message", sender: testEnv.botMxid, roomId }); + const url = await createInboundConnection(user, testEnv.botMxid, roomId, '2h'); + expect((await okMsg).data.content.body).toEqual('Room configured to bridge webhooks. See admin room for secret url.'); + const stateEvent = (await user.getRoomState(roomId)).find(v => v.type === GenericHookConnection.CanonicalEventType) + await user.sendStateEvent(roomId, stateEvent.type, stateEvent.state_key, { + ...stateEvent.content, + includeHookBody: false, + }); + + const expectedMsg = user.waitForRoomEvent({ eventType: "m.room.message", sender: testEnv.botMxid, roomId }); + const req = await fetch(url, { + method: "PUT", + body: "Hello world" + }); + expect(req.status).toEqual(200); + expect(await req.json()).toEqual({ ok: true }); + expect((await expectedMsg).data.content).toEqual({ + msgtype: 'm.notice', + body: 'Received webhook data: Hello world', + formatted_body: '

Received webhook data: Hello world

', + format: 'org.matrix.custom.html', + }); + }); });