feat(FN-4583): complete Step 4 — fetch newest chat room message window
Fusion-Task-Id: FN-4583 Fusion-Task-Lineage: 4d9b088d-a705-4376-b547-15b37e5370aa
This commit is contained in:
@@ -73,7 +73,7 @@ describe("chat room legacy API client", () => {
|
||||
it("builds message endpoints", async () => {
|
||||
const fetchMock = vi.spyOn(globalThis, "fetch").mockImplementation(async () => jsonResponse({ success: true }));
|
||||
|
||||
await fetchChatRoomMessages("room-1", { limit: 2, offset: 1, before: "2026-01-01" }, "proj-3");
|
||||
await fetchChatRoomMessages("room-1", { limit: 2, offset: 1, before: "2026-01-01", order: "desc" }, "proj-3");
|
||||
await postChatRoomMessage("room-1", { content: "hello", mentions: ["agent-x"] }, "proj-3");
|
||||
await deleteChatRoomMessage("room-1", "msg-1", "proj-3");
|
||||
|
||||
@@ -83,6 +83,7 @@ describe("chat room legacy API client", () => {
|
||||
expect(listUrl).toContain("limit=2");
|
||||
expect(listUrl).toContain("offset=1");
|
||||
expect(listUrl).toContain("before=2026-01-01");
|
||||
expect(listUrl).toContain("order=desc");
|
||||
|
||||
const [, postInit] = fetchMock.mock.calls[1] as [string, RequestInit];
|
||||
expect(postInit.method).toBe("POST");
|
||||
@@ -91,4 +92,14 @@ describe("chat room legacy API client", () => {
|
||||
const [, delInit] = fetchMock.mock.calls[2] as [string, RequestInit];
|
||||
expect(delInit.method).toBe("DELETE");
|
||||
});
|
||||
|
||||
it("omits order param when undefined", async () => {
|
||||
const fetchMock = vi.spyOn(globalThis, "fetch").mockImplementation(async () => jsonResponse({ messages: [] }));
|
||||
|
||||
await fetchChatRoomMessages("room-1", { limit: 2 }, "proj-3");
|
||||
|
||||
const [listUrl] = fetchMock.mock.calls[0] as [string, RequestInit];
|
||||
expect(listUrl).toContain("limit=2");
|
||||
expect(listUrl).not.toContain("order=");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8466,13 +8466,14 @@ export function removeChatRoomMember(id: string, agentId: string, projectId?: st
|
||||
|
||||
export function fetchChatRoomMessages(
|
||||
id: string,
|
||||
opts?: { limit?: number; offset?: number; before?: string },
|
||||
opts?: { limit?: number; offset?: number; before?: string; order?: "asc" | "desc" },
|
||||
projectId?: string,
|
||||
): Promise<ChatRoomMessageListResponse> {
|
||||
const search = new URLSearchParams();
|
||||
if (opts?.limit !== undefined) search.set("limit", String(opts.limit));
|
||||
if (opts?.offset !== undefined) search.set("offset", String(opts.offset));
|
||||
if (opts?.before) search.set("before", opts.before);
|
||||
if (opts?.order) search.set("order", opts.order);
|
||||
const qs = search.toString();
|
||||
return api<ChatRoomMessageListResponse>(
|
||||
withProjectId(`/chat/rooms/${encodeURIComponent(id)}/messages${qs ? `?${qs}` : ""}`, projectId),
|
||||
|
||||
Reference in New Issue
Block a user