Files
buzz-sheet/lib/cache/analytics.test.ts
T
gunshiz a3803118ef
CI / Verify (push) Successful in 2m10s
CI / Build immutable images and deploy (push) Successful in 2m33s
feat : add analytics page
2026-10-10 20:19:49 +07:00

18 lines
819 B
TypeScript

import { beforeEach, expect, it, vi } from "vitest";
const mocks = vi.hoisted(() => ({ tag: vi.fn(), life: vi.fn(), query: vi.fn() }));
vi.mock("server-only", () => ({}));
vi.mock("next/cache", () => ({ cacheTag: mocks.tag, cacheLife: mocks.life }));
vi.mock("@/lib/analytics/queries", () => ({ getPublicAnalytics: mocks.query }));
import { getCachedPublicAnalytics } from "./analytics";
beforeEach(() => vi.resetAllMocks());
it("tags analytics for aggregate invalidation and uses the public revalidation interval", async () => {
const result = { guideCount: 2 };
mocks.query.mockResolvedValue(result);
expect(await getCachedPublicAnalytics()).toBe(result);
expect(mocks.tag).toHaveBeenCalledWith("buzz:analytics");
expect(mocks.life).toHaveBeenCalledWith({ stale: 15, revalidate: 60, expire: 3600 });
});