Skip to content

Commit

Permalink
Merge pull request #417 from ably/temp-ably-js-branch
Browse files Browse the repository at this point in the history
build: temporarily point to ably-js branch
  • Loading branch information
AndyTWF authored Nov 27, 2024
2 parents 4f8a53c + 248d2be commit c85fe27
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 94 deletions.
2 changes: 1 addition & 1 deletion demo/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
},
"homepage": "https://github.com/ably/ably-chat-js#readme",
"peerDependencies": {
"ably": "^2.5.0"
"ably": "ably/ably-js#mutable-messages-with-submodule-test"
},
"devDependencies": {
"@eslint/compat": "^1.2.0",
Expand Down
19 changes: 8 additions & 11 deletions src/core/message-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ interface MessagePayload {
};

serial: string;
updatedAt?: number;
updateSerial?: string;
createdAt: number;
version?: string;
action: Ably.MessageAction;
operation?: Ably.Operation;
}
Expand Down Expand Up @@ -69,11 +69,11 @@ export function parseMessage(roomId: string | undefined, inboundMessage: Ably.In
text: message.data.text,
metadata: message.data.metadata ?? {},
headers: message.extras.headers ?? {},
createdAt: new Date(message.timestamp),
createdAt: new Date(message.createdAt),
latestAction: message.action as ChatMessageActions,
latestActionSerial: message.updateSerial ?? message.serial,
updatedAt: message.updatedAt ? new Date(message.updatedAt) : undefined,
deletedAt: message.updatedAt ? new Date(message.updatedAt) : undefined,
latestActionSerial: message.version ?? message.serial,
updatedAt: message.timestamp ? new Date(message.timestamp) : undefined,
deletedAt: message.timestamp ? new Date(message.timestamp) : undefined,
operation: message.operation as MessageActionDetails,
};

