mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 21:54:31 +00:00
fix(telegram): clean up update offset on channels remove --delete (#18233)
This commit is contained in:
committed by
Peter Steinberger
parent
b91e43714b
commit
6757a9fedc
@@ -11,6 +11,10 @@ const authMocks = vi.hoisted(() => ({
|
||||
loadAuthProfileStore: vi.fn(),
|
||||
}));
|
||||
|
||||
const offsetMocks = vi.hoisted(() => ({
|
||||
deleteTelegramUpdateOffset: vi.fn().mockResolvedValue(undefined),
|
||||
}));
|
||||
|
||||
vi.mock("../config/config.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../config/config.js")>();
|
||||
return {
|
||||
@@ -28,6 +32,14 @@ vi.mock("../agents/auth-profiles.js", async (importOriginal) => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../telegram/update-offset-store.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../telegram/update-offset-store.js")>();
|
||||
return {
|
||||
...actual,
|
||||
deleteTelegramUpdateOffset: offsetMocks.deleteTelegramUpdateOffset,
|
||||
};
|
||||
});
|
||||
|
||||
import {
|
||||
channelsAddCommand,
|
||||
channelsListCommand,
|
||||
@@ -42,6 +54,7 @@ describe("channels command", () => {
|
||||
configMocks.readConfigFileSnapshot.mockReset();
|
||||
configMocks.writeConfigFile.mockClear();
|
||||
authMocks.loadAuthProfileStore.mockReset();
|
||||
offsetMocks.deleteTelegramUpdateOffset.mockClear();
|
||||
runtime.log.mockClear();
|
||||
runtime.error.mockClear();
|
||||
runtime.exit.mockClear();
|
||||
@@ -456,4 +469,70 @@ describe("channels command", () => {
|
||||
});
|
||||
expect(disconnected.join("\n")).toMatch(/disconnected/i);
|
||||
});
|
||||
|
||||
it("cleans up telegram update offset when deleting a telegram account", async () => {
|
||||
configMocks.readConfigFileSnapshot.mockResolvedValue({
|
||||
...baseConfigSnapshot,
|
||||
config: {
|
||||
channels: {
|
||||
telegram: { botToken: "123:abc", enabled: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await channelsRemoveCommand(
|
||||
{ channel: "telegram", account: "default", delete: true },
|
||||
runtime,
|
||||
{
|
||||
hasFlags: true,
|
||||
},
|
||||
);
|
||||
|
||||
expect(offsetMocks.deleteTelegramUpdateOffset).toHaveBeenCalledWith({ accountId: "default" });
|
||||
});
|
||||
|
||||
it("does not clean up offset when deleting a non-telegram channel", async () => {
|
||||
configMocks.readConfigFileSnapshot.mockResolvedValue({
|
||||
...baseConfigSnapshot,
|
||||
config: {
|
||||
channels: {
|
||||
discord: {
|
||||
accounts: {
|
||||
default: { token: "d0" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await channelsRemoveCommand({ channel: "discord", account: "default", delete: true }, runtime, {
|
||||
hasFlags: true,
|
||||
});
|
||||
|
||||
expect(offsetMocks.deleteTelegramUpdateOffset).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not clean up offset when disabling (not deleting) a telegram account", async () => {
|
||||
configMocks.readConfigFileSnapshot.mockResolvedValue({
|
||||
...baseConfigSnapshot,
|
||||
config: {
|
||||
channels: {
|
||||
telegram: { botToken: "123:abc", enabled: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const prompt = { confirm: vi.fn().mockResolvedValue(true) };
|
||||
const prompterModule = await import("../wizard/clack-prompter.js");
|
||||
const promptSpy = vi
|
||||
.spyOn(prompterModule, "createClackPrompter")
|
||||
.mockReturnValue(prompt as never);
|
||||
|
||||
await channelsRemoveCommand({ channel: "telegram", account: "default" }, runtime, {
|
||||
hasFlags: true,
|
||||
});
|
||||
|
||||
expect(offsetMocks.deleteTelegramUpdateOffset).not.toHaveBeenCalled();
|
||||
promptSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user