groupInputReaction.test.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { describe, expect, it, vi } from "vitest";
  2. import { createGroupInputReactionUpdater } from "#src/bots/providers/groupInputReaction.js";
  3. describe("group input reactions", () => {
  4. it("serializes transitions and ignores late admission and duplicate completion", async () => {
  5. const apply = vi.fn(async (_key: string, _state: string) => {});
  6. const update = createGroupInputReactionUpdater(apply);
  7. await Promise.all([
  8. update("message-a", "working"),
  9. update("message-a", "waiting"),
  10. update("message-a", "done"),
  11. update("message-a", "working"),
  12. update("message-a", "done"),
  13. ]);
  14. expect(apply.mock.calls).toEqual([
  15. ["message-a", "working"],
  16. ["message-a", "done"],
  17. ]);
  18. });
  19. it("keeps messages independent and removes cancelled status", async () => {
  20. const apply = vi.fn(async (_key: string, _state: string) => {});
  21. const update = createGroupInputReactionUpdater(apply);
  22. await update("a", "waiting");
  23. await update("b", "working");
  24. await update("a", "cancelled");
  25. await update("a", "working");
  26. await update("b", "failed");
  27. expect(apply.mock.calls).toEqual([
  28. ["a", "waiting"],
  29. ["b", "working"],
  30. ["a", "cancelled"],
  31. ["b", "failed"],
  32. ]);
  33. });
  34. it("retries failed presentation without accepting older lifecycle state", async () => {
  35. const apply = vi
  36. .fn(async (_key: string, _state: string) => {})
  37. .mockRejectedValueOnce(new Error("network"));
  38. const update = createGroupInputReactionUpdater(apply);
  39. await expect(update("a", "done")).rejects.toThrow("network");
  40. await update("a", "waiting");
  41. await update("a", "done");
  42. expect(apply.mock.calls).toEqual([
  43. ["a", "done"],
  44. ["a", "done"],
  45. ]);
  46. });
  47. });