diff --git a/frontend/src/api/sessions.test.ts b/frontend/src/api/sessions.test.ts index 4082a3df..06c362fa 100644 --- a/frontend/src/api/sessions.test.ts +++ b/frontend/src/api/sessions.test.ts @@ -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"); +}); diff --git a/frontend/src/api/sessions.ts b/frontend/src/api/sessions.ts index f84b4546..f3a88b7d 100644 --- a/frontend/src/api/sessions.ts +++ b/frontend/src/api/sessions.ts @@ -1,5 +1,5 @@ import { apiFetch } from "./client"; -import type { SessionSummary, UiResponse } from "./types"; +import type { SessionSummary, SessionDocument, UiResponse } from "./types"; export const createSession = (i: { question: string; name?: string }) => apiFetch<{ id: string }>("/sessions", { method: "POST", body: JSON.stringify(i) }); @@ -26,3 +26,21 @@ export const closeSession = (id: string) => export const resumeSession = (id: string) => apiFetch(`/sessions/${id}/resume`, { method: "POST" }); + +export const renameSession = (id: string, name: string) => + apiFetch(`/sessions/${id}/rename`, { method: "POST", body: JSON.stringify({ name }) }); + +export const setSessionGroup = (id: string, group: string) => + apiFetch(`/sessions/${id}/group`, { method: "POST", body: JSON.stringify({ group }) }); + +export const archiveSession = (id: string) => + apiFetch(`/sessions/${id}/archive`, { method: "POST" }); + +export const unarchiveSession = (id: string) => + apiFetch(`/sessions/${id}/unarchive`, { method: "POST" }); + +export const deleteSession = (id: string) => + apiFetch(`/sessions/${id}`, { method: "DELETE" }); + +export const getSessionDocuments = (id: string) => + apiFetch(`/sessions/${id}/documents`); diff --git a/frontend/src/api/types.ts b/frontend/src/api/types.ts index 2482b884..db794623 100644 --- a/frontend/src/api/types.ts +++ b/frontend/src/api/types.ts @@ -47,6 +47,17 @@ export interface SessionSummary { created_at: string; updated_at: string | null; author: string | null; + name: string | null; + group: string | null; + archived: boolean; +} + +export interface SessionDocument { + phase: string; + key: string; + title: string; + format: "markdown" | "sql" | "schema-linking" | "decisions" | "text"; + content: string; } export interface PreviewResult {