Files
hunjing/frontend/src/lib/api/embryos.test.ts
T

52 lines
1.5 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
vi.mock("./client", () => ({
apiRequest: vi.fn(),
apiGet: vi.fn(),
apiPatch: vi.fn(),
apiPost: vi.fn(),
}));
import { apiRequest, apiGet, apiPost } from "./client";
import {
activateEmbryo,
importCard,
listEmbryos,
rehearseEmbryo,
} from "./embryos";
describe("embryos api", () => {
it("listEmbryos GET /embryo-drafts", async () => {
vi.mocked(apiGet).mockResolvedValue([]);
await listEmbryos();
expect(apiGet).toHaveBeenCalledWith("/embryo-drafts");
});
it("rehearseEmbryo POST /embryo-drafts/:id/rehearse", async () => {
vi.mocked(apiPost).mockResolvedValue({
run_id: "run_1",
kind: "rehearsal",
});
await rehearseEmbryo("embryo_1", "你是谁");
expect(apiPost).toHaveBeenCalledWith("/embryo-drafts/embryo_1/rehearse", {
prompt: "你是谁",
});
});
it("activateEmbryo POST /embryo-drafts/:id/activate", async () => {
vi.mocked(apiPost).mockResolvedValue({ character_id: "character_1" });
await activateEmbryo("embryo_1");
expect(apiPost).toHaveBeenCalledWith("/embryo-drafts/embryo_1/activate");
});
it("importCard 以 FormData POST /characters/import-card", async () => {
vi.mocked(apiRequest).mockResolvedValue({ embryo_id: "embryo_2" });
const file = new File(["{}"], "card.json", { type: "application/json" });
await importCard(file);
expect(apiRequest).toHaveBeenCalledWith(
"/characters/import-card",
expect.objectContaining({ method: "POST", body: expect.any(FormData) }),
);
});
});