* #708 apply strictier linting rules and fix simple eslint bugs * #708 fix eslint errors relate to promise * #708 fix eslint import/no-extraneous-dependencies * #708 fix eslint errors of react-hook * #708 enable eslint check for typescript --------- Co-authored-by: lethemanh <lethemanh@lethemanhs-MacBook-Pro.local>
This commit is contained in:
@@ -1,76 +1,76 @@
|
||||
import { parseMessage } from "@/websocket/messaging/parseMessage";
|
||||
import { WS_INBOUND_EVENTS } from "@/websocket/protocols";
|
||||
import { parseMessage } from '@/websocket/messaging/parseMessage'
|
||||
import { WS_INBOUND_EVENTS } from '@/websocket/protocols'
|
||||
|
||||
describe("parseMessage", () => {
|
||||
it("should return empty set for non-object messages", () => {
|
||||
const result1 = parseMessage(null);
|
||||
const result2 = parseMessage("string");
|
||||
const result3 = parseMessage(123);
|
||||
describe('parseMessage', () => {
|
||||
it('should return empty set for non-object messages', () => {
|
||||
const result1 = parseMessage(null)
|
||||
const result2 = parseMessage('string')
|
||||
const result3 = parseMessage(123)
|
||||
|
||||
expect(result1.calendarsToRefresh).toEqual(new Set<string>());
|
||||
expect(result2.calendarsToRefresh).toEqual(new Set<string>());
|
||||
expect(result3.calendarsToRefresh).toEqual(new Set<string>());
|
||||
});
|
||||
expect(result1.calendarsToRefresh).toEqual(new Set<string>())
|
||||
expect(result2.calendarsToRefresh).toEqual(new Set<string>())
|
||||
expect(result3.calendarsToRefresh).toEqual(new Set<string>())
|
||||
})
|
||||
|
||||
it("should handle registered event", () => {
|
||||
it('should handle registered event', () => {
|
||||
const message = {
|
||||
[WS_INBOUND_EVENTS.CLIENT_REGISTERED]: [
|
||||
"/calendars/cal1/entry1",
|
||||
"/calendars/cal2/entry2",
|
||||
],
|
||||
};
|
||||
'/calendars/cal1/entry1',
|
||||
'/calendars/cal2/entry2'
|
||||
]
|
||||
}
|
||||
|
||||
const result = parseMessage(message);
|
||||
const result = parseMessage(message)
|
||||
|
||||
expect(result.calendarsToRefresh).toContain("/calendars/cal1/entry1");
|
||||
expect(result.calendarsToRefresh).toContain("/calendars/cal2/entry2");
|
||||
expect(result.calendarsToRefresh.size).toBe(2);
|
||||
});
|
||||
expect(result.calendarsToRefresh).toContain('/calendars/cal1/entry1')
|
||||
expect(result.calendarsToRefresh).toContain('/calendars/cal2/entry2')
|
||||
expect(result.calendarsToRefresh.size).toBe(2)
|
||||
})
|
||||
|
||||
it("should handle unregistered event", () => {
|
||||
it('should handle unregistered event', () => {
|
||||
const message = {
|
||||
[WS_INBOUND_EVENTS.CLIENT_UNREGISTERED]: ["/calendars/cal1/entry1"],
|
||||
};
|
||||
[WS_INBOUND_EVENTS.CLIENT_UNREGISTERED]: ['/calendars/cal1/entry1']
|
||||
}
|
||||
|
||||
const result = parseMessage(message);
|
||||
const result = parseMessage(message)
|
||||
|
||||
expect(result.calendarsToHide).toContain("/calendars/cal1/entry1");
|
||||
});
|
||||
expect(result.calendarsToHide).toContain('/calendars/cal1/entry1')
|
||||
})
|
||||
|
||||
it("should handle calendar path updates", () => {
|
||||
it('should handle calendar path updates', () => {
|
||||
const message = {
|
||||
"/calendars/cal1/entry1": { updated: true },
|
||||
};
|
||||
'/calendars/cal1/entry1': { updated: true }
|
||||
}
|
||||
|
||||
const result = parseMessage(message);
|
||||
const result = parseMessage(message)
|
||||
|
||||
expect(result.calendarsToRefresh).toContain("/calendars/cal1/entry1");
|
||||
expect(result.calendarsToRefresh.size).toBe(1);
|
||||
});
|
||||
expect(result.calendarsToRefresh).toContain('/calendars/cal1/entry1')
|
||||
expect(result.calendarsToRefresh.size).toBe(1)
|
||||
})
|
||||
|
||||
it("should parse multiple calendar paths", () => {
|
||||
it('should parse multiple calendar paths', () => {
|
||||
const message = {
|
||||
"/calendars/cal1/entry1": {},
|
||||
"/calendars/cal2/entry2": {},
|
||||
};
|
||||
'/calendars/cal1/entry1': {},
|
||||
'/calendars/cal2/entry2': {}
|
||||
}
|
||||
|
||||
const result = parseMessage(message);
|
||||
const result = parseMessage(message)
|
||||
|
||||
expect(result.calendarsToRefresh.size).toBe(2);
|
||||
expect(result.calendarsToRefresh).toContain("/calendars/cal1/entry1");
|
||||
expect(result.calendarsToRefresh).toContain("/calendars/cal2/entry2");
|
||||
});
|
||||
expect(result.calendarsToRefresh.size).toBe(2)
|
||||
expect(result.calendarsToRefresh).toContain('/calendars/cal1/entry1')
|
||||
expect(result.calendarsToRefresh).toContain('/calendars/cal2/entry2')
|
||||
})
|
||||
|
||||
it("should handle multiple event types in single message", () => {
|
||||
it('should handle multiple event types in single message', () => {
|
||||
const message = {
|
||||
[WS_INBOUND_EVENTS.CLIENT_REGISTERED]: ["/calendars/cal1/entry1"],
|
||||
[WS_INBOUND_EVENTS.CLIENT_UNREGISTERED]: ["/calendars/cal2/entry2"],
|
||||
"/calendars/cal1/entry1": {},
|
||||
};
|
||||
[WS_INBOUND_EVENTS.CLIENT_REGISTERED]: ['/calendars/cal1/entry1'],
|
||||
[WS_INBOUND_EVENTS.CLIENT_UNREGISTERED]: ['/calendars/cal2/entry2'],
|
||||
'/calendars/cal1/entry1': {}
|
||||
}
|
||||
|
||||
const result = parseMessage(message);
|
||||
const result = parseMessage(message)
|
||||
|
||||
expect(result.calendarsToRefresh.size).toBe(1);
|
||||
expect(result.calendarsToRefresh).toContain("/calendars/cal1/entry1");
|
||||
});
|
||||
});
|
||||
expect(result.calendarsToRefresh.size).toBe(1)
|
||||
expect(result.calendarsToRefresh).toContain('/calendars/cal1/entry1')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
import { registerToCalendars } from "@/websocket/operations/registerToCalendars";
|
||||
import { registerToCalendars } from '@/websocket/operations/registerToCalendars'
|
||||
|
||||
describe("registerToCalendars", () => {
|
||||
let mockSocket: any;
|
||||
describe('registerToCalendars', () => {
|
||||
let mockSocket: any
|
||||
|
||||
beforeEach(() => {
|
||||
mockSocket = {
|
||||
readyState: WebSocket.OPEN,
|
||||
send: jest.fn(),
|
||||
};
|
||||
});
|
||||
send: jest.fn()
|
||||
}
|
||||
})
|
||||
|
||||
it("should send registration message with calendar URIs", () => {
|
||||
const calendarURIs = ["/calendars/cal1", "/calendars/cal2"];
|
||||
it('should send registration message with calendar URIs', () => {
|
||||
const calendarURIs = ['/calendars/cal1', '/calendars/cal2']
|
||||
|
||||
registerToCalendars(mockSocket, calendarURIs);
|
||||
registerToCalendars(mockSocket, calendarURIs)
|
||||
|
||||
expect(mockSocket.send).toHaveBeenCalledWith(
|
||||
JSON.stringify({
|
||||
register: calendarURIs,
|
||||
register: calendarURIs
|
||||
})
|
||||
);
|
||||
});
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw error if socket is not open", () => {
|
||||
mockSocket.readyState = WebSocket.CONNECTING;
|
||||
const calendarURIs = ["/calendars/cal1"];
|
||||
it('should throw error if socket is not open', () => {
|
||||
mockSocket.readyState = WebSocket.CONNECTING
|
||||
const calendarURIs = ['/calendars/cal1']
|
||||
|
||||
expect(() => registerToCalendars(mockSocket, calendarURIs)).toThrow(
|
||||
"Cannot register: WebSocket is not open"
|
||||
);
|
||||
});
|
||||
'Cannot register: WebSocket is not open'
|
||||
)
|
||||
})
|
||||
|
||||
it("should handle empty calendar list", () => {
|
||||
registerToCalendars(mockSocket, []);
|
||||
it('should handle empty calendar list', () => {
|
||||
registerToCalendars(mockSocket, [])
|
||||
|
||||
expect(mockSocket.send).toHaveBeenCalledWith(
|
||||
JSON.stringify({
|
||||
register: [],
|
||||
register: []
|
||||
})
|
||||
);
|
||||
});
|
||||
)
|
||||
})
|
||||
|
||||
it("should log registration", () => {
|
||||
const consoleInfoSpy = jest.spyOn(console, "info").mockImplementation();
|
||||
const calendarURIs = ["/calendars/cal1", "/calendars/cal2"];
|
||||
it('should log registration', () => {
|
||||
const consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation()
|
||||
const calendarURIs = ['/calendars/cal1', '/calendars/cal2']
|
||||
|
||||
registerToCalendars(mockSocket, calendarURIs);
|
||||
registerToCalendars(mockSocket, calendarURIs)
|
||||
|
||||
expect(consoleInfoSpy).toHaveBeenCalledWith(
|
||||
"Registered to calendars",
|
||||
'Registered to calendars',
|
||||
calendarURIs
|
||||
);
|
||||
)
|
||||
|
||||
consoleInfoSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
consoleInfoSpy.mockRestore()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,58 +1,58 @@
|
||||
import { unregisterToCalendars } from "@/websocket/operations/unregisterToCalendars";
|
||||
import { unregisterToCalendars } from '@/websocket/operations/unregisterToCalendars'
|
||||
|
||||
describe("unregisterToCalendars", () => {
|
||||
let mockSocket: any;
|
||||
describe('unregisterToCalendars', () => {
|
||||
let mockSocket: any
|
||||
|
||||
beforeEach(() => {
|
||||
mockSocket = {
|
||||
readyState: WebSocket.OPEN,
|
||||
send: jest.fn(),
|
||||
};
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
send: jest.fn()
|
||||
}
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
it("should send unregistration message with calendar URIs", () => {
|
||||
const calendarURIs = ["/calendars/cal1", "/calendars/cal2"];
|
||||
it('should send unregistration message with calendar URIs', () => {
|
||||
const calendarURIs = ['/calendars/cal1', '/calendars/cal2']
|
||||
|
||||
unregisterToCalendars(mockSocket, calendarURIs);
|
||||
unregisterToCalendars(mockSocket, calendarURIs)
|
||||
|
||||
expect(mockSocket.send).toHaveBeenCalledWith(
|
||||
JSON.stringify({
|
||||
unregister: calendarURIs,
|
||||
unregister: calendarURIs
|
||||
})
|
||||
);
|
||||
});
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw error if socket is not open", () => {
|
||||
mockSocket.readyState = WebSocket.CONNECTING;
|
||||
const calendarURIs = ["/calendars/cal1"];
|
||||
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"
|
||||
);
|
||||
});
|
||||
'Cannot unregister: WebSocket is not open'
|
||||
)
|
||||
})
|
||||
|
||||
it("should handle empty calendar list", () => {
|
||||
unregisterToCalendars(mockSocket, []);
|
||||
it('should handle empty calendar list', () => {
|
||||
unregisterToCalendars(mockSocket, [])
|
||||
|
||||
expect(mockSocket.send).toHaveBeenCalledWith(
|
||||
JSON.stringify({
|
||||
unregister: [],
|
||||
unregister: []
|
||||
})
|
||||
);
|
||||
});
|
||||
)
|
||||
})
|
||||
|
||||
it("should log unregistration", () => {
|
||||
const consoleInfoSpy = jest.spyOn(console, "info").mockImplementation();
|
||||
const calendarURIs = ["/calendars/cal1", "/calendars/cal2"];
|
||||
it('should log unregistration', () => {
|
||||
const consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation()
|
||||
const calendarURIs = ['/calendars/cal1', '/calendars/cal2']
|
||||
|
||||
unregisterToCalendars(mockSocket, calendarURIs);
|
||||
unregisterToCalendars(mockSocket, calendarURIs)
|
||||
|
||||
expect(consoleInfoSpy).toHaveBeenCalledWith(
|
||||
"Unregistered to calendars",
|
||||
'Unregistered to calendars',
|
||||
calendarURIs
|
||||
);
|
||||
)
|
||||
|
||||
consoleInfoSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
consoleInfoSpy.mockRestore()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user