18 lines
819 B
TypeScript
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 });
|
|
});
|