diff --git a/src/lib/chat/matrix-client.test.ts b/src/lib/chat/matrix-client.test.ts index dbbf8b5e7..993dbdc00 100644 --- a/src/lib/chat/matrix-client.test.ts +++ b/src/lib/chat/matrix-client.test.ts @@ -59,6 +59,7 @@ const getSdkClient = (sdkClient = {}) => ({ getAccountData: jest.fn(), getUser: jest.fn(), setGlobalErrorOnUnknownDevices: () => undefined, + fetchRoomEvent: jest.fn(), ...sdkClient, }); @@ -748,4 +749,52 @@ describe('matrix client', () => { expect(fetchedMessages).toHaveLength(0); }); }); + + describe('editMessage', () => { + it('edits a message successfully', async () => { + const originalMessageId = 'orig-message-id'; + const roomId = '!testRoomId'; + const editedMessage = 'edited message content'; + + const sendMessage = jest.fn(() => + Promise.resolve({ + event_id: 'edited-message-id', + }) + ); + + const fetchRoomEvent = jest.fn(() => + Promise.resolve({ + type: 'm.room.message', + content: { + body: editedMessage, + msgtype: 'm.text', + 'm.relates_to': { + rel_type: 'm.replace', + event_id: originalMessageId, + }, + }, + event_id: 'edited-message-id', + user_id: '@testUser:zero-synapse-development.zer0.io', + }) + ); + + const getSenderData = jest.fn(() => + Promise.resolve({ + displayName: 'Test User', + }) + ); + + const client = subject({ + createClient: jest.fn(() => getSdkClient({ sendMessage, fetchRoomEvent, getUser: getSenderData })), + }); + + await client.connect(null, 'token'); + const result = await client.editMessage(roomId, originalMessageId, editedMessage, []); + + expect(result).toMatchObject({ + id: 'edited-message-id', + message: editedMessage, + }); + }); + }); });