Skip to content

Commit

Permalink
fix(api): unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yassinedorbozgithub committed Oct 11, 2024
1 parent 476ffb6 commit ff17a9d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"test:cov": "jest --coverage --runInBand --detectOpenHandles --forceExit",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"test:clear": "jest --clearCache",
"typecheck": "tsc --noEmit",
"reset": "npm install && npm run containers:restart",
"reset:hard": "npm clean-install && npm run containers:rebuild",
Expand Down
2 changes: 2 additions & 0 deletions api/src/websocket/websocket.gateway.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ describe('WebsocketGateway', () => {
ioClient = io('http://localhost:3000', {
autoConnect: false,
transports: ['websocket', 'polling'],
// path: '/socket.io/?EIO=4&transport=websocket&channel=offline',
query: { EIO: '4', transport: 'websocket', channel: 'offline' },
});

app.listen(3000);
Expand Down
34 changes: 15 additions & 19 deletions api/src/websocket/websocket.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,30 +251,26 @@ export class WebsocketGateway

handleConnection(client: Socket, ..._args: any[]): void {
const { sockets } = this.io.sockets;
const handshake = client.handshake;
const { channel } = handshake.query;
this.logger.log(`Client id: ${client.id} connected`);
this.logger.debug(`Number of connected clients: ${sockets?.size}`);

this.eventEmitter.emit(`hook:websocket:connection`, client);
// @TODO : Revisit once we don't use anymore in frontend
if (!channel) {
const response = new SocketResponse();
client.send(
response
.setHeaders({
'access-control-allow-origin':
config.security.cors.allowOrigins.join(','),
vary: 'Origin',
'access-control-allow-credentials':
config.security.cors.allowCredentials.toString(),
})
.status(200)
.json({
success: true,
}),
);
}
const response = new SocketResponse();
client.send(
response
.setHeaders({
'access-control-allow-origin':
config.security.cors.allowOrigins.join(','),
vary: 'Origin',
'access-control-allow-credentials':
config.security.cors.allowCredentials.toString(),
})
.status(200)
.json({
success: true,
}),
);
}

async handleDisconnect(client: Socket): Promise<void> {
Expand Down

0 comments on commit ff17a9d

Please sign in to comment.