mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-19 05:50:47 +00:00
* refactor: move Telegram channel implementation to extensions/telegram/src/ Move all Telegram channel code (123 files + 10 bot/ files + 8 channel plugin files) from src/telegram/ and src/channels/plugins/*/telegram.ts to extensions/telegram/src/. Leave thin re-export shims at original locations so cross-cutting src/ imports continue to resolve. - Fix all relative import paths in moved files (../X/ -> ../../../src/X/) - Fix vi.mock paths in 60 test files - Fix inline typeof import() expressions - Update tsconfig.plugin-sdk.dts.json rootDir to "." for cross-directory DTS - Update write-plugin-sdk-entry-dts.ts for new rootDir structure - Move channel plugin files with correct path remapping * fix: support keyed telegram send deps * fix: sync telegram extension copies with latest main * fix: correct import paths and remove misplaced files in telegram extension * fix: sync outbound-adapter with main (add sendTelegramPayloadMessages) and fix delivery.test import path
72 lines
2.2 KiB
TypeScript
72 lines
2.2 KiB
TypeScript
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
let collectTelegramUnmentionedGroupIds: typeof import("./audit.js").collectTelegramUnmentionedGroupIds;
|
|
let auditTelegramGroupMembership: typeof import("./audit.js").auditTelegramGroupMembership;
|
|
const undiciFetch = vi.hoisted(() => vi.fn());
|
|
|
|
vi.mock("undici", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("undici")>();
|
|
return {
|
|
...actual,
|
|
fetch: undiciFetch,
|
|
};
|
|
});
|
|
|
|
function mockGetChatMemberStatus(status: string) {
|
|
undiciFetch.mockResolvedValueOnce(
|
|
new Response(JSON.stringify({ ok: true, result: { status } }), {
|
|
status: 200,
|
|
headers: { "Content-Type": "application/json" },
|
|
}),
|
|
);
|
|
}
|
|
|
|
async function auditSingleGroup() {
|
|
return auditTelegramGroupMembership({
|
|
token: "t",
|
|
botId: 123,
|
|
groupIds: ["-1001"],
|
|
timeoutMs: 5000,
|
|
});
|
|
}
|
|
|
|
describe("telegram audit", () => {
|
|
beforeAll(async () => {
|
|
({ collectTelegramUnmentionedGroupIds, auditTelegramGroupMembership } =
|
|
await import("./audit.js"));
|
|
});
|
|
|
|
beforeEach(() => {
|
|
undiciFetch.mockReset();
|
|
});
|
|
|
|
it("collects unmentioned numeric group ids and flags wildcard", async () => {
|
|
const res = collectTelegramUnmentionedGroupIds({
|
|
"*": { requireMention: false },
|
|
"-1001": { requireMention: false },
|
|
"@group": { requireMention: false },
|
|
"-1002": { requireMention: true },
|
|
"-1003": { requireMention: false, enabled: false },
|
|
});
|
|
expect(res.hasWildcardUnmentionedGroups).toBe(true);
|
|
expect(res.groupIds).toEqual(["-1001"]);
|
|
expect(res.unresolvedGroups).toBe(1);
|
|
});
|
|
|
|
it("audits membership via getChatMember", async () => {
|
|
mockGetChatMemberStatus("member");
|
|
const res = await auditSingleGroup();
|
|
expect(res.ok).toBe(true);
|
|
expect(res.groups[0]?.chatId).toBe("-1001");
|
|
expect(res.groups[0]?.status).toBe("member");
|
|
});
|
|
|
|
it("reports bot not in group when status is left", async () => {
|
|
mockGetChatMemberStatus("left");
|
|
const res = await auditSingleGroup();
|
|
expect(res.ok).toBe(false);
|
|
expect(res.groups[0]?.ok).toBe(false);
|
|
expect(res.groups[0]?.status).toBe("left");
|
|
});
|
|
});
|