botBoundGroups.test.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { describe, expect, it } from "vitest";
  2. import type { BotState } from "@zcode/shared";
  3. import { projectBoundGroups } from "@/hooks/useBotBoundGroups.js";
  4. const state = (chatId: string, threadId?: string, extra: Partial<BotState> = {}): BotState => ({
  5. botId: "bot",
  6. workspacePath: "/workspace",
  7. mode: "task",
  8. activeTaskId: "task",
  9. updatedAt: 1,
  10. group: {
  11. chatId,
  12. threadId,
  13. name: chatId,
  14. ownerId: "owner",
  15. enabled: true,
  16. taskIds: ["task"],
  17. currentOptions: {},
  18. },
  19. ...extra,
  20. });
  21. describe("bound group list", () => {
  22. it("counts unique recorded topics without mixing bots, groups or owners", () => {
  23. const otherOwner = state("a", "foreign");
  24. otherOwner.group!.ownerId = "other";
  25. const rows = projectBoundGroups(
  26. [
  27. state("a"),
  28. state("a", "t1"),
  29. state("a", "t1"),
  30. state("a", "t2"),
  31. state("b"),
  32. state("b", "t1"),
  33. state("a", "other", { botId: "other" }),
  34. otherOwner,
  35. state("orphan", "t"),
  36. state("private", undefined, { group: undefined }),
  37. ],
  38. "bot",
  39. "owner",
  40. );
  41. expect(rows).toEqual([
  42. { chatId: "a", name: "a", enabled: true, topicCount: 2 },
  43. { chatId: "b", name: "b", enabled: true, topicCount: 1 },
  44. ]);
  45. expect(projectBoundGroups([state("a")], "bot", undefined)).toEqual([]);
  46. });
  47. it("uses the group switch even when topic records retain old enabled values", () => {
  48. const group = state("a");
  49. group.group!.enabled = false;
  50. expect(projectBoundGroups([group, state("a", "t")], "bot", "owner")[0]).toMatchObject({
  51. enabled: false,
  52. topicCount: 1,
  53. });
  54. });
  55. });