mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 03:09:49 +08:00
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.
40 lines
1.0 KiB
TypeScript
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],
|
|
});
|
|
});
|