Files
kandev/apps/web/app/actions/workspaces.test.ts
T

34 lines
1005 B
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
vi.mock("@/lib/config", () => ({
getBackendConfig: () => ({ apiBaseUrl: "http://backend.test" }),
}));
import { deleteWorkspaceAction } from "./workspaces";
describe("deleteWorkspaceAction", () => {
beforeEach(() => {
vi.stubGlobal(
"fetch",
vi.fn(async () => new Response("", { status: 204 })),
);
});
afterEach(() => {
vi.unstubAllGlobals();
vi.restoreAllMocks();
});
it("sends the workspace name as confirm_name in the DELETE body", async () => {
await deleteWorkspaceAction("ws-1", "My Workspace");
const fetchMock = fetch as unknown as ReturnType<typeof vi.fn>;
expect(fetchMock).toHaveBeenCalledTimes(1);
const [url, init] = fetchMock.mock.calls[0];
expect(url).toBe("http://backend.test/api/v1/office/workspaces/ws-1");
expect(init.method).toBe("DELETE");
expect(JSON.parse(init.body as string)).toEqual({ confirm_name: "My Workspace" });
});
});