Skip to content

Commit

Permalink
feat: add test coverage for editMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
domw30 committed Oct 16, 2023
1 parent 99aba81 commit d1e4f17
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/lib/chat/matrix-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const getSdkClient = (sdkClient = {}) => ({
getAccountData: jest.fn(),
getUser: jest.fn(),
setGlobalErrorOnUnknownDevices: () => undefined,
fetchRoomEvent: jest.fn(),
...sdkClient,
});

Expand Down Expand Up @@ -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,
});
});
});
});

0 comments on commit d1e4f17

Please sign in to comment.