Expand All @@ -83,11 +83,8 @@ export function parseMessage(roomId: string | undefined, inboundMessage: Ably.In
}
case ChatMessageActions.MessageUpdate:
case ChatMessageActions.MessageDelete: {
if (!message.updatedAt) {
throw new Ably.ErrorInfo(`received incoming ${message.action} without updatedAt`, 50000, 500);
}
if (!message.updateSerial) {
throw new Ably.ErrorInfo(`received incoming ${message.action} without updateSerial`, 50000, 500);
if (!message.version) {
throw new Ably.ErrorInfo(`received incoming ${message.action} without version`, 50000, 500);
}
break;
}
Expand Down
74 changes: 25 additions & 49 deletions test/core/message-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('parseMessage', () => {
message: {
clientId: 'client1',
timestamp: 1728402074206,
createdAt: 1728402074206,
extras: {},
serial: '01728402074206-000@cbfkKvEYgBhDaZ38195418:0',
action: ChatMessageActions.MessageCreate,
Expand All @@ -31,6 +32,7 @@ describe('parseMessage', () => {
message: {
data: { text: 'hello' },
timestamp: 1728402074206,
createdAt: 1728402074206,
extras: {},
serial: '01728402074206-000@cbfkKvEYgBhDaZ38195418:0',
action: ChatMessageActions.MessageCreate,
Expand All @@ -44,6 +46,7 @@ describe('parseMessage', () => {
data: {},
clientId: 'client1',
timestamp: 1728402074206,
createdAt: 1728402074206,
extras: {},
serial: '01728402074206-000@cbfkKvEYgBhDaZ38195418:0',
action: ChatMessageActions.MessageCreate,
Expand All @@ -57,6 +60,7 @@ describe('parseMessage', () => {
data: { text: 'hello' },
clientId: 'client1',
timestamp: 1728402074206,
createdAt: 1728402074206,
serial: '01728402074206-000@cbfkKvEYgBhDaZ38195418:0',
action: ChatMessageActions.MessageCreate,
},
Expand All @@ -69,6 +73,7 @@ describe('parseMessage', () => {
data: { text: 'hello' },
clientId: 'client1',
timestamp: 1728402074206,
createdAt: 1728402074206,
extras: {},
action: ChatMessageActions.MessageCreate,
},
Expand All @@ -81,71 +86,42 @@ describe('parseMessage', () => {
data: { text: 'hello' },
clientId: 'client1',
timestamp: 1728402074206,
createdAt: 1728402074206,
extras: {},
serial: '01728402074206-000@cbfkKvEYgBhDaZ38195418:0',
action: 'unhandled.action',
},
expectedError: 'received incoming message with unhandled action; unhandled.action',
},
{
description: 'message.updatedAt is undefined for update',
description: 'message.version is undefined for update',
roomId: 'room1',
message: {
data: { text: 'hello' },
clientId: 'client1',
timestamp: 1728402074206,
createdAt: 1728402074206,
extras: {},
serial: '01728402074206-000@cbfkKvEYgBhDaZ38195418:0',
action: ChatMessageActions.MessageUpdate,
updatedAt: undefined,
updateSerial: '01728402074206-000@cbfkKvEYgBhDaZ38195418:0',
},
expectedError: 'received incoming message.update without updatedAt',
},
{
description: 'message.updateSerial is undefined for update',
roomId: 'room1',
message: {
data: { text: 'hello' },
clientId: 'client1',
timestamp: 1728402074206,
extras: {},
serial: '01728402074206-000@cbfkKvEYgBhDaZ38195418:0',
action: ChatMessageActions.MessageUpdate,
updatedAt: 1234567890,
updateSerial: undefined,
},
expectedError: 'received incoming message.update without updateSerial',
},
{
description: 'message.updatedAt is undefined for deletion',
roomId: 'room1',
message: {
data: { text: 'hello' },
clientId: 'client1',
timestamp: 1728402074206,
extras: {},
serial: '01728402074206-000@cbfkKvEYgBhDaZ38195418:0',
updatedAt: undefined,
updateSerial: '01728402074206-000@cbfkKvEYgBhDaZ38195418:0',
action: ChatMessageActions.MessageDelete,
timestamp: 1234567890,
version: undefined,
},
expectedError: 'received incoming message.delete without updatedAt',
expectedError: 'received incoming message.update without version',
},
{
description: 'message.updateSerial is undefined for deletion',
description: 'message.version is undefined for deletion',
roomId: 'room1',
message: {
data: { text: 'hello' },
clientId: 'client1',
timestamp: 1728402074206,
createdAt: 1728402074206,
extras: {},
serial: '01728402074206-000@cbfkKvEYgBhDaZ38195418:0',
updatedAt: 1234567890,
updateSerial: undefined,
timestamp: 1234567890,
version: undefined,
action: ChatMessageActions.MessageDelete,
},
expectedError: 'received incoming message.delete without updateSerial',
expectedError: 'received incoming message.delete without version',
},
])('should throw an error ', ({ description, roomId, message, expectedError }) => {
it(`should throw an error if ${description}`, () => {
Expand All @@ -162,12 +138,12 @@ describe('parseMessage', () => {
const message = {
data: { text: 'hello', metadata: { key: 'value' } },
clientId: 'client1',
timestamp: 1728402074206,
createdAt: 1728402074206,
extras: {
headers: { headerKey: 'headerValue' },
},
updatedAt: 1728402074206,
updateSerial: '01728402074206-000@cbfkKvEYgBhDaZ38195418:0',
timestamp: 1728402074206,
version: '01728402074206-000@cbfkKvEYgBhDaZ38195418:0',
action: ChatMessageActions.MessageCreate,
serial: '01728402074206-000@cbfkKvEYgBhDaZ38195418:0',
} as Ably.InboundMessage;
Expand Down Expand Up @@ -200,14 +176,14 @@ describe('parseMessage', () => {
id: 'message-id',
data: { text: 'hello', metadata: { key: 'value' } },
clientId: 'client1',
timestamp: 1728402074206,
createdAt: 1728402074206,
extras: {
headers: { headerKey: 'headerValue' },
},
action: ChatMessageActions.MessageUpdate,
serial: '01728402074206-000@cbfkKvEYgBhDaZ38195418:0',
updatedAt: 1728402074206,
updateSerial: '01728402074206-000@cbfkKvEYgBhDaZ38195418:0',
timestamp: 1728402074206,
version: '01728402074206-000@cbfkKvEYgBhDaZ38195418:0',
operation: { clientId: 'client2', description: 'update message', metadata: { 'custom-update': 'some flag' } },
} as Ably.InboundMessage;

Expand Down Expand Up @@ -241,14 +217,14 @@ describe('parseMessage', () => {
id: 'message-id',
data: { text: 'hello', metadata: { key: 'value' } },
clientId: 'client1',
timestamp: 1728402074206,
createdAt: 1728402074206,
extras: {
headers: { headerKey: 'headerValue' },
},
action: ChatMessageActions.MessageDelete,
serial: '01728402074206-000@cbfkKvEYgBhDaZ38195418:0',
updatedAt: 1728402074206,
updateSerial: '01728402074206-000@cbfkKvEYgBhDaZ38195418:0',
timestamp: 1728402074206,
version: '01728402074206-000@cbfkKvEYgBhDaZ38195418:0',
operation: {
clientId: 'client2',
description: 'delete message',
Expand Down
10 changes: 9 additions & 1 deletion test/core/messages.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ const waitForMessages = (messages: Message[], expectedCount: number) => {

describe('messages integration', () => {
beforeEach<TestContext>((context) => {
context.chat = newChatClient();
context.chat = newChatClient(
undefined,
ablyRealtimeClient({
logLevel: 4,
logHandler: (message) => {
console.log(message);
},
}),
);
});

it<TestContext>('sets the agent version on the channel', async (context) => {
Expand Down
Loading

0 comments on commit c85fe27

Please sign in to comment.