Skip to content

Commit

Permalink
add removeMember to api.chatRoom (#2595)
Browse files Browse the repository at this point in the history
* add removeMember to api.chatRoom

* add unit test for api.chatRoom.removeMember
  • Loading branch information
rogorman9 committed Sep 15, 2023
1 parent e7d58ec commit 41a4122
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions __tests__/core/cluster.ts
Expand Up @@ -101,6 +101,20 @@ describe("Core: Action Cluster", () => {
expect(message.message).toEqual("hi");
});

test("can call api.chatRoom.removeMember on other servers", async () => {
const client = await specHelper.buildConnection();
const spy = jest
.spyOn(api.chatRoom, "removeMember")
.mockImplementationOnce(jest.fn());
await redis.doCluster("api.chatRoom.removeMember", [
client.id,
"defaultRoom",
]);
await utils.sleep(100);

expect(spy).toHaveBeenCalledWith(client.id, "defaultRoom");
});

test("failing RPC calls with a callback will have a failure callback", async () => {
try {
await redis.doCluster(
Expand Down
8 changes: 8 additions & 0 deletions src/initializers/chatRoom.ts
Expand Up @@ -14,6 +14,7 @@ export interface ChatRoomApi {
incomingMessage: ChatRoomInitializer["incomingMessage"];
incomingMessagePerConnection?: ChatRoomInitializer["incomingMessagePerConnection"];
runMiddleware: ChatRoomInitializer["runMiddleware"];
removeMember: ChatRoomInitializer["removeMember"];
}

export type ChatMiddlewareDirections =
Expand Down Expand Up @@ -160,6 +161,12 @@ export class ChatRoomInitializer extends Initializer {
return newMessagePayload;
};

removeMember = (
connectionId: string,
room: string,
toWaitRemote: boolean = true,
) => chatRoom.removeMember(connectionId, room, toWaitRemote);

async initialize() {
api.chatRoom = {
middleware: {},
Expand All @@ -174,6 +181,7 @@ export class ChatRoomInitializer extends Initializer {
incomingMessage: this.incomingMessage,
incomingMessagePerConnection: this.incomingMessagePerConnection,
runMiddleware: this.runMiddleware,
removeMember: this.removeMember,
};
}

Expand Down

0 comments on commit 41a4122

Please sign in to comment.