mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 07:20:22 +00:00
test: collapse telegram and whatsapp target suites
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { isNumericTelegramUserId, normalizeTelegramAllowFromEntry } from "./allow-from.js";
|
||||
|
||||
describe("telegram allow-from helpers", () => {
|
||||
it("normalizes tg/telegram prefixes", () => {
|
||||
const cases = [
|
||||
{ value: " TG:123 ", expected: "123" },
|
||||
{ value: "telegram:@someone", expected: "@someone" },
|
||||
] as const;
|
||||
for (const testCase of cases) {
|
||||
expect(normalizeTelegramAllowFromEntry(testCase.value)).toBe(testCase.expected);
|
||||
}
|
||||
});
|
||||
|
||||
it("accepts signed numeric IDs", () => {
|
||||
const cases = [
|
||||
{ value: "123456789", expected: true },
|
||||
{ value: "-1001234567890", expected: true },
|
||||
{ value: "@someone", expected: false },
|
||||
{ value: "12 34", expected: false },
|
||||
] as const;
|
||||
for (const testCase of cases) {
|
||||
expect(isNumericTelegramUserId(testCase.value)).toBe(testCase.expected);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,23 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { looksLikeTelegramTargetId, normalizeTelegramMessagingTarget } from "./normalize.js";
|
||||
|
||||
describe("telegram target normalization", () => {
|
||||
it("normalizes telegram prefixes, group targets, and topic suffixes", () => {
|
||||
expect(normalizeTelegramMessagingTarget("telegram:123456")).toBe("telegram:123456");
|
||||
expect(normalizeTelegramMessagingTarget("tg:group:-100123")).toBe("telegram:group:-100123");
|
||||
expect(normalizeTelegramMessagingTarget("telegram:-100123:topic:99")).toBe(
|
||||
"telegram:-100123:topic:99",
|
||||
);
|
||||
});
|
||||
|
||||
it("returns undefined for invalid telegram recipients", () => {
|
||||
expect(normalizeTelegramMessagingTarget("telegram:")).toBeUndefined();
|
||||
expect(normalizeTelegramMessagingTarget(" ")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("detects valid telegram target identifiers", () => {
|
||||
expect(looksLikeTelegramTargetId("telegram:123456")).toBe(true);
|
||||
expect(looksLikeTelegramTargetId("tg:group:-100123")).toBe(true);
|
||||
expect(looksLikeTelegramTargetId("hello world")).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,46 +0,0 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { resolveTelegramAllowFromEntries } from "./setup-core.js";
|
||||
|
||||
describe("resolveTelegramAllowFromEntries", () => {
|
||||
it("passes apiRoot through username lookups", async () => {
|
||||
const globalFetch = vi.fn(async () => {
|
||||
throw new Error("global fetch should not be called");
|
||||
});
|
||||
const fetchMock = vi.fn(async () => ({
|
||||
ok: true,
|
||||
json: async () => ({ ok: true, result: { id: 12345 } }),
|
||||
}));
|
||||
vi.stubGlobal("fetch", globalFetch);
|
||||
const proxyFetch = vi.fn();
|
||||
const fetchModule = await import("./fetch.js");
|
||||
const proxyModule = await import("./proxy.js");
|
||||
const resolveTelegramFetch = vi.spyOn(fetchModule, "resolveTelegramFetch");
|
||||
const makeProxyFetch = vi.spyOn(proxyModule, "makeProxyFetch");
|
||||
makeProxyFetch.mockReturnValue(proxyFetch as unknown as typeof fetch);
|
||||
resolveTelegramFetch.mockReturnValue(fetchMock as unknown as typeof fetch);
|
||||
|
||||
try {
|
||||
const resolved = await resolveTelegramAllowFromEntries({
|
||||
entries: ["@user"],
|
||||
credentialValue: "tok",
|
||||
apiRoot: "https://custom.telegram.test/root/",
|
||||
proxyUrl: "http://127.0.0.1:8080",
|
||||
network: { autoSelectFamily: false, dnsResultOrder: "ipv4first" },
|
||||
});
|
||||
|
||||
expect(resolved).toEqual([{ input: "@user", resolved: true, id: "12345" }]);
|
||||
expect(makeProxyFetch).toHaveBeenCalledWith("http://127.0.0.1:8080");
|
||||
expect(resolveTelegramFetch).toHaveBeenCalledWith(proxyFetch, {
|
||||
network: { autoSelectFamily: false, dnsResultOrder: "ipv4first" },
|
||||
});
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
"https://custom.telegram.test/root/bottok/getChat?chat_id=%40user",
|
||||
undefined,
|
||||
);
|
||||
} finally {
|
||||
makeProxyFetch.mockRestore();
|
||||
resolveTelegramFetch.mockRestore();
|
||||
vi.unstubAllGlobals();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
runSetupWizardFinalize,
|
||||
runSetupWizardPrepare,
|
||||
} from "../../../test/helpers/extensions/setup-wizard.js";
|
||||
import { resolveTelegramAllowFromEntries } from "./setup-core.js";
|
||||
import { telegramSetupWizard } from "./setup-surface.js";
|
||||
|
||||
async function runPrepare(cfg: OpenClawConfig, accountId: string) {
|
||||
@@ -160,3 +161,47 @@ describe("telegramSetupWizard.finalize", () => {
|
||||
expect(note).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveTelegramAllowFromEntries", () => {
|
||||
it("passes apiRoot through username lookups", async () => {
|
||||
const globalFetch = vi.fn(async () => {
|
||||
throw new Error("global fetch should not be called");
|
||||
});
|
||||
const fetchMock = vi.fn(async () => ({
|
||||
ok: true,
|
||||
json: async () => ({ ok: true, result: { id: 12345 } }),
|
||||
}));
|
||||
vi.stubGlobal("fetch", globalFetch);
|
||||
const proxyFetch = vi.fn();
|
||||
const fetchModule = await import("./fetch.js");
|
||||
const proxyModule = await import("./proxy.js");
|
||||
const resolveTelegramFetch = vi.spyOn(fetchModule, "resolveTelegramFetch");
|
||||
const makeProxyFetch = vi.spyOn(proxyModule, "makeProxyFetch");
|
||||
makeProxyFetch.mockReturnValue(proxyFetch as unknown as typeof fetch);
|
||||
resolveTelegramFetch.mockReturnValue(fetchMock as unknown as typeof fetch);
|
||||
|
||||
try {
|
||||
const resolved = await resolveTelegramAllowFromEntries({
|
||||
entries: ["@user"],
|
||||
credentialValue: "tok",
|
||||
apiRoot: "https://custom.telegram.test/root/",
|
||||
proxyUrl: "http://127.0.0.1:8080",
|
||||
network: { autoSelectFamily: false, dnsResultOrder: "ipv4first" },
|
||||
});
|
||||
|
||||
expect(resolved).toEqual([{ input: "@user", resolved: true, id: "12345" }]);
|
||||
expect(makeProxyFetch).toHaveBeenCalledWith("http://127.0.0.1:8080");
|
||||
expect(resolveTelegramFetch).toHaveBeenCalledWith(proxyFetch, {
|
||||
network: { autoSelectFamily: false, dnsResultOrder: "ipv4first" },
|
||||
});
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
"https://custom.telegram.test/root/bottok/getChat?chat_id=%40user",
|
||||
undefined,
|
||||
);
|
||||
} finally {
|
||||
makeProxyFetch.mockRestore();
|
||||
resolveTelegramFetch.mockRestore();
|
||||
vi.unstubAllGlobals();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,183 +0,0 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../../../src/config/config.js";
|
||||
|
||||
const readConfigFileSnapshotForWrite = vi.fn();
|
||||
const writeConfigFile = vi.fn();
|
||||
const loadCronStore = vi.fn();
|
||||
const resolveCronStorePath = vi.fn();
|
||||
const saveCronStore = vi.fn();
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/config-runtime", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/config-runtime")>();
|
||||
return {
|
||||
...actual,
|
||||
readConfigFileSnapshotForWrite,
|
||||
writeConfigFile,
|
||||
loadCronStore,
|
||||
resolveCronStorePath,
|
||||
saveCronStore,
|
||||
};
|
||||
});
|
||||
|
||||
describe("maybePersistResolvedTelegramTarget", () => {
|
||||
let maybePersistResolvedTelegramTarget: typeof import("./target-writeback.js").maybePersistResolvedTelegramTarget;
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
({ maybePersistResolvedTelegramTarget } = await import("./target-writeback.js"));
|
||||
readConfigFileSnapshotForWrite.mockReset();
|
||||
writeConfigFile.mockReset();
|
||||
loadCronStore.mockReset();
|
||||
resolveCronStorePath.mockReset();
|
||||
saveCronStore.mockReset();
|
||||
resolveCronStorePath.mockReturnValue("/tmp/cron/jobs.json");
|
||||
});
|
||||
|
||||
it("skips writeback when target is already numeric", async () => {
|
||||
await maybePersistResolvedTelegramTarget({
|
||||
cfg: {} as OpenClawConfig,
|
||||
rawTarget: "-100123",
|
||||
resolvedChatId: "-100123",
|
||||
});
|
||||
|
||||
expect(readConfigFileSnapshotForWrite).not.toHaveBeenCalled();
|
||||
expect(loadCronStore).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("writes back matching config and cron targets", async () => {
|
||||
readConfigFileSnapshotForWrite.mockResolvedValue({
|
||||
snapshot: {
|
||||
config: {
|
||||
channels: {
|
||||
telegram: {
|
||||
defaultTo: "t.me/mychannel",
|
||||
accounts: {
|
||||
alerts: {
|
||||
defaultTo: "@mychannel",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
writeOptions: { expectedConfigPath: "/tmp/openclaw.json" },
|
||||
});
|
||||
loadCronStore.mockResolvedValue({
|
||||
version: 1,
|
||||
jobs: [
|
||||
{ id: "a", delivery: { channel: "telegram", to: "https://t.me/mychannel" } },
|
||||
{ id: "b", delivery: { channel: "slack", to: "C123" } },
|
||||
],
|
||||
});
|
||||
|
||||
await maybePersistResolvedTelegramTarget({
|
||||
cfg: {
|
||||
cron: { store: "/tmp/cron/jobs.json" },
|
||||
} as OpenClawConfig,
|
||||
rawTarget: "t.me/mychannel",
|
||||
resolvedChatId: "-100123",
|
||||
});
|
||||
|
||||
expect(writeConfigFile).toHaveBeenCalledTimes(1);
|
||||
expect(writeConfigFile).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
channels: {
|
||||
telegram: {
|
||||
defaultTo: "-100123",
|
||||
accounts: {
|
||||
alerts: {
|
||||
defaultTo: "-100123",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
expect.objectContaining({ expectedConfigPath: "/tmp/openclaw.json" }),
|
||||
);
|
||||
expect(saveCronStore).toHaveBeenCalledTimes(1);
|
||||
expect(saveCronStore).toHaveBeenCalledWith(
|
||||
"/tmp/cron/jobs.json",
|
||||
expect.objectContaining({
|
||||
jobs: [
|
||||
{ id: "a", delivery: { channel: "telegram", to: "-100123" } },
|
||||
{ id: "b", delivery: { channel: "slack", to: "C123" } },
|
||||
],
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("preserves topic suffix style in writeback target", async () => {
|
||||
readConfigFileSnapshotForWrite.mockResolvedValue({
|
||||
snapshot: {
|
||||
config: {
|
||||
channels: {
|
||||
telegram: {
|
||||
defaultTo: "t.me/mychannel:topic:9",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
writeOptions: {},
|
||||
});
|
||||
loadCronStore.mockResolvedValue({ version: 1, jobs: [] });
|
||||
|
||||
await maybePersistResolvedTelegramTarget({
|
||||
cfg: {} as OpenClawConfig,
|
||||
rawTarget: "t.me/mychannel:topic:9",
|
||||
resolvedChatId: "-100123",
|
||||
});
|
||||
|
||||
expect(writeConfigFile).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
channels: {
|
||||
telegram: {
|
||||
defaultTo: "-100123:topic:9",
|
||||
},
|
||||
},
|
||||
}),
|
||||
expect.any(Object),
|
||||
);
|
||||
});
|
||||
|
||||
it("matches username targets case-insensitively", async () => {
|
||||
readConfigFileSnapshotForWrite.mockResolvedValue({
|
||||
snapshot: {
|
||||
config: {
|
||||
channels: {
|
||||
telegram: {
|
||||
defaultTo: "https://t.me/mychannel",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
writeOptions: {},
|
||||
});
|
||||
loadCronStore.mockResolvedValue({
|
||||
version: 1,
|
||||
jobs: [{ id: "a", delivery: { channel: "telegram", to: "https://t.me/mychannel" } }],
|
||||
});
|
||||
|
||||
await maybePersistResolvedTelegramTarget({
|
||||
cfg: {} as OpenClawConfig,
|
||||
rawTarget: "@MyChannel",
|
||||
resolvedChatId: "-100123",
|
||||
});
|
||||
|
||||
expect(writeConfigFile).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
channels: {
|
||||
telegram: {
|
||||
defaultTo: "-100123",
|
||||
},
|
||||
},
|
||||
}),
|
||||
expect.any(Object),
|
||||
);
|
||||
expect(saveCronStore).toHaveBeenCalledWith(
|
||||
"/tmp/cron/jobs.json",
|
||||
expect.objectContaining({
|
||||
jobs: [{ id: "a", delivery: { channel: "telegram", to: "-100123" } }],
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,8 +1,11 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../../../src/config/config.js";
|
||||
import { isNumericTelegramUserId, normalizeTelegramAllowFromEntry } from "./allow-from.js";
|
||||
import {
|
||||
resolveTelegramGroupRequireMention,
|
||||
resolveTelegramGroupToolPolicy,
|
||||
} from "./group-policy.js";
|
||||
import { looksLikeTelegramTargetId, normalizeTelegramMessagingTarget } from "./normalize.js";
|
||||
import {
|
||||
isNumericTelegramChatId,
|
||||
normalizeTelegramChatId,
|
||||
@@ -11,6 +14,24 @@ import {
|
||||
stripTelegramInternalPrefixes,
|
||||
} from "./targets.js";
|
||||
|
||||
const readConfigFileSnapshotForWrite = vi.fn();
|
||||
const writeConfigFile = vi.fn();
|
||||
const loadCronStore = vi.fn();
|
||||
const resolveCronStorePath = vi.fn();
|
||||
const saveCronStore = vi.fn();
|
||||
|
||||
vi.mock("openclaw/plugin-sdk/config-runtime", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/config-runtime")>();
|
||||
return {
|
||||
...actual,
|
||||
readConfigFileSnapshotForWrite,
|
||||
writeConfigFile,
|
||||
loadCronStore,
|
||||
resolveCronStorePath,
|
||||
saveCronStore,
|
||||
};
|
||||
});
|
||||
|
||||
describe("stripTelegramInternalPrefixes", () => {
|
||||
it("strips telegram prefix", () => {
|
||||
expect(stripTelegramInternalPrefixes("telegram:123")).toBe("123");
|
||||
@@ -168,3 +189,211 @@ describe("telegram group policy", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("telegram allow-from helpers", () => {
|
||||
it("normalizes tg/telegram prefixes", () => {
|
||||
const cases = [
|
||||
{ value: " TG:123 ", expected: "123" },
|
||||
{ value: "telegram:@someone", expected: "@someone" },
|
||||
] as const;
|
||||
for (const testCase of cases) {
|
||||
expect(normalizeTelegramAllowFromEntry(testCase.value)).toBe(testCase.expected);
|
||||
}
|
||||
});
|
||||
|
||||
it("accepts signed numeric IDs", () => {
|
||||
const cases = [
|
||||
{ value: "123456789", expected: true },
|
||||
{ value: "-1001234567890", expected: true },
|
||||
{ value: "@someone", expected: false },
|
||||
{ value: "12 34", expected: false },
|
||||
] as const;
|
||||
for (const testCase of cases) {
|
||||
expect(isNumericTelegramUserId(testCase.value)).toBe(testCase.expected);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("telegram target normalization", () => {
|
||||
it("normalizes telegram prefixes, group targets, and topic suffixes", () => {
|
||||
expect(normalizeTelegramMessagingTarget("telegram:123456")).toBe("telegram:123456");
|
||||
expect(normalizeTelegramMessagingTarget("tg:group:-100123")).toBe("telegram:group:-100123");
|
||||
expect(normalizeTelegramMessagingTarget("telegram:-100123:topic:99")).toBe(
|
||||
"telegram:-100123:topic:99",
|
||||
);
|
||||
});
|
||||
|
||||
it("returns undefined for invalid telegram recipients", () => {
|
||||
expect(normalizeTelegramMessagingTarget("telegram:")).toBeUndefined();
|
||||
expect(normalizeTelegramMessagingTarget(" ")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("detects valid telegram target identifiers", () => {
|
||||
expect(looksLikeTelegramTargetId("telegram:123456")).toBe(true);
|
||||
expect(looksLikeTelegramTargetId("tg:group:-100123")).toBe(true);
|
||||
expect(looksLikeTelegramTargetId("hello world")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("maybePersistResolvedTelegramTarget", () => {
|
||||
let maybePersistResolvedTelegramTarget: typeof import("./target-writeback.js").maybePersistResolvedTelegramTarget;
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
({ maybePersistResolvedTelegramTarget } = await import("./target-writeback.js"));
|
||||
readConfigFileSnapshotForWrite.mockReset();
|
||||
writeConfigFile.mockReset();
|
||||
loadCronStore.mockReset();
|
||||
resolveCronStorePath.mockReset();
|
||||
saveCronStore.mockReset();
|
||||
resolveCronStorePath.mockReturnValue("/tmp/cron/jobs.json");
|
||||
});
|
||||
|
||||
it("skips writeback when target is already numeric", async () => {
|
||||
await maybePersistResolvedTelegramTarget({
|
||||
cfg: {} as OpenClawConfig,
|
||||
rawTarget: "-100123",
|
||||
resolvedChatId: "-100123",
|
||||
});
|
||||
|
||||
expect(readConfigFileSnapshotForWrite).not.toHaveBeenCalled();
|
||||
expect(loadCronStore).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("writes back matching config and cron targets", async () => {
|
||||
readConfigFileSnapshotForWrite.mockResolvedValue({
|
||||
snapshot: {
|
||||
config: {
|
||||
channels: {
|
||||
telegram: {
|
||||
defaultTo: "t.me/mychannel",
|
||||
accounts: {
|
||||
alerts: {
|
||||
defaultTo: "@mychannel",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
writeOptions: { expectedConfigPath: "/tmp/openclaw.json" },
|
||||
});
|
||||
loadCronStore.mockResolvedValue({
|
||||
version: 1,
|
||||
jobs: [
|
||||
{ id: "a", delivery: { channel: "telegram", to: "https://t.me/mychannel" } },
|
||||
{ id: "b", delivery: { channel: "slack", to: "C123" } },
|
||||
],
|
||||
});
|
||||
|
||||
await maybePersistResolvedTelegramTarget({
|
||||
cfg: {
|
||||
cron: { store: "/tmp/cron/jobs.json" },
|
||||
} as OpenClawConfig,
|
||||
rawTarget: "t.me/mychannel",
|
||||
resolvedChatId: "-100123",
|
||||
});
|
||||
|
||||
expect(writeConfigFile).toHaveBeenCalledTimes(1);
|
||||
expect(writeConfigFile).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
channels: {
|
||||
telegram: {
|
||||
defaultTo: "-100123",
|
||||
accounts: {
|
||||
alerts: {
|
||||
defaultTo: "-100123",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
expect.objectContaining({ expectedConfigPath: "/tmp/openclaw.json" }),
|
||||
);
|
||||
expect(saveCronStore).toHaveBeenCalledTimes(1);
|
||||
expect(saveCronStore).toHaveBeenCalledWith(
|
||||
"/tmp/cron/jobs.json",
|
||||
expect.objectContaining({
|
||||
jobs: [
|
||||
{ id: "a", delivery: { channel: "telegram", to: "-100123" } },
|
||||
{ id: "b", delivery: { channel: "slack", to: "C123" } },
|
||||
],
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("preserves topic suffix style in writeback target", async () => {
|
||||
readConfigFileSnapshotForWrite.mockResolvedValue({
|
||||
snapshot: {
|
||||
config: {
|
||||
channels: {
|
||||
telegram: {
|
||||
defaultTo: "t.me/mychannel:topic:9",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
writeOptions: {},
|
||||
});
|
||||
loadCronStore.mockResolvedValue({ version: 1, jobs: [] });
|
||||
|
||||
await maybePersistResolvedTelegramTarget({
|
||||
cfg: {} as OpenClawConfig,
|
||||
rawTarget: "t.me/mychannel:topic:9",
|
||||
resolvedChatId: "-100123",
|
||||
});
|
||||
|
||||
expect(writeConfigFile).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
channels: {
|
||||
telegram: {
|
||||
defaultTo: "-100123:topic:9",
|
||||
},
|
||||
},
|
||||
}),
|
||||
expect.any(Object),
|
||||
);
|
||||
});
|
||||
|
||||
it("matches username targets case-insensitively", async () => {
|
||||
readConfigFileSnapshotForWrite.mockResolvedValue({
|
||||
snapshot: {
|
||||
config: {
|
||||
channels: {
|
||||
telegram: {
|
||||
defaultTo: "https://t.me/mychannel",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
writeOptions: {},
|
||||
});
|
||||
loadCronStore.mockResolvedValue({
|
||||
version: 1,
|
||||
jobs: [{ id: "a", delivery: { channel: "telegram", to: "https://t.me/mychannel" } }],
|
||||
});
|
||||
|
||||
await maybePersistResolvedTelegramTarget({
|
||||
cfg: {} as OpenClawConfig,
|
||||
rawTarget: "@MyChannel",
|
||||
resolvedChatId: "-100123",
|
||||
});
|
||||
|
||||
expect(writeConfigFile).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
channels: {
|
||||
telegram: {
|
||||
defaultTo: "-100123",
|
||||
},
|
||||
},
|
||||
}),
|
||||
expect.any(Object),
|
||||
);
|
||||
expect(saveCronStore).toHaveBeenCalledWith(
|
||||
"/tmp/cron/jobs.json",
|
||||
expect.objectContaining({
|
||||
jobs: [{ id: "a", delivery: { channel: "telegram", to: "-100123" } }],
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user