30 lines
1.1 KiB
TypeScript
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");
|
|
});
|
|
});
|