Skip to content
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions apps/meteor/tests/end-to-end/api/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,135 @@ describe('[Chat]', () => {
});
});

describe('Threaded replies with tmid', () => {
it('should send a threaded reply to a message in a channel using tmid with roomId', async () => {
const channelName = `chat-api-tmid-channel-test-${Date.now()}`;
let testChannelResponse;
try {
testChannelResponse = await createRoom({ type: 'c', name: channelName });
Comment thread
ahmed-n-abdeltwab marked this conversation as resolved.
expect(testChannelResponse.body.success).to.be.true;
const testChannel = testChannelResponse.body.channel;

const initialMessagePayload = {
Comment thread
ahmed-n-abdeltwab marked this conversation as resolved.
channel: `#${channelName}`,
text: 'Initial message for tmid test',
};
const initialMessageResponse = await request.post(api('chat.postMessage')).set(credentials).send(initialMessagePayload);
expect(initialMessageResponse.status).to.equal(200);
expect(initialMessageResponse.body.success).to.be.true;
const initialMessageId = initialMessageResponse.body.message._id;

const replyMessagePayload = {
Comment thread
ahmed-n-abdeltwab marked this conversation as resolved.
roomId: testChannel._id,
text: 'This is a threaded reply',
tmid: initialMessageId,
};
const replyMessageResponse = await request.post(api('chat.postMessage')).set(credentials).send(replyMessagePayload);

expect(replyMessageResponse.status).to.equal(200);
expect(replyMessageResponse.body.success).to.be.true;

expect(replyMessageResponse.body.message.tmid).to.equal(initialMessageId);

const getReplyMessageResponse = await request
Comment thread
ahmed-n-abdeltwab marked this conversation as resolved.
.get(api('chat.getMessage'))
.set(credentials)
.query({ msgId: replyMessageResponse.body.message._id });
expect(getReplyMessageResponse.status).to.equal(200);
expect(getReplyMessageResponse.body.success).to.be.true;
expect(getReplyMessageResponse.body.message.tmid).to.equal(initialMessageId);
} finally {
if (testChannelResponse?.body.success) {
await deleteRoom({ type: 'c', roomId: testChannelResponse.body.channel._id });
Comment thread
ahmed-n-abdeltwab marked this conversation as resolved.
}
}
});

it('should send a threaded reply to a message in a channel using tmid with room ID', async () => {
const channelName = `chat-api-tmid-roomid-test-${Date.now()}`;
let testRoomResponse;
try {
testRoomResponse = await createRoom({ type: 'c', name: channelName });
Comment thread
ahmed-n-abdeltwab marked this conversation as resolved.
expect(testRoomResponse.body.success).to.be.true;
const testRoomId = testRoomResponse.body.channel._id;

const initialMessagePayload = {
Comment thread
ahmed-n-abdeltwab marked this conversation as resolved.
roomId: testRoomId,
text: 'Initial message for tmid with roomId test',
};
const initialMessageResponse = await request.post(api('chat.postMessage')).set(credentials).send(initialMessagePayload);
expect(initialMessageResponse.status).to.equal(200);
expect(initialMessageResponse.body.success).to.be.true;
const initialMessageId = initialMessageResponse.body.message._id;

const replyMessagePayload = {
Comment thread
ahmed-n-abdeltwab marked this conversation as resolved.
roomId: testRoomId,
text: 'This is a threaded reply using roomId',
tmid: initialMessageId,
};
const replyMessageResponse = await request.post(api('chat.postMessage')).set(credentials).send(replyMessagePayload);

expect(replyMessageResponse.status).to.equal(200);
expect(replyMessageResponse.body.success).to.be.true;

expect(replyMessageResponse.body.message.tmid).to.equal(initialMessageId);

const getReplyMessageResponse = await request
Comment thread
ahmed-n-abdeltwab marked this conversation as resolved.
.get(api('chat.getMessage'))
.set(credentials)
.query({ msgId: replyMessageResponse.body.message._id });
expect(getReplyMessageResponse.status).to.equal(200);
expect(getReplyMessageResponse.body.success).to.be.true;
expect(getReplyMessageResponse.body.message.tmid).to.equal(initialMessageId);
} finally {
if (testRoomResponse?.body?.success) {
await deleteRoom({ type: 'c', roomId: testRoomResponse.body.channel._id });
Comment thread
ahmed-n-abdeltwab marked this conversation as resolved.
}
}
});
it('should send a threaded reply to a message in a channel using tmid with channel name', async () => {
const channelName = `chat-api-tmid-channel-test-${Date.now()}`;
let testChannelResponse;
try {
testChannelResponse = await createRoom({ type: 'c', name: channelName });
expect(testChannelResponse.body.success).to.be.true;

const initialMessagePayload = {
channel: `#${channelName}`,
text: 'Initial message for tmid test',
};
const initialMessageResponse = await request.post(api('chat.postMessage')).set(credentials).send(initialMessagePayload);
expect(initialMessageResponse.status).to.equal(200);
expect(initialMessageResponse.body.success).to.be.true;
const initialMessageId = initialMessageResponse.body.message._id;

const replyMessagePayload = {
channel: `#${channelName}`,
text: 'This is a threaded reply',
tmid: initialMessageId,
};
const replyMessageResponse = await request.post(api('chat.postMessage')).set(credentials).send(replyMessagePayload);

expect(replyMessageResponse.status).to.equal(200);
expect(replyMessageResponse.body.success).to.be.true;

expect(replyMessageResponse.body.message.tmid).to.equal(initialMessageId);

const getReplyMessageResponse = await request
.get(api('chat.getMessage'))
.set(credentials)
.query({ msgId: replyMessageResponse.body.message._id });
expect(getReplyMessageResponse.status).to.equal(200);
expect(getReplyMessageResponse.body.success).to.be.true;
expect(getReplyMessageResponse.body.message.tmid).to.equal(initialMessageId);
} finally {
if (testChannelResponse?.body.success) {
await deleteRoom({ type: 'c', roomId: testChannelResponse.body.channel._id });
}
}
});
});

describe('/chat.getMessage', () => {
it('should retrieve the message successfully', (done) => {
void request
Expand Down
1 change: 1 addition & 0 deletions packages/rest-typings/src/v1/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ type ChatPostMessage =
emoji?: string;
avatar?: string;
attachments?: MessageAttachment[];
tmid?: string;
Comment thread
ahmed-n-abdeltwab marked this conversation as resolved.
customFields?: IMessage['customFields'];
}
| {
Expand Down