mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-20 06:20:55 +00:00
* refactor: remove channel shim directories, point all imports to extensions
Delete the 6 backward-compat shim directories (src/telegram, src/discord,
src/slack, src/signal, src/imessage, src/web) that were re-exporting from
extensions. Update all 112+ source files to import directly from
extensions/{channel}/src/ instead of through the shims.
Also:
- Move src/channels/telegram/ (allow-from, api) to extensions/telegram/src/
- Fix outbound adapters to use resolveOutboundSendDep (fixes 5 pre-existing TS errors)
- Update cross-extension imports (src/web/media.js → extensions/whatsapp/src/media.js)
- Update vitest, tsdown, knip, labeler, and script configs for new paths
- Update guard test allowlists for extension paths
After this, src/ has zero channel-specific implementation code — only the
generic plugin framework remains.
* fix: update raw-fetch guard allowlist line numbers after shim removal
* refactor: document direct extension channel imports
* test: mock transcript module in delivery helpers
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { fetchTelegramChatId } from "./api-fetch.js";
|
|
|
|
describe("fetchTelegramChatId", () => {
|
|
const cases = [
|
|
{
|
|
name: "returns stringified id when Telegram getChat succeeds",
|
|
fetchImpl: vi.fn(async () => ({
|
|
ok: true,
|
|
json: async () => ({ ok: true, result: { id: 12345 } }),
|
|
})),
|
|
expected: "12345",
|
|
},
|
|
{
|
|
name: "returns null when response is not ok",
|
|
fetchImpl: vi.fn(async () => ({
|
|
ok: false,
|
|
json: async () => ({}),
|
|
})),
|
|
expected: null,
|
|
},
|
|
{
|
|
name: "returns null on transport failures",
|
|
fetchImpl: vi.fn(async () => {
|
|
throw new Error("network failed");
|
|
}),
|
|
expected: null,
|
|
},
|
|
] as const;
|
|
|
|
for (const testCase of cases) {
|
|
it(testCase.name, async () => {
|
|
vi.stubGlobal("fetch", testCase.fetchImpl);
|
|
|
|
const id = await fetchTelegramChatId({
|
|
token: "abc",
|
|
chatId: "@user",
|
|
});
|
|
|
|
expect(id).toBe(testCase.expected);
|
|
});
|
|
}
|
|
|
|
it("calls Telegram getChat endpoint", async () => {
|
|
const fetchMock = vi.fn(async () => ({
|
|
ok: true,
|
|
json: async () => ({ ok: true, result: { id: 12345 } }),
|
|
}));
|
|
vi.stubGlobal("fetch", fetchMock);
|
|
|
|
await fetchTelegramChatId({ token: "abc", chatId: "@user" });
|
|
expect(fetchMock).toHaveBeenCalledWith(
|
|
"https://api.telegram.org/botabc/getChat?chat_id=%40user",
|
|
undefined,
|
|
);
|
|
});
|
|
});
|