Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/message: add test for history pagination with msgpack #401

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Changes from all 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
51 changes: 51 additions & 0 deletions test/core/messages.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { RoomStatus } from '../../src/core/room-status.ts';
import { CHANNEL_OPTIONS_AGENT_STRING } from '../../src/core/version.ts';
import { newChatClient } from '../helper/chat.ts';
import { randomRoomId } from '../helper/identifier.ts';
import { ablyRealtimeClient } from '../helper/realtime-client.ts';
import { getRandomRoom, waitForRoomStatus } from '../helper/room.ts';

interface TestContext {
Expand Down Expand Up @@ -355,6 +356,56 @@ describe('messages integration', () => {
expect(history2?.hasNext()).toBe(false);
});

it<TestContext>('should be able to paginate chat history (msgpack)', async () => {
const chat = newChatClient(undefined, ablyRealtimeClient({ useBinaryProtocol: true }));

const room = await getRandomRoom(chat);

// Publish 4 messages
const message1 = await room.messages.send({ text: 'Hello there!' });
const message2 = await room.messages.send({ text: 'I have the high ground!' });
const message3 = await room.messages.send({ text: 'You underestimate my power!' });
const message4 = await room.messages.send({ text: "Don't try it!" });

// Do a history request to get the first 3 messages
const history1 = await room.messages.get({ limit: 3, direction: 'forwards' });

expect(history1.items).toEqual([
expect.objectContaining({
text: 'Hello there!',
clientId: chat.clientId,
serial: message1.serial,
}),
expect.objectContaining({
text: 'I have the high ground!',
clientId: chat.clientId,
serial: message2.serial,
}),
expect.objectContaining({
text: 'You underestimate my power!',
clientId: chat.clientId,
serial: message3.serial,
}),
]);

// We should have a "next" link in the response
expect(history1.hasNext()).toBe(true);

// Do a history request to get the next 2 messages
const history2 = await history1.next();

expect(history2?.items).toEqual([
expect.objectContaining({
text: "Don't try it!",
clientId: chat.clientId,
serial: message4.serial,
}),
]);

// We shouldn't have a "next" link in the response
expect(history2?.hasNext()).toBe(false);
});

it<TestContext>('should be able to paginate chat history, but backwards', async (context) => {
const { chat } = context;

Expand Down
Loading