Files
openclaw-zero-token/channels/channels-misc.test.ts
sjhu 571e14a236 feat: upgrade to upstream v2026.3.28
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
2026-03-30 17:58:12 +08:00

70 lines
2.7 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "vitest";
import { normalizeChatType } from "./chat-type.js";
describe("normalizeChatType", () => {
it.each([
{ name: "normalizes direct", value: "direct", expected: "direct" },
{ name: "normalizes dm alias", value: "dm", expected: "direct" },
{ name: "normalizes group", value: "group", expected: "group" },
{ name: "normalizes channel", value: "channel", expected: "channel" },
{ name: "returns undefined for undefined", value: undefined, expected: undefined },
{ name: "returns undefined for empty", value: "", expected: undefined },
{ name: "returns undefined for unknown value", value: "nope", expected: undefined },
{ name: "returns undefined for unsupported room", value: "room", expected: undefined },
] satisfies Array<{ name: string; value: string | undefined; expected: string | undefined }>)(
"$name",
({ value, expected }) => {
expect(normalizeChatType(value)).toBe(expected);
},
);
describe("backward compatibility", () => {
it("accepts legacy 'dm' value shape variants and normalizes to 'direct'", () => {
// Legacy config/input may use "dm" with non-canonical casing/spacing.
expect(normalizeChatType("DM")).toBe("direct");
expect(normalizeChatType(" dm ")).toBe("direct");
});
});
});
describe("WA_WEB_AUTH_DIR", () => {
afterEach(() => {
vi.doUnmock("../plugins/runtime/runtime-whatsapp-boundary.js");
vi.resetModules();
});
it("resolves lazily and caches across the legacy and channels/web entrypoints", async () => {
const resolveWaWebAuthDir = vi.fn(() => "/tmp/openclaw-whatsapp-auth");
vi.resetModules();
vi.doMock("../plugins/runtime/runtime-whatsapp-boundary.js", () => ({
createWaSocket: vi.fn(),
extractMediaPlaceholder: vi.fn(),
extractText: vi.fn(),
formatError: vi.fn(),
getStatusCode: vi.fn(),
logWebSelfId: vi.fn(),
loginWeb: vi.fn(),
logoutWeb: vi.fn(),
monitorWebChannel: vi.fn(),
monitorWebInbox: vi.fn(),
pickWebChannel: vi.fn(),
resolveHeartbeatRecipients: vi.fn(),
resolveWaWebAuthDir,
runWebHeartbeatOnce: vi.fn(),
sendMessageWhatsApp: vi.fn(),
sendReactionWhatsApp: vi.fn(),
waitForWaConnection: vi.fn(),
webAuthExists: vi.fn(),
}));
const channelWeb = await import("../channel-web.js");
const webEntry = await import("./web/index.js");
expect(resolveWaWebAuthDir).not.toHaveBeenCalled();
expect(String(channelWeb.WA_WEB_AUTH_DIR)).toBe("/tmp/openclaw-whatsapp-auth");
expect(String(webEntry.WA_WEB_AUTH_DIR)).toBe("/tmp/openclaw-whatsapp-auth");
expect(resolveWaWebAuthDir).toHaveBeenCalledTimes(1);
});
});