feat(FN-4739): complete Step 3 — add room transcript clear route
Fusion-Task-Id: FN-4739 Fusion-Task-Lineage: fc120dfa-d1b2-4065-9595-d0bc6304d2af
This commit is contained in:
committed by
gsxdsm
parent
356f49588a
commit
698e8c272a
@@ -269,6 +269,32 @@ describe("Chat Room API Routes", () => {
|
||||
expect(del2.status).toBe(404);
|
||||
});
|
||||
|
||||
it("clears all messages in a room", async () => {
|
||||
const room = chatStore.createRoom({ name: "Clear API" });
|
||||
chatStore.addRoomMessage(room.id, { role: "user", content: "one" });
|
||||
chatStore.addRoomMessage(room.id, { role: "assistant", content: "two" });
|
||||
chatStore.addRoomMessage(room.id, { role: "user", content: "three" });
|
||||
|
||||
const res = await request(app, "DELETE", `/api/chat/rooms/${room.id}/messages`);
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body).toEqual({ success: true, deletedCount: 3 });
|
||||
expect(chatStore.getRoomMessages(room.id)).toEqual([]);
|
||||
});
|
||||
|
||||
it("returns 404 when clearing messages for an unknown room", async () => {
|
||||
const res = await request(app, "DELETE", "/api/chat/rooms/room-missing/messages");
|
||||
expect(res.status).toBe(404);
|
||||
});
|
||||
|
||||
it("keeps per-message delete route behavior after adding room-clear endpoint", async () => {
|
||||
const room = chatStore.createRoom({ name: "Route ordering" });
|
||||
const message = chatStore.addRoomMessage(room.id, { role: "user", content: "one" });
|
||||
|
||||
const res = await request(app, "DELETE", `/api/chat/rooms/${room.id}/messages/${message.id}`);
|
||||
expect(res.status).toBe(200);
|
||||
expect(chatStore.getRoomMessage(message.id)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("handles message attachments route", async () => {
|
||||
const room = chatStore.createRoom({ name: "Files" });
|
||||
const message = chatStore.addRoomMessage(room.id, { role: "user", content: "hello" });
|
||||
|
||||
@@ -332,6 +332,21 @@ export function registerChatRoomRoutes(ctx: ApiRoutesContext): void {
|
||||
}
|
||||
});
|
||||
|
||||
router.delete("/chat/rooms/:id/messages", rateLimit(RATE_LIMITS.mutation), async (req, res) => {
|
||||
try {
|
||||
const roomId = String(req.params.id);
|
||||
const { chatStore } = await resolveRoomScopedServices(req, getRequestedProjectId(req));
|
||||
const room = chatStore.getRoom(roomId);
|
||||
if (!room) throw notFound(`Chat room ${roomId} not found`);
|
||||
|
||||
const deletedCount = chatStore.clearRoomMessages(roomId);
|
||||
res.json({ success: true, deletedCount });
|
||||
} catch (err: unknown) {
|
||||
if (err instanceof ApiError) throw err;
|
||||
rethrowAsApiError(err, "Failed to clear chat room messages");
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/chat/rooms/:id/messages/:messageId/attachments", rateLimit(RATE_LIMITS.mutation), async (req, res) => {
|
||||
try {
|
||||
const roomId = String(req.params.id);
|
||||
@@ -371,6 +386,7 @@ export function registerChatRoomRoutes(ctx: ApiRoutesContext): void {
|
||||
"GET /chat/rooms/:id/messages",
|
||||
"POST /chat/rooms/:id/messages",
|
||||
"DELETE /chat/rooms/:id/messages/:messageId",
|
||||
"DELETE /chat/rooms/:id/messages",
|
||||
"POST /chat/rooms/:id/messages/:messageId/attachments",
|
||||
];
|
||||
chatLogger.info("room routes registered", { chatRoomRoutes });
|
||||
|
||||
Reference in New Issue
Block a user