forked from syntaxbullet/AuroraBot-discord
feat: implement visual analytics and activity charts
This commit is contained in:
@@ -189,4 +189,43 @@ describe("dashboardService", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("getActivityAggregation", () => {
|
||||
test("should return exactly 24 data points representing the last 24 hours", async () => {
|
||||
const now = new Date();
|
||||
now.setHours(now.getHours(), 0, 0, 0);
|
||||
|
||||
mockSelect.mockImplementationOnce(() => ({
|
||||
// @ts-ignore
|
||||
from: mock(() => ({
|
||||
where: mock(() => ({
|
||||
groupBy: mock(() => ({
|
||||
orderBy: mock(() => Promise.resolve([
|
||||
{
|
||||
hour: now.toISOString(),
|
||||
transactions: "10",
|
||||
commands: "5"
|
||||
}
|
||||
]))
|
||||
}))
|
||||
}))
|
||||
}))
|
||||
}));
|
||||
|
||||
const activity = await dashboardService.getActivityAggregation();
|
||||
|
||||
expect(activity).toHaveLength(24);
|
||||
|
||||
// Check if the current hour matches our mock
|
||||
const currentHourData = activity.find(a => new Date(a.hour).getTime() === now.getTime());
|
||||
expect(currentHourData).toBeDefined();
|
||||
expect(currentHourData?.transactions).toBe(10);
|
||||
expect(currentHourData?.commands).toBe(5);
|
||||
|
||||
// Check if missing hours are filled with 0
|
||||
const otherHour = activity.find(a => new Date(a.hour).getTime() !== now.getTime());
|
||||
expect(otherHour?.transactions).toBe(0);
|
||||
expect(otherHour?.commands).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user