botAdminAttention.test.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. import { describe, expect, it } from "vitest";
  2. import { createGroupAdminAttention } from "../src/bots/groupAdminAttention.js";
  3. import type { BotActor } from "@zcode/shared";
  4. const actor: BotActor = {
  5. botId: "bot",
  6. provider: "feishu",
  7. providerUserId: "member",
  8. chatType: "group",
  9. chatId: "oc_group",
  10. threadId: "topic",
  11. };
  12. describe("group administrator attention", () => {
  13. it("deduplicates a blocker and allows a new reminder after recovery", () => {
  14. const notices = createGroupAdminAttention();
  15. expect(notices.mention(actor, "ou_owner", "model")).toEqual(["ou_owner"]);
  16. expect(notices.mention({ ...actor, providerUserId: "other" }, "ou_owner", "model")).toEqual([]);
  17. notices.clear(actor, "ou_owner", "model");
  18. expect(notices.mention(actor, "ou_owner", "model")).toEqual(["ou_owner"]);
  19. });
  20. it("isolates topics, owners and approval requests and skips private chats", () => {
  21. const notices = createGroupAdminAttention();
  22. for (const [target, owner, reason] of [
  23. [actor, "ou_owner", "approval:1"],
  24. [actor, "ou_owner", "approval:2"],
  25. [{ ...actor, threadId: "other" }, "ou_owner", "approval:1"],
  26. [actor, "ou_new", "approval:1"],
  27. ] as const) {
  28. expect(notices.mention(target, owner, reason)).toEqual([owner]);
  29. }
  30. expect(notices.mention({ ...actor, chatType: "private" }, "ou_owner", "model")).toBeUndefined();
  31. expect(notices.mention(actor, undefined, "model")).toBeUndefined();
  32. });
  33. });