mirror of https://github.com/openclaw/openclaw.git
test: share directory runtime helpers
This commit is contained in:
parent
8410d5a050
commit
38b09866b8
|
|
@ -1,15 +1,10 @@
|
|||
import type { OpenClawConfig, RuntimeEnv } from "openclaw/plugin-sdk/msteams";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createDirectoryTestRuntime, expectDirectorySurface } from "../../test-utils/directory.js";
|
||||
import { msteamsPlugin } from "./channel.js";
|
||||
|
||||
describe("msteams directory", () => {
|
||||
const runtimeEnv: RuntimeEnv = {
|
||||
log: () => {},
|
||||
error: () => {},
|
||||
exit: (code: number): never => {
|
||||
throw new Error(`exit ${code}`);
|
||||
},
|
||||
};
|
||||
const runtimeEnv = createDirectoryTestRuntime() as RuntimeEnv;
|
||||
|
||||
it("lists peers and groups from config", async () => {
|
||||
const cfg = {
|
||||
|
|
@ -29,12 +24,10 @@ describe("msteams directory", () => {
|
|||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
|
||||
expect(msteamsPlugin.directory).toBeTruthy();
|
||||
expect(msteamsPlugin.directory?.listPeers).toBeTruthy();
|
||||
expect(msteamsPlugin.directory?.listGroups).toBeTruthy();
|
||||
const directory = expectDirectorySurface(msteamsPlugin.directory);
|
||||
|
||||
await expect(
|
||||
msteamsPlugin.directory!.listPeers!({
|
||||
directory.listPeers({
|
||||
cfg,
|
||||
query: undefined,
|
||||
limit: undefined,
|
||||
|
|
@ -50,7 +43,7 @@ describe("msteams directory", () => {
|
|||
);
|
||||
|
||||
await expect(
|
||||
msteamsPlugin.directory!.listGroups!({
|
||||
directory.listGroups({
|
||||
cfg,
|
||||
query: undefined,
|
||||
limit: undefined,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
export function createDirectoryTestRuntime() {
|
||||
return {
|
||||
log: () => {},
|
||||
error: () => {},
|
||||
exit: (code: number): never => {
|
||||
throw new Error(`exit ${code}`);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function expectDirectorySurface(
|
||||
directory:
|
||||
| {
|
||||
listPeers?: unknown;
|
||||
listGroups?: unknown;
|
||||
}
|
||||
| null
|
||||
| undefined,
|
||||
) {
|
||||
if (!directory) {
|
||||
throw new Error("expected directory");
|
||||
}
|
||||
if (!directory.listPeers) {
|
||||
throw new Error("expected listPeers");
|
||||
}
|
||||
if (!directory.listGroups) {
|
||||
throw new Error("expected listGroups");
|
||||
}
|
||||
return directory as {
|
||||
listPeers: NonNullable<typeof directory.listPeers>;
|
||||
listGroups: NonNullable<typeof directory.listGroups>;
|
||||
};
|
||||
}
|
||||
|
|
@ -1,15 +1,10 @@
|
|||
import type { OpenClawConfig, RuntimeEnv } from "openclaw/plugin-sdk/zalo";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createDirectoryTestRuntime, expectDirectorySurface } from "../../test-utils/directory.js";
|
||||
import { zaloPlugin } from "./channel.js";
|
||||
|
||||
describe("zalo directory", () => {
|
||||
const runtimeEnv: RuntimeEnv = {
|
||||
log: () => {},
|
||||
error: () => {},
|
||||
exit: (code: number): never => {
|
||||
throw new Error(`exit ${code}`);
|
||||
},
|
||||
};
|
||||
const runtimeEnv = createDirectoryTestRuntime() as RuntimeEnv;
|
||||
|
||||
it("lists peers from allowFrom", async () => {
|
||||
const cfg = {
|
||||
|
|
@ -20,12 +15,10 @@ describe("zalo directory", () => {
|
|||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
|
||||
expect(zaloPlugin.directory).toBeTruthy();
|
||||
expect(zaloPlugin.directory?.listPeers).toBeTruthy();
|
||||
expect(zaloPlugin.directory?.listGroups).toBeTruthy();
|
||||
const directory = expectDirectorySurface(zaloPlugin.directory);
|
||||
|
||||
await expect(
|
||||
zaloPlugin.directory!.listPeers!({
|
||||
directory.listPeers({
|
||||
cfg,
|
||||
accountId: undefined,
|
||||
query: undefined,
|
||||
|
|
@ -41,7 +34,7 @@ describe("zalo directory", () => {
|
|||
);
|
||||
|
||||
await expect(
|
||||
zaloPlugin.directory!.listGroups!({
|
||||
directory.listGroups({
|
||||
cfg,
|
||||
accountId: undefined,
|
||||
query: undefined,
|
||||
|
|
|
|||
Loading…
Reference in New Issue