mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-07 18:12:51 +00:00
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
|
|
import { describe, expect, it } from "vitest";
|
|
import {
|
|
listWhatsAppDirectoryGroupsFromConfig,
|
|
listWhatsAppDirectoryPeersFromConfig,
|
|
} from "../directory-contract-api.js";
|
|
|
|
function ids(entries: Array<{ id: string }>) {
|
|
return entries.map((entry) => entry.id);
|
|
}
|
|
|
|
describe("WhatsApp directory contract", () => {
|
|
it("lists peers/groups from config", async () => {
|
|
const cfg = {
|
|
channels: {
|
|
whatsapp: {
|
|
allowFrom: ["+15550000000", "*", "123@g.us"],
|
|
groups: { "999@g.us": { requireMention: true }, "*": {} },
|
|
},
|
|
},
|
|
} as unknown as OpenClawConfig;
|
|
|
|
const peers = await listWhatsAppDirectoryPeersFromConfig({
|
|
cfg,
|
|
accountId: "default",
|
|
query: null,
|
|
limit: null,
|
|
});
|
|
const groups = await listWhatsAppDirectoryGroupsFromConfig({
|
|
cfg,
|
|
accountId: "default",
|
|
query: null,
|
|
limit: null,
|
|
});
|
|
expect(ids(peers)).toEqual(["+15550000000"]);
|
|
expect(ids(groups)).toEqual(["999@g.us"]);
|
|
});
|
|
|
|
it("applies query and limit filtering for config-backed directories", async () => {
|
|
const cfg = {
|
|
channels: {
|
|
whatsapp: {
|
|
groups: { "111@g.us": {}, "222@g.us": {}, "333@s.whatsapp.net": {} },
|
|
},
|
|
},
|
|
} as unknown as OpenClawConfig;
|
|
|
|
const groups = await listWhatsAppDirectoryGroupsFromConfig({
|
|
cfg,
|
|
accountId: "default",
|
|
query: "@g.us",
|
|
limit: 1,
|
|
});
|
|
expect(ids(groups)).toEqual(["111@g.us"]);
|
|
});
|
|
});
|