feat(frontend): session mutation + documents API client and types
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { server } from "../test/msw";
|
||||
import { createSession, listSessions } from "./sessions";
|
||||
import {
|
||||
renameSession, setSessionGroup, archiveSession, unarchiveSession,
|
||||
deleteSession, getSessionDocuments,
|
||||
} from "./sessions";
|
||||
|
||||
test("createSession POSTs only {question} and returns the id", async () => {
|
||||
let body: unknown = null;
|
||||
@@ -19,3 +23,44 @@ test("listSessions GETs the array", async () => {
|
||||
const rows = await listSessions();
|
||||
expect(rows[0].id).toBe("s1");
|
||||
});
|
||||
|
||||
test("renameSession POSTs {name}", async () => {
|
||||
let body: unknown = null;
|
||||
server.use(http.post("http://localhost:8787/sessions/s1/rename", async ({ request }) => {
|
||||
body = await request.json();
|
||||
return new HttpResponse(null, { status: 204 });
|
||||
}));
|
||||
await renameSession("s1", "Nome");
|
||||
expect(body).toEqual({ name: "Nome" });
|
||||
});
|
||||
|
||||
test("setSessionGroup POSTs {group}", async () => {
|
||||
let body: unknown = null;
|
||||
server.use(http.post("http://localhost:8787/sessions/s1/group", async ({ request }) => {
|
||||
body = await request.json();
|
||||
return new HttpResponse(null, { status: 204 });
|
||||
}));
|
||||
await setSessionGroup("s1", "G");
|
||||
expect(body).toEqual({ group: "G" });
|
||||
});
|
||||
|
||||
test("archive / unarchive / delete hit the right verbs+paths", async () => {
|
||||
const hits: string[] = [];
|
||||
server.use(
|
||||
http.post("http://localhost:8787/sessions/s1/archive", () => { hits.push("archive"); return new HttpResponse(null, { status: 204 }); }),
|
||||
http.post("http://localhost:8787/sessions/s1/unarchive", () => { hits.push("unarchive"); return new HttpResponse(null, { status: 204 }); }),
|
||||
http.delete("http://localhost:8787/sessions/s1", () => { hits.push("delete"); return new HttpResponse(null, { status: 204 }); }),
|
||||
);
|
||||
await archiveSession("s1");
|
||||
await unarchiveSession("s1");
|
||||
await deleteSession("s1");
|
||||
expect(hits).toEqual(["archive", "unarchive", "delete"]);
|
||||
});
|
||||
|
||||
test("getSessionDocuments GETs the array", async () => {
|
||||
server.use(http.get("http://localhost:8787/sessions/s1/documents", () =>
|
||||
HttpResponse.json([{ phase: "—", key: "question", title: "t", format: "text", content: "q" }]),
|
||||
));
|
||||
const docs = await getSessionDocuments("s1");
|
||||
expect(docs[0].key).toBe("question");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user