chore: upgrade Node.js runtime to v24 across codebase #419
@@ -124,6 +124,52 @@ describe("WebSocketGateway", () => {
|
||||
expect(mockClient.disconnect).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should clear timeout when workspace membership query throws error", async () => {
|
||||
const clearTimeoutSpy = vi.spyOn(global, "clearTimeout");
|
||||
|
||||
const mockSessionData = {
|
||||
user: { id: "user-123", email: "test@example.com" },
|
||||
session: { id: "session-123" },
|
||||
};
|
||||
|
||||
vi.spyOn(authService, "verifySession").mockResolvedValue(mockSessionData);
|
||||
vi.spyOn(prismaService.workspaceMember, "findFirst").mockRejectedValue(
|
||||
new Error("Database connection failed")
|
||||
);
|
||||
|
||||
await gateway.handleConnection(mockClient);
|
||||
|
||||
// Verify clearTimeout was called (timer cleanup on error)
|
||||
expect(clearTimeoutSpy).toHaveBeenCalled();
|
||||
expect(mockClient.disconnect).toHaveBeenCalled();
|
||||
|
||||
clearTimeoutSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("should clear timeout on successful connection", async () => {
|
||||
const clearTimeoutSpy = vi.spyOn(global, "clearTimeout");
|
||||
|
||||
const mockSessionData = {
|
||||
user: { id: "user-123", email: "test@example.com" },
|
||||
session: { id: "session-123" },
|
||||
};
|
||||
|
||||
vi.spyOn(authService, "verifySession").mockResolvedValue(mockSessionData);
|
||||
vi.spyOn(prismaService.workspaceMember, "findFirst").mockResolvedValue({
|
||||
userId: "user-123",
|
||||
workspaceId: "workspace-456",
|
||||
role: "MEMBER",
|
||||
} as never);
|
||||
|
||||
await gateway.handleConnection(mockClient);
|
||||
|
||||
// Verify clearTimeout was called (timer cleanup on success)
|
||||
expect(clearTimeoutSpy).toHaveBeenCalled();
|
||||
expect(mockClient.disconnect).not.toHaveBeenCalled();
|
||||
|
||||
clearTimeoutSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("should have connection timeout mechanism in place", () => {
|
||||
// This test verifies that the gateway has a CONNECTION_TIMEOUT_MS constant
|
||||
// The actual timeout is tested indirectly through authentication failure tests
|
||||
|
||||
Reference in New Issue
Block a user