dashboard-cache-keys.test.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { describe, expect, it } from "vitest";
  2. import { buildOverviewCacheKey, buildStatisticsCacheKey } from "@/types/dashboard-cache";
  3. import type { TimeRange } from "@/types/statistics";
  4. describe("buildOverviewCacheKey", () => {
  5. it("returns 'overview:global' for global scope", () => {
  6. expect(buildOverviewCacheKey("global")).toBe("overview:global");
  7. });
  8. it("returns 'overview:user:42' for user scope with userId=42", () => {
  9. expect(buildOverviewCacheKey("user", 42)).toBe("overview:user:42");
  10. });
  11. });
  12. describe("buildStatisticsCacheKey", () => {
  13. it("returns correct key for today/users/global", () => {
  14. expect(buildStatisticsCacheKey("today", "users")).toBe("statistics:today:users:global");
  15. });
  16. it("returns correct key with userId", () => {
  17. expect(buildStatisticsCacheKey("7days", "keys", 42)).toBe("statistics:7days:keys:42");
  18. });
  19. it("handles all TimeRange values", () => {
  20. const timeRanges: TimeRange[] = ["today", "7days", "30days", "thisMonth"];
  21. const keys = timeRanges.map((timeRange) => buildStatisticsCacheKey(timeRange, "users"));
  22. expect(keys).toEqual([
  23. "statistics:today:users:global",
  24. "statistics:7days:users:global",
  25. "statistics:30days:users:global",
  26. "statistics:thisMonth:users:global",
  27. ]);
  28. expect(new Set(keys).size).toBe(timeRanges.length);
  29. });
  30. });