fix(api): update WebsocketGateway unit tests

This commit is contained in:
yassinedorbozgithub
2025-05-12 18:18:02 +01:00
parent e203485d75
commit 22ef79b05f
2 changed files with 111 additions and 15 deletions

View File

@@ -416,6 +416,10 @@ export class WebsocketGateway
async getNotificationSockets(
sessionId: string,
): Promise<RemoteSocket<DefaultEventsMap, any>[]> {
if (!sessionId) {
throw new Error('SessionId is required!');
}
return (await this.io.fetchSockets()).filter(
({ handshake, data }) =>
!handshake.query.channel && data.sessionID === sessionId,
@@ -429,8 +433,16 @@ export class WebsocketGateway
* @param room - the joined room name
*/
async joinNotificationSockets(sessionId: string, room: Room): Promise<void> {
if (!sessionId) {
throw new Error('SessionId is required!');
}
const notificationSockets = await this.getNotificationSockets(sessionId);
if (!notificationSockets.length) {
throw new Error('No notification sockets found!');
}
notificationSockets.forEach((notificationSocket) =>
notificationSocket.join(room),
);