botGroupDeliveryThrottle.test.ts 749 B

12345678910111213141516
  1. import { afterEach, expect, it, vi } from "vitest";
  2. import { createGroupDeliveryThrottle } from "../src/bots/groupDeliveryThrottle.js";
  3. afterEach(() => vi.useRealTimers());
  4. it("spaces sends across bots in the same group while leaving other groups independent", async () => {
  5. vi.useFakeTimers();
  6. const wait = createGroupDeliveryThrottle();
  7. const sent: string[] = [];
  8. const first = wait("feishu:oc_a").then(() => sent.push("a1"));
  9. const second = wait("feishu:oc_a").then(() => sent.push("a2"));
  10. const other = wait("feishu:oc_b").then(() => sent.push("b1"));
  11. await Promise.all([first, other]);
  12. expect(sent).toEqual(["a1", "b1"]);
  13. await vi.advanceTimersByTimeAsync(250);
  14. await second;
  15. expect(sent).toEqual(["a1", "b1", "a2"]);
  16. });