File tree Expand file tree Collapse file tree 3 files changed +43
-24
lines changed
Expand file tree Collapse file tree 3 files changed +43
-24
lines changed Original file line number Diff line number Diff line change 11import type { OpenClawConfig , RuntimeEnv } from "openclaw/plugin-sdk/msteams" ;
22import { describe , expect , it } from "vitest" ;
3+ import { createDirectoryTestRuntime , expectDirectorySurface } from "../../test-utils/directory.js" ;
34import { msteamsPlugin } from "./channel.js" ;
45
56describe ( "msteams directory" , ( ) => {
6- const runtimeEnv : RuntimeEnv = {
7- log : ( ) => { } ,
8- error : ( ) => { } ,
9- exit : ( code : number ) : never => {
10- throw new Error ( `exit ${ code } ` ) ;
11- } ,
12- } ;
7+ const runtimeEnv = createDirectoryTestRuntime ( ) as RuntimeEnv ;
138
149 it ( "lists peers and groups from config" , async ( ) => {
1510 const cfg = {
@@ -29,12 +24,10 @@ describe("msteams directory", () => {
2924 } ,
3025 } as unknown as OpenClawConfig ;
3126
32- expect ( msteamsPlugin . directory ) . toBeTruthy ( ) ;
33- expect ( msteamsPlugin . directory ?. listPeers ) . toBeTruthy ( ) ;
34- expect ( msteamsPlugin . directory ?. listGroups ) . toBeTruthy ( ) ;
27+ const directory = expectDirectorySurface ( msteamsPlugin . directory ) ;
3528
3629 await expect (
37- msteamsPlugin . directory ! . listPeers ! ( {
30+ directory . listPeers ( {
3831 cfg,
3932 query : undefined ,
4033 limit : undefined ,
@@ -50,7 +43,7 @@ describe("msteams directory", () => {
5043 ) ;
5144
5245 await expect (
53- msteamsPlugin . directory ! . listGroups ! ( {
46+ directory . listGroups ( {
5447 cfg,
5548 query : undefined ,
5649 limit : undefined ,
Original file line number Diff line number Diff line change 1+ export function createDirectoryTestRuntime ( ) {
2+ return {
3+ log : ( ) => { } ,
4+ error : ( ) => { } ,
5+ exit : ( code : number ) : never => {
6+ throw new Error ( `exit ${ code } ` ) ;
7+ } ,
8+ } ;
9+ }
10+
11+ export function expectDirectorySurface (
12+ directory :
13+ | {
14+ listPeers ?: unknown ;
15+ listGroups ?: unknown ;
16+ }
17+ | null
18+ | undefined ,
19+ ) {
20+ if ( ! directory ) {
21+ throw new Error ( "expected directory" ) ;
22+ }
23+ if ( ! directory . listPeers ) {
24+ throw new Error ( "expected listPeers" ) ;
25+ }
26+ if ( ! directory . listGroups ) {
27+ throw new Error ( "expected listGroups" ) ;
28+ }
29+ return directory as {
30+ listPeers : NonNullable < typeof directory . listPeers > ;
31+ listGroups : NonNullable < typeof directory . listGroups > ;
32+ } ;
33+ }
Original file line number Diff line number Diff line change 11import type { OpenClawConfig , RuntimeEnv } from "openclaw/plugin-sdk/zalo" ;
22import { describe , expect , it } from "vitest" ;
3+ import { createDirectoryTestRuntime , expectDirectorySurface } from "../../test-utils/directory.js" ;
34import { zaloPlugin } from "./channel.js" ;
45
56describe ( "zalo directory" , ( ) => {
6- const runtimeEnv : RuntimeEnv = {
7- log : ( ) => { } ,
8- error : ( ) => { } ,
9- exit : ( code : number ) : never => {
10- throw new Error ( `exit ${ code } ` ) ;
11- } ,
12- } ;
7+ const runtimeEnv = createDirectoryTestRuntime ( ) as RuntimeEnv ;
138
149 it ( "lists peers from allowFrom" , async ( ) => {
1510 const cfg = {
@@ -20,12 +15,10 @@ describe("zalo directory", () => {
2015 } ,
2116 } as unknown as OpenClawConfig ;
2217
23- expect ( zaloPlugin . directory ) . toBeTruthy ( ) ;
24- expect ( zaloPlugin . directory ?. listPeers ) . toBeTruthy ( ) ;
25- expect ( zaloPlugin . directory ?. listGroups ) . toBeTruthy ( ) ;
18+ const directory = expectDirectorySurface ( zaloPlugin . directory ) ;
2619
2720 await expect (
28- zaloPlugin . directory ! . listPeers ! ( {
21+ directory . listPeers ( {
2922 cfg,
3023 accountId : undefined ,
3124 query : undefined ,
@@ -41,7 +34,7 @@ describe("zalo directory", () => {
4134 ) ;
4235
4336 await expect (
44- zaloPlugin . directory ! . listGroups ! ( {
37+ directory . listGroups ( {
4538 cfg,
4639 accountId : undefined ,
4740 query : undefined ,
You can’t perform that action at this time.
0 commit comments