Files
DeepTutor/web/tests/session-api-delete-message.spec.ts
yuanyyt 19760d5ded fix: refresh tutor threads after deleting a source message
Return the detached thread ids from deleteMessage and have deleteTurn
notify the session-change bus, so useSessionThreads and the viewer refresh
immediately instead of keeping a stale marker.

ChatWorkspace clears only the tabs still pointing at one of the deleted
message rows; a newer passage selected but not yet sent survives the delete.
2026-10-30 23:15:37 +08:00

40 lines
1.0 KiB
TypeScript

import { afterEach, expect, it, vi } from "vitest";
import { deleteMessage } from "@/lib/session-api";
afterEach(() => {
vi.unstubAllGlobals();
});
it("passes the detached tutor threads through to the caller", async () => {
const fetchMock = vi.fn(async () =>
Response.json({
deleted: true,
detached_thread_ids: ["thread-1", "thread-2"],
deleted_message_ids: [7, 8],
}),
);
vi.stubGlobal("fetch", fetchMock);
await expect(deleteMessage("session-1", 7)).resolves.toEqual({
detachedThreadIds: ["thread-1", "thread-2"],
deletedMessageIds: [7, 8],
});
expect(fetchMock).toHaveBeenCalledWith(
expect.stringContaining("/api/sessions/session-1/messages/7"),
expect.objectContaining({ method: "DELETE" }),
);
});
it("returns no threads when an older server omits the list", async () => {
vi.stubGlobal(
"fetch",
vi.fn(async () => Response.json({ deleted: true })),
);
await expect(deleteMessage("session-1", 7)).resolves.toEqual({
detachedThreadIds: [],
deletedMessageIds: [7],
});
});