fix tests

This commit is contained in:
StarAppeal
2025-09-24 05:50:31 +02:00
parent cd38892d65
commit 5e9f3494e7
2 changed files with 2 additions and 7 deletions
@@ -28,7 +28,6 @@ describe("WebsocketEventHandler", () => {
emit: vi.fn(), emit: vi.fn(),
isAlive: false, isAlive: false,
payload: { username: "testuser", uuid: "test-uuid", id: "test-id" }, payload: { username: "testuser", uuid: "test-uuid", id: "test-id" },
asyncUpdates: new Map([["update1", 123], ["update2", 456]]),
} as unknown as Mocked<ExtendedWebSocket>; } as unknown as Mocked<ExtendedWebSocket>;
// not used in this test // not used in this test
@@ -60,9 +59,8 @@ describe("WebsocketEventHandler", () => {
}); });
describe("enableDisconnectEvent", () => { describe("enableDisconnectEvent", () => {
it("should set onclose handler, clear async updates, and call the callback", () => { it("should set onclose handler and call the callback", () => {
const mockCallback = vi.fn(); const mockCallback = vi.fn();
const clearIntervalSpy = vi.spyOn(global, "clearInterval");
websocketEventHandler.enableDisconnectEvent(mockCallback); websocketEventHandler.enableDisconnectEvent(mockCallback);
expect(mockWebSocket.onclose).toBeInstanceOf(Function); expect(mockWebSocket.onclose).toBeInstanceOf(Function);
@@ -70,12 +68,10 @@ describe("WebsocketEventHandler", () => {
mockWebSocket.onclose!({ code: 1000, reason: "Normal" } as any); mockWebSocket.onclose!({ code: 1000, reason: "Normal" } as any);
expect(console.log).toHaveBeenCalledWith("User: testuser disconnected"); expect(console.log).toHaveBeenCalledWith("User: testuser disconnected");
expect(clearIntervalSpy).toHaveBeenCalledWith(123);
expect(clearIntervalSpy).toHaveBeenCalledWith(456);
expect(mockCallback).toHaveBeenCalledOnce(); expect(mockCallback).toHaveBeenCalledOnce();
}); });
it("should handle disconnect with no async updates", () => { it("should handle disconnect with", () => {
const mockCallback = vi.fn(); const mockCallback = vi.fn();
const clearIntervalSpy = vi.spyOn(global, "clearInterval"); const clearIntervalSpy = vi.spyOn(global, "clearInterval");
@@ -61,7 +61,6 @@ describe("WebsocketServerEventHandler", () => {
expect(ws.user).toEqual(userObj); expect(ws.user).toEqual(userObj);
expect(ws.payload).toEqual(req.payload); expect(ws.payload).toEqual(req.payload);
expect(ws.isAlive).toBe(true); expect(ws.isAlive).toBe(true);
expect(ws.asyncUpdates).toBeInstanceOf(Map);
expect(cb).toHaveBeenCalledWith(ws, req); expect(cb).toHaveBeenCalledWith(ws, req);
}); });