Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
test(hub): cover conversation rpc handlers
Jiayuan Zhang6a778e38e727
diff --git a/packages/core/src/hub/rpc/handlers/create-conversation.test.ts b/packages/core/src/hub/rpc/handlers/create-conversation.test.tsnew file mode 100644index 0000000000..ad308ff744--- /dev/null+++ b/packages/core/src/hub/rpc/handlers/create-conversation.test.ts@@ -0,0 +1,24 @@+import { describe, it, expect, vi } from "vitest";+import { createCreateConversationHandler } from "./create-conversation.js";++describe("createCreateConversationHandler", () => {+ it("creates conversation with explicit id", () => {+ const createConversation = vi.fn(() => ({ sessionId: "conv-1" }));+ const handler = createCreateConversationHandler({ createConversation });++ const result = handler({ id: "custom-id" }, "device-1") as { id: string };++ expect(createConversation).toHaveBeenCalledWith("custom-id");+ expect(result).toEqual({ id: "conv-1" });+ });++ it("creates conversation without id when params are missing", () => {+ const createConversation = vi.fn(() => ({ sessionId: "conv-2" }));+ const handler = createCreateConversationHandler({ createConversation });++ const result = handler(undefined, "device-1") as { id: string };++ expect(createConversation).toHaveBeenCalledWith(undefined);+ expect(result).toEqual({ id: "conv-2" });+ });+});diff --git a/packages/core/src/hub/rpc/handlers/delete-conversation.test.ts b/packages/core/src/hub/rpc/handlers/delete-conversation.test.tsnew file mode 100644index 0000000000..2b583d5327--- /dev/null+++ b/packages/core/src/hub/rpc/handlers/delete-conversation.test.ts@@ -0,0 +1,33 @@+import { describe, it, expect, vi } from "vitest";+import { RpcError } from "../dispatcher.js";+import { createDeleteConversationHandler } from "./delete-conversation.js";++describe("createDeleteConversationHandler", () => {+ it("throws INVALID_PARAMS when params are not an object", () => {+ const closeConversation = vi.fn();+ const handler = createDeleteConversationHandler({ closeConversation });++ expect(() => handler(undefined, "device-1")).toThrowError(RpcError);+ expect(() => handler(undefined, "device-1")).toThrowError("params must be an object");+ expect(closeConversation).not.toHaveBeenCalled();+ });++ it("throws INVALID_PARAMS when id is missing", () => {+ const closeConversation = vi.fn();+ const handler = createDeleteConversationHandler({ closeConversation });++ expect(() => handler({}, "device-1")).toThrowError(RpcError);+ expect(() => handler({}, "device-1")).toThrowError("Missing required param: id");+ expect(closeConversation).not.toHaveBeenCalled();+ });++ it("closes conversation when id is provided", () => {+ const closeConversation = vi.fn(() => true);+ const handler = createDeleteConversationHandler({ closeConversation });++ const result = handler({ id: "conv-1" }, "device-1") as { ok: boolean };++ expect(closeConversation).toHaveBeenCalledWith("conv-1");+ expect(result).toEqual({ ok: true });+ });+});diff --git a/packages/core/src/hub/rpc/handlers/list-conversations.test.ts b/packages/core/src/hub/rpc/handlers/list-conversations.test.tsnew file mode 100644index 0000000000..20b8c20b4c--- /dev/null+++ b/packages/core/src/hub/rpc/handlers/list-conversations.test.ts@@ -0,0 +1,35 @@+import { describe, it, expect, vi } from "vitest";+import { createListConversationsHandler } from "./list-conversations.js";++describe("createListConversationsHandler", () => {+ it("lists conversations with closed status", () => {+ const listConversations = vi.fn(() => ["conv-1", "conv-2"]);+ const getConversation = vi.fn((id: string) => (id === "conv-1" ? { closed: false } : { closed: true }));+ const handler = createListConversationsHandler({ listConversations, getConversation });++ const result = handler(undefined, "device-1") as {+ conversations: Array<{ id: string; closed: boolean }>;+ };++ expect(result).toEqual({+ conversations: [+ { id: "conv-1", closed: false },+ { id: "conv-2", closed: true },+ ],+ });+ });++ it("defaults closed=true when conversation is missing", () => {+ const listConversations = vi.fn(() => ["conv-1"]);+ const getConversation = vi.fn(() => undefined);+ const handler = createListConversationsHandler({ listConversations, getConversation });++ const result = handler(undefined, "device-1") as {+ conversations: Array<{ id: string; closed: boolean }>;+ };++ expect(result).toEqual({+ conversations: [{ id: "conv-1", closed: true }],+ });+ });+});