Files
workavia-calendar-front/__test__/features/websocket/websocketAPI/unregisterToCalendars.test.tsx
T
Camille Moussu d6e464afad [#421] added eslint check to CI (#534)
Co-authored-by: Camille Moussu <cmoussu@linagora.com>
2026-02-10 10:41:37 +01:00

59 lines
1.5 KiB
TypeScript

import { unregisterToCalendars } from "@/websocket/operations/unregisterToCalendars";
describe("unregisterToCalendars", () => {
let mockSocket: any;
beforeEach(() => {
mockSocket = {
readyState: WebSocket.OPEN,
send: jest.fn(),
};
jest.clearAllMocks();
});
it("should send unregistration message with calendar URIs", () => {
const calendarURIs = ["/calendars/cal1", "/calendars/cal2"];
unregisterToCalendars(mockSocket, calendarURIs);
expect(mockSocket.send).toHaveBeenCalledWith(
JSON.stringify({
unregister: calendarURIs,
})
);
});
it("should throw error if socket is not open", () => {
mockSocket.readyState = WebSocket.CONNECTING;
const calendarURIs = ["/calendars/cal1"];
expect(() => unregisterToCalendars(mockSocket, calendarURIs)).toThrow(
"Cannot unregister: WebSocket is not open"
);
});
it("should handle empty calendar list", () => {
unregisterToCalendars(mockSocket, []);
expect(mockSocket.send).toHaveBeenCalledWith(
JSON.stringify({
unregister: [],
})
);
});
it("should log unregistration", () => {
const consoleInfoSpy = jest.spyOn(console, "info").mockImplementation();
const calendarURIs = ["/calendars/cal1", "/calendars/cal2"];
unregisterToCalendars(mockSocket, calendarURIs);
expect(consoleInfoSpy).toHaveBeenCalledWith(
"Unregistered to calendars",
calendarURIs
);
consoleInfoSpy.mockRestore();
});
});