forked from syntaxbullet/AuroraBot-discord
fix(dash): address safety constraints, validation, and test quality issues
This commit is contained in:
@@ -148,15 +148,15 @@ describe("dashboardService", () => {
|
||||
|
||||
expect(events).toHaveLength(2);
|
||||
// Should be sorted by timestamp (newest first)
|
||||
expect(events[0]?.timestamp.getTime()).toBeGreaterThanOrEqual(
|
||||
events[1]?.timestamp.getTime() ?? 0
|
||||
);
|
||||
const t0 = events[0]?.timestamp instanceof Date ? events[0].timestamp.getTime() : new Date(events[0]?.timestamp ?? 0).getTime();
|
||||
const t1 = events[1]?.timestamp instanceof Date ? events[1].timestamp.getTime() : new Date(events[1]?.timestamp ?? 0).getTime();
|
||||
expect(t0).toBeGreaterThanOrEqual(t1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("recordEvent", () => {
|
||||
test("should emit NEW_EVENT to systemEvents", async () => {
|
||||
const mockEmit = mock(() => { });
|
||||
const mockEmit = mock((_event: string, _data: any) => { });
|
||||
|
||||
mock.module("@shared/lib/events", () => ({
|
||||
systemEvents: {
|
||||
@@ -176,10 +176,17 @@ describe("dashboardService", () => {
|
||||
});
|
||||
|
||||
expect(mockEmit).toHaveBeenCalled();
|
||||
const [eventName, data] = mockEmit.mock.calls[0] as any;
|
||||
expect(eventName).toBe("dashboard:new_event");
|
||||
expect(data.message).toBe("Test Event");
|
||||
expect(data.timestamp).toBeDefined();
|
||||
const calls = mockEmit.mock.calls;
|
||||
if (calls.length > 0 && calls[0]) {
|
||||
expect(calls[0][0]).toBe("dashboard:new_event");
|
||||
const data = calls[0][1] as { message: string, timestamp: string };
|
||||
expect(data.message).toBe("Test Event");
|
||||
expect(data.timestamp).toBeDefined();
|
||||
// Verify it's an ISO string
|
||||
expect(() => new Date(data.timestamp).toISOString()).not.toThrow();
|
||||
} else {
|
||||
throw new Error("mockEmit was not called with expected arguments");
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user