Files
canina/frontend/application/app/api/revalidate/route.test.ts
devops ff6f04fe46
Deploy Canina / deploy (push) Successful in 2m35s
fix(cache): revalidate storefront after admin mutations
2026-10-18 19:31:46 +00:00

30 lines
1.1 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
import { NextRequest } from "next/server";
import { revalidatePath, revalidateTag } from "next/cache";
import { POST } from "./route";
vi.mock("next/cache", () => ({ revalidatePath: vi.fn(), revalidateTag: vi.fn() }));
describe("revalidation route", () => {
beforeEach(() => {
vi.clearAllMocks();
process.env.REVALIDATION_SECRET = "test-secret";
});
it("revalidates deduplicated tag and path batches", async () => {
const request = new NextRequest("http://localhost/api/revalidate", {
method: "POST",
headers: { "content-type": "application/json", "x-revalidate-secret": "test-secret" },
body: JSON.stringify({ tags: ["blogs", "blogs"], paths: ["/blog", "/blog"] }),
});
const response = await POST(request);
expect(response.status).toBe(200);
expect(revalidateTag).toHaveBeenCalledTimes(1);
expect(revalidateTag).toHaveBeenCalledWith("blogs", "default");
expect(revalidatePath).toHaveBeenCalledTimes(1);
expect(revalidatePath).toHaveBeenCalledWith("/blog", "page");
});
});