mirror of https://github.com/openclaw/openclaw.git
refactor: share telegram channel test harnesses
This commit is contained in:
parent
3ffb9f19cb
commit
9ecd1898d0
|
|
@ -91,6 +91,30 @@ function installGatewayRuntime(params?: { probeOk?: boolean; botUsername?: strin
|
|||
};
|
||||
}
|
||||
|
||||
function configureOpsProxyNetwork(cfg: OpenClawConfig) {
|
||||
cfg.channels!.telegram!.accounts!.ops = {
|
||||
...cfg.channels!.telegram!.accounts!.ops,
|
||||
proxy: "http://127.0.0.1:8888",
|
||||
network: {
|
||||
autoSelectFamily: false,
|
||||
dnsResultOrder: "ipv4first",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function installSendMessageRuntime(
|
||||
sendMessageTelegram: ReturnType<typeof vi.fn>,
|
||||
): ReturnType<typeof vi.fn> {
|
||||
setTelegramRuntime({
|
||||
channel: {
|
||||
telegram: {
|
||||
sendMessageTelegram,
|
||||
},
|
||||
},
|
||||
} as unknown as PluginRuntime);
|
||||
return sendMessageTelegram;
|
||||
}
|
||||
|
||||
describe("telegramPlugin duplicate token guard", () => {
|
||||
it("marks secondary account as not configured when token is shared", async () => {
|
||||
const cfg = createCfg();
|
||||
|
|
@ -176,14 +200,7 @@ describe("telegramPlugin duplicate token guard", () => {
|
|||
});
|
||||
|
||||
const cfg = createCfg();
|
||||
cfg.channels!.telegram!.accounts!.ops = {
|
||||
...cfg.channels!.telegram!.accounts!.ops,
|
||||
proxy: "http://127.0.0.1:8888",
|
||||
network: {
|
||||
autoSelectFamily: false,
|
||||
dnsResultOrder: "ipv4first",
|
||||
},
|
||||
};
|
||||
configureOpsProxyNetwork(cfg);
|
||||
const account = telegramPlugin.config.resolveAccount(cfg, "ops");
|
||||
|
||||
await telegramPlugin.status!.probeAccount!({
|
||||
|
|
@ -215,13 +232,9 @@ describe("telegramPlugin duplicate token guard", () => {
|
|||
});
|
||||
|
||||
const cfg = createCfg();
|
||||
configureOpsProxyNetwork(cfg);
|
||||
cfg.channels!.telegram!.accounts!.ops = {
|
||||
...cfg.channels!.telegram!.accounts!.ops,
|
||||
proxy: "http://127.0.0.1:8888",
|
||||
network: {
|
||||
autoSelectFamily: false,
|
||||
dnsResultOrder: "ipv4first",
|
||||
},
|
||||
groups: {
|
||||
"-100123": { requireMention: false },
|
||||
},
|
||||
|
|
@ -249,14 +262,9 @@ describe("telegramPlugin duplicate token guard", () => {
|
|||
});
|
||||
|
||||
it("forwards mediaLocalRoots to sendMessageTelegram for outbound media sends", async () => {
|
||||
const sendMessageTelegram = vi.fn(async () => ({ messageId: "tg-1" }));
|
||||
setTelegramRuntime({
|
||||
channel: {
|
||||
telegram: {
|
||||
sendMessageTelegram,
|
||||
},
|
||||
},
|
||||
} as unknown as PluginRuntime);
|
||||
const sendMessageTelegram = installSendMessageRuntime(
|
||||
vi.fn(async () => ({ messageId: "tg-1" })),
|
||||
);
|
||||
|
||||
const result = await telegramPlugin.outbound!.sendMedia!({
|
||||
cfg: createCfg(),
|
||||
|
|
@ -279,14 +287,9 @@ describe("telegramPlugin duplicate token guard", () => {
|
|||
});
|
||||
|
||||
it("preserves buttons for outbound text payload sends", async () => {
|
||||
const sendMessageTelegram = vi.fn(async () => ({ messageId: "tg-2" }));
|
||||
setTelegramRuntime({
|
||||
channel: {
|
||||
telegram: {
|
||||
sendMessageTelegram,
|
||||
},
|
||||
},
|
||||
} as unknown as PluginRuntime);
|
||||
const sendMessageTelegram = installSendMessageRuntime(
|
||||
vi.fn(async () => ({ messageId: "tg-2" })),
|
||||
);
|
||||
|
||||
const result = await telegramPlugin.outbound!.sendPayload!({
|
||||
cfg: createCfg(),
|
||||
|
|
@ -314,17 +317,12 @@ describe("telegramPlugin duplicate token guard", () => {
|
|||
});
|
||||
|
||||
it("sends outbound payload media lists and keeps buttons on the first message only", async () => {
|
||||
const sendMessageTelegram = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce({ messageId: "tg-3", chatId: "12345" })
|
||||
.mockResolvedValueOnce({ messageId: "tg-4", chatId: "12345" });
|
||||
setTelegramRuntime({
|
||||
channel: {
|
||||
telegram: {
|
||||
sendMessageTelegram,
|
||||
},
|
||||
},
|
||||
} as unknown as PluginRuntime);
|
||||
const sendMessageTelegram = installSendMessageRuntime(
|
||||
vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce({ messageId: "tg-3", chatId: "12345" })
|
||||
.mockResolvedValueOnce({ messageId: "tg-4", chatId: "12345" }),
|
||||
);
|
||||
|
||||
const result = await telegramPlugin.outbound!.sendPayload!({
|
||||
cfg: createCfg(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue