File size: 932 Bytes
eb3f11e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
 * Shared directory adapter fixtures for channel contract tests.
 */
import type { ChannelDirectoryAdapter } from "../channel-contract.js";

type DirectorySurface = {
  listPeers: NonNullable<ChannelDirectoryAdapter["listPeers"]>;
  listGroups: NonNullable<ChannelDirectoryAdapter["listGroups"]>;
};

export function createDirectoryTestRuntime() {
  return {
    log: () => {},
    error: () => {},
    exit: (code: number): never => {
      throw new Error(`exit ${code}`);
    },
  };
}

export function expectDirectorySurface(directory: unknown): DirectorySurface {
  if (!directory || typeof directory !== "object") {
    throw new Error("expected directory");
  }
  const { listPeers, listGroups } = directory as ChannelDirectoryAdapter;
  if (!listPeers) {
    throw new Error("expected listPeers");
  }
  if (!listGroups) {
    throw new Error("expected listGroups");
  }
  return {
    listPeers,
    listGroups,
  };
}