openclaw / src /plugin-sdk /test-helpers /directory-ids.ts
SaylorTwift's picture
SaylorTwift HF Staff
Add files using upload-large-folder tool
eb3f11e verified
Raw History Blame Contribute Delete
1.15 kB
/**
* Shared assertions for channel directory id contract tests.
*/
import { expect } from "vitest";
import type { ChannelDirectoryEntry } from "../channel-contract.js";
import type { OpenClawConfig } from "../config-contracts.js";
export type DirectoryListFn = (params: {
cfg: OpenClawConfig;
accountId?: string;
query?: string | null;
limit?: number | null;
}) => Promise<ChannelDirectoryEntry[]>;
/** Calls a directory lister and compares returned ids, optionally ignoring order. */
export async function expectDirectoryIds(
listFn: DirectoryListFn,
cfg: OpenClawConfig,
expected: string[],
options?: { sorted?: boolean },
) {
const entries = await listFn({
cfg,
accountId: "default",
query: null,
limit: null,
});
const ids = entries.map((entry) => entry.id);
expect(options?.sorted ? sortDirectoryIds(ids) : ids).toEqual(
options?.sorted ? sortDirectoryIds(expected) : expected,
);
}
function compareDirectoryIds(left: string, right: string) {
return left < right ? -1 : left > right ? 1 : 0;
}
function sortDirectoryIds(values: string[]) {
return values.toSorted(compareDirectoryIds);
}