fix(cache): revalidate storefront after admin mutations
Deploy Canina / deploy (push) Successful in 2m35s
Deploy Canina / deploy (push) Successful in 2m35s
This commit is contained in:
1 parent
2e9a0e30c1
commit
ff6f04fe46
7 files changed
+205
-49
No files matched your search
@@ -0,0 +1,29 @@
|
||||
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");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user