mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-26 09:21:55 +00:00
* refactor: move WhatsApp channel from src/web/ to extensions/whatsapp/ Move all WhatsApp implementation code (77 source/test files + 9 channel plugin files) from src/web/ and src/channels/plugins/*/whatsapp* to extensions/whatsapp/src/. - Leave thin re-export shims at all original locations so cross-cutting imports continue to resolve - Update plugin-sdk/whatsapp.ts to only re-export generic framework utilities; channel-specific functions imported locally by the extension - Update vi.mock paths in 15 cross-cutting test files - Rename outbound.ts -> send.ts to match extension naming conventions and avoid false positive in cfg-threading guard test - Widen tsconfig.plugin-sdk.dts.json rootDir to support shim->extension cross-directory references Part of the core-channels-to-extensions migration (PR 6/10). * style: format WhatsApp extension files * fix: correct stale import paths in WhatsApp extension tests Fix vi.importActual, test mock, and hardcoded source paths that weren't updated during the file move: - media.test.ts: vi.importActual path - onboarding.test.ts: vi.importActual path - test-helpers.ts: test/mocks/baileys.js path - monitor-inbox.test-harness.ts: incomplete media/store mock - login.test.ts: hardcoded source file path - message-action-runner.media.test.ts: vi.mock/importActual path
99 lines
2.9 KiB
TypeScript
99 lines
2.9 KiB
TypeScript
import fs from "node:fs";
|
|
import fsPromises from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const runtime = {
|
|
log: vi.fn(),
|
|
error: vi.fn(),
|
|
exit: vi.fn(),
|
|
};
|
|
const WEB_LOGOUT_TEST_TIMEOUT_MS = 15_000;
|
|
|
|
describe("web logout", () => {
|
|
let fixtureRoot = "";
|
|
let caseId = 0;
|
|
let logoutWeb: typeof import("./auth-store.js").logoutWeb;
|
|
|
|
beforeAll(async () => {
|
|
fixtureRoot = await fsPromises.mkdtemp(path.join(os.tmpdir(), "openclaw-test-web-logout-"));
|
|
({ logoutWeb } = await import("./auth-store.js"));
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await fsPromises.rm(fixtureRoot, { recursive: true, force: true });
|
|
});
|
|
|
|
const makeCaseDir = async () => {
|
|
const dir = path.join(fixtureRoot, `case-${caseId++}`);
|
|
await fsPromises.mkdir(dir, { recursive: true });
|
|
return dir;
|
|
};
|
|
|
|
const createAuthCase = async (files: Record<string, string>) => {
|
|
const authDir = await makeCaseDir();
|
|
await Promise.all(
|
|
Object.entries(files).map(async ([name, contents]) => {
|
|
await fsPromises.writeFile(path.join(authDir, name), contents, "utf-8");
|
|
}),
|
|
);
|
|
return authDir;
|
|
};
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it(
|
|
"deletes cached credentials when present",
|
|
{ timeout: WEB_LOGOUT_TEST_TIMEOUT_MS },
|
|
async () => {
|
|
const authDir = await createAuthCase({ "creds.json": "{}" });
|
|
const result = await logoutWeb({ authDir, runtime: runtime as never });
|
|
expect(result).toBe(true);
|
|
expect(fs.existsSync(authDir)).toBe(false);
|
|
},
|
|
);
|
|
|
|
it("removes oauth.json too when not using legacy auth dir", async () => {
|
|
const authDir = await createAuthCase({
|
|
"creds.json": "{}",
|
|
"oauth.json": '{"token":true}',
|
|
"session-abc.json": "{}",
|
|
});
|
|
const result = await logoutWeb({ authDir, runtime: runtime as never });
|
|
expect(result).toBe(true);
|
|
expect(fs.existsSync(authDir)).toBe(false);
|
|
});
|
|
|
|
it("no-ops when nothing to delete", { timeout: WEB_LOGOUT_TEST_TIMEOUT_MS }, async () => {
|
|
const authDir = await makeCaseDir();
|
|
const result = await logoutWeb({ authDir, runtime: runtime as never });
|
|
expect(result).toBe(false);
|
|
expect(runtime.log).toHaveBeenCalled();
|
|
});
|
|
|
|
it("keeps shared oauth.json when using legacy auth dir", async () => {
|
|
const credsDir = await createAuthCase({
|
|
"creds.json": "{}",
|
|
"oauth.json": '{"token":true}',
|
|
"session-abc.json": "{}",
|
|
});
|
|
|
|
const result = await logoutWeb({
|
|
authDir: credsDir,
|
|
isLegacyAuthDir: true,
|
|
runtime: runtime as never,
|
|
});
|
|
expect(result).toBe(true);
|
|
expect(fs.existsSync(path.join(credsDir, "oauth.json"))).toBe(true);
|
|
expect(fs.existsSync(path.join(credsDir, "creds.json"))).toBe(false);
|
|
expect(fs.existsSync(path.join(credsDir, "session-abc.json"))).toBe(false);
|
|
});
|
|
});
|