Files
site/apps/web/src/modules/content/api/contentApi.test.ts
T
vlad 86cc3fa541 Update admin theme/layout and refresh README details.
Align the project baseline with the latest admin interface styling and layout structure while documenting setup and usage updates in README.
2026-07-14 17:12:28 +03:00

54 lines
1.6 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import {
createContentPage,
deleteContentPage,
getAdminPages,
getPageBySlug,
updateContentPage
} from "./contentApi";
vi.mock("@shared/api/client", () => ({
apiClient: {
get: vi.fn(async (url: string) => {
if (url === "/api/v1/content/pages/manage/all") {
return { data: { data: [{ id: "1", slug: "about", title: "About", body: "", status: "published" }] } };
}
return { data: { slug: "about", title: "About" } };
}),
post: vi.fn(async () => ({ data: { id: "2", slug: "new", title: "New", body: "", status: "draft" } })),
patch: vi.fn(async () => ({ data: { id: "1", slug: "about", title: "Updated", body: "", status: "published" } })),
delete: vi.fn(async () => ({ data: {} }))
}
}));
describe("contentApi", () => {
it("loads page by slug", async () => {
const data = await getPageBySlug("about");
expect(data.slug).toBe("about");
});
it("loads admin pages", async () => {
const pages = await getAdminPages();
expect(pages[0].slug).toBe("about");
});
it("creates content page", async () => {
const page = await createContentPage({
slug: "new",
title: "New",
body: "<p>x</p>",
status: "draft"
});
expect(page.slug).toBe("new");
});
it("updates content page", async () => {
const page = await updateContentPage("1", { title: "Updated" });
expect(page.title).toBe("Updated");
});
it("deletes content page", async () => {
await expect(deleteContentPage("1")).resolves.toBeUndefined();
});
});