mirror of https://github.com/openclaw/openclaw.git
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import {
|
|
createDiscordTypingLease,
|
|
type CreateDiscordTypingLeaseParams,
|
|
} from "./runtime-discord-typing.js";
|
|
|
|
describe("createDiscordTypingLease", () => {
|
|
afterEach(() => {
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
it("uses the Discord default interval and forwards pulse params", async () => {
|
|
vi.useFakeTimers();
|
|
const pulse: CreateDiscordTypingLeaseParams["pulse"] = vi.fn(async () => undefined);
|
|
const cfg = { channels: { discord: { token: "x" } } };
|
|
|
|
const lease = await createDiscordTypingLease({
|
|
channelId: "123",
|
|
accountId: "work",
|
|
cfg,
|
|
intervalMs: Number.NaN,
|
|
pulse,
|
|
});
|
|
|
|
expect(pulse).toHaveBeenCalledTimes(1);
|
|
expect(pulse).toHaveBeenCalledWith({
|
|
channelId: "123",
|
|
accountId: "work",
|
|
cfg,
|
|
});
|
|
|
|
await vi.advanceTimersByTimeAsync(7_999);
|
|
expect(pulse).toHaveBeenCalledTimes(1);
|
|
await vi.advanceTimersByTimeAsync(1);
|
|
expect(pulse).toHaveBeenCalledTimes(2);
|
|
|
|
lease.stop();
|
|
});
|
|
});
|