Some checks failed
Verify and publish container / build-and-push (push) Failing after 33s
44 lines
1.9 KiB
TypeScript
44 lines
1.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { summarizeActivityBuckets, summarizeActivityRows } from "./activityService";
|
|
|
|
describe("summarizeActivityRows", () => {
|
|
it("summarizes the remaining activity categories without Arcade fields", () => {
|
|
const now = new Date("2026-08-07T18:00:00.000Z");
|
|
const summary = summarizeActivityBuckets([
|
|
{ date: "2026-08-07", type: "FLASHCARD", count: 2 },
|
|
{ date: "2026-08-07", type: "QUIZ_QUESTION", count: 3 },
|
|
], now);
|
|
|
|
expect(summary).toMatchObject({ flashcards: 2, questions: 3, currentStreak: 0 });
|
|
expect(summary.days.find((day) => day.date === summary.today)).toMatchObject({ flashcards: 2, questions: 3, total: 5 });
|
|
expect(summary).not.toHaveProperty("arcade");
|
|
});
|
|
|
|
it("keeps a 53-week display while preserving a longer current streak", () => {
|
|
const now = new Date("2026-08-07T18:00:00.000Z");
|
|
const activities = Array.from({ length: 400 }, (_, age) =>
|
|
Array.from({ length: 20 }, () => ({
|
|
type: "FLASHCARD",
|
|
occurredAt: new Date(now.getTime() - age * 24 * 60 * 60 * 1000),
|
|
}))
|
|
).flat();
|
|
const summary = summarizeActivityRows(activities, now);
|
|
expect(summary.days).toHaveLength(371);
|
|
expect(summary.currentStreak).toBe(400);
|
|
expect(summary.days.filter((day) => day.date <= summary.today).at(-1)?.date).toBe(summary.today);
|
|
});
|
|
|
|
it("preserves counts and long streaks from database-aggregated daily buckets", () => {
|
|
const now = new Date("2026-08-07T18:00:00.000Z");
|
|
const buckets = Array.from({ length: 400 }, (_, age) => ({
|
|
date: new Date(now.getTime() - 7 * 60 * 60 * 1000 - age * 86_400_000)
|
|
.toISOString()
|
|
.slice(0, 10),
|
|
type: "FLASHCARD",
|
|
count: 20,
|
|
}));
|
|
const summary = summarizeActivityBuckets(buckets, now);
|
|
expect(summary.currentStreak).toBe(400);
|
|
expect(summary.days).toHaveLength(371);
|
|
});
|
|
});
|