Files
Moltbot/src/telegram/update-offset-store.test.ts
2026-02-21 13:02:12 +00:00

38 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { withStateDirEnv } from "../test-helpers/state-dir-env.js";
import {
deleteTelegramUpdateOffset,
readTelegramUpdateOffset,
writeTelegramUpdateOffset,
} from "./update-offset-store.js";
describe("deleteTelegramUpdateOffset", () => {
it("removes the offset file so a new bot starts fresh", async () => {
await withStateDirEnv("openclaw-tg-offset-", async () => {
await writeTelegramUpdateOffset({ accountId: "default", updateId: 432_000_000 });
expect(await readTelegramUpdateOffset({ accountId: "default" })).toBe(432_000_000);
await deleteTelegramUpdateOffset({ accountId: "default" });
expect(await readTelegramUpdateOffset({ accountId: "default" })).toBeNull();
});
});
it("does not throw when the offset file does not exist", async () => {
await withStateDirEnv("openclaw-tg-offset-", async () => {
await expect(deleteTelegramUpdateOffset({ accountId: "nonexistent" })).resolves.not.toThrow();
});
});
it("only removes the targeted account offset, leaving others intact", async () => {
await withStateDirEnv("openclaw-tg-offset-", async () => {
await writeTelegramUpdateOffset({ accountId: "default", updateId: 100 });
await writeTelegramUpdateOffset({ accountId: "alerts", updateId: 200 });
await deleteTelegramUpdateOffset({ accountId: "default" });
expect(await readTelegramUpdateOffset({ accountId: "default" })).toBeNull();
expect(await readTelegramUpdateOffset({ accountId: "alerts" })).toBe(200);
});
});
});