MCPcopy
hub / github.com/callstack/agent-device / createTestClient

Function createTestClient

src/__tests__/remote-connection.test.ts:73–161  ·  view source on GitHub ↗
(
  options: {
    allocate?: AgentDeviceClient['leases']['allocate'];
    heartbeat?: AgentDeviceClient['leases']['heartbeat'];
    release?: AgentDeviceClient['leases']['release'];
    prepare?: AgentDeviceClient['metro']['prepare'];
    closeSession?: AgentDeviceClient['sessions']['close'];
    listDevices?: AgentDeviceClient['devices']['list'];
  } = {},
)

Source from the content-addressed store, hash-verified

71}
72
73function createTestClient(
74 options: {
75 allocate?: AgentDeviceClient['leases']['allocate'];
76 heartbeat?: AgentDeviceClient['leases']['heartbeat'];
77 release?: AgentDeviceClient['leases']['release'];
78 prepare?: AgentDeviceClient['metro']['prepare'];
79 closeSession?: AgentDeviceClient['sessions']['close'];
80 listDevices?: AgentDeviceClient['devices']['list'];
81 } = {},
82): AgentDeviceClient {
83 return {
84 command: createThrowingMethodGroup<AgentDeviceClient['command']>(),
85 devices: createThrowingMethodGroup<AgentDeviceClient['devices']>({
86 list:
87 options.listDevices ??
88 (async () => [
89 {
90 platform: 'android',
91 target: 'mobile',
92 kind: 'emulator',
93 id: 'emulator-5554',
94 name: 'Android Emulator',
95 booted: true,
96 identifiers: { serial: 'emulator-5554' },
97 android: { serial: 'emulator-5554' },
98 },
99 ]),
100 }),
101 sessions: createThrowingMethodGroup<AgentDeviceClient['sessions']>({
102 close:
103 options.closeSession ??
104 (async () => ({
105 session: 'adc-android',
106 identifiers: { session: 'adc-android' },
107 })),
108 }),
109 apps: createThrowingMethodGroup<AgentDeviceClient['apps']>(),
110 materializations: createThrowingMethodGroup<AgentDeviceClient['materializations']>(),
111 leases: createThrowingMethodGroup<AgentDeviceClient['leases']>({
112 allocate:
113 options.allocate ??
114 (async (request) => ({
115 leaseId: 'lease-1',
116 tenantId: request.tenant,
117 runId: request.runId,
118 backend: request.leaseBackend ?? 'android-instance',
119 })),
120 heartbeat:
121 options.heartbeat ??
122 (async (request) => ({
123 leaseId: request.leaseId,
124 tenantId: request.tenant ?? 'acme',
125 runId: request.runId ?? 'run-123',
126 backend: request.leaseBackend ?? 'android-instance',
127 })),
128 release: options.release ?? (async () => ({ released: true })),
129 }),
130 metro: createThrowingMethodGroup<AgentDeviceClient['metro']>({

Callers 1

Calls 1

Tested by

no test coverage detected