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 type { OpenClawConfig, RuntimeEnv } from "openclaw/plugin-sdk/msteams";
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { createDirectoryTestRuntime, expectDirectorySurface } from "../../test-utils/directory.js";
|
||||||
import { msteamsPlugin } from "./channel.js";
|
import { msteamsPlugin } from "./channel.js";
|
||||||
|
|
||||||
describe("msteams directory", () => {
|
describe("msteams directory", () => {
|
||||||
const runtimeEnv: RuntimeEnv = {
|
const runtimeEnv = createDirectoryTestRuntime() as RuntimeEnv;
|
||||||
log: () => {},
|
|
||||||
error: () => {},
|
|
||||||
exit: (code: number): never => {
|
|
||||||
throw new Error(`exit ${code}`);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
it("lists peers and groups from config", async () => {
|
it("lists peers and groups from config", async () => {
|
||||||
const cfg = {
|
const cfg = {
|
||||||
|
|
@ -29,12 +24,10 @@ describe("msteams directory", () => {
|
||||||
},
|
},
|
||||||
} as unknown as OpenClawConfig;
|
} as unknown as OpenClawConfig;
|
||||||
|
|
||||||
expect(msteamsPlugin.directory).toBeTruthy();
|
const directory = expectDirectorySurface(msteamsPlugin.directory);
|
||||||
expect(msteamsPlugin.directory?.listPeers).toBeTruthy();
|
|
||||||
expect(msteamsPlugin.directory?.listGroups).toBeTruthy();
|
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
msteamsPlugin.directory!.listPeers!({
|
directory.listPeers({
|
||||||
cfg,
|
cfg,
|
||||||
query: undefined,
|
query: undefined,
|
||||||
limit: undefined,
|
limit: undefined,
|
||||||
|
|
@ -50,7 +43,7 @@ describe("msteams directory", () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
msteamsPlugin.directory!.listGroups!({
|
directory.listGroups({
|
||||||
cfg,
|
cfg,
|
||||||
query: undefined,
|
query: undefined,
|
||||||
limit: 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 type { OpenClawConfig, RuntimeEnv } from "openclaw/plugin-sdk/zalo";
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { createDirectoryTestRuntime, expectDirectorySurface } from "../../test-utils/directory.js";
|
||||||
import { zaloPlugin } from "./channel.js";
|
import { zaloPlugin } from "./channel.js";
|
||||||
|
|
||||||
describe("zalo directory", () => {
|
describe("zalo directory", () => {
|
||||||
const runtimeEnv: RuntimeEnv = {
|
const runtimeEnv = createDirectoryTestRuntime() as RuntimeEnv;
|
||||||
log: () => {},
|
|
||||||
error: () => {},
|
|
||||||
exit: (code: number): never => {
|
|
||||||
throw new Error(`exit ${code}`);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
it("lists peers from allowFrom", async () => {
|
it("lists peers from allowFrom", async () => {
|
||||||
const cfg = {
|
const cfg = {
|
||||||
|
|
@ -20,12 +15,10 @@ describe("zalo directory", () => {
|
||||||
},
|
},
|
||||||
} as unknown as OpenClawConfig;
|
} as unknown as OpenClawConfig;
|
||||||
|
|
||||||
expect(zaloPlugin.directory).toBeTruthy();
|
const directory = expectDirectorySurface(zaloPlugin.directory);
|
||||||
expect(zaloPlugin.directory?.listPeers).toBeTruthy();
|
|
||||||
expect(zaloPlugin.directory?.listGroups).toBeTruthy();
|
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
zaloPlugin.directory!.listPeers!({
|
directory.listPeers({
|
||||||
cfg,
|
cfg,
|
||||||
accountId: undefined,
|
accountId: undefined,
|
||||||
query: undefined,
|
query: undefined,
|
||||||
|
|
@ -41,7 +34,7 @@ describe("zalo directory", () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
zaloPlugin.directory!.listGroups!({
|
directory.listGroups({
|
||||||
cfg,
|
cfg,
|
||||||
accountId: undefined,
|
accountId: undefined,
|
||||||
query: undefined,
|
query: undefined,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue