(results: Record<string, unknown>)
| 53 | |
| 54 | /** Build a ctx whose rpc routes by method name to a supplied map of results. */ |
| 55 | const buildCtx = (results: Record<string, unknown>) => { |
| 56 | const sys = vi.fn() |
| 57 | const calls: Array<{ method: string; params: unknown }> = [] |
| 58 | |
| 59 | const rpc = vi.fn((method: string, params: unknown) => { |
| 60 | calls.push({ method, params }) |
| 61 | |
| 62 | return Promise.resolve(results[method]) |
| 63 | }) |
| 64 | |
| 65 | const ctx = { |
| 66 | gateway: { rpc }, |
| 67 | guarded, |
| 68 | guardedErr: vi.fn(), |
| 69 | sid: 'sid-1', |
| 70 | stale: () => false, |
| 71 | transcript: { page: vi.fn(), panel: vi.fn(), sys } |
| 72 | } |
| 73 | |
| 74 | const run = async (arg: string) => { |
| 75 | billingCommand.run(arg, ctx as any, 'billing') |
| 76 | await rpc.mock.results[0]?.value |
| 77 | await Promise.resolve() |
| 78 | await Promise.resolve() |
| 79 | } |
| 80 | |
| 81 | return { calls, ctx, rpc, run, sys } |
| 82 | } |
| 83 | |
| 84 | const printed = (sys: ReturnType<typeof vi.fn>) => sys.mock.calls.map(c => c[0]).join('\n') |
| 85 |
no test coverage detected