|
| 1 | +import { S } from '@metamask/kernel-utils'; |
1 | 2 | import { describe, it, expect } from 'vitest'; |
2 | 3 |
|
3 | | -import { capability } from './capability.ts'; |
| 4 | +import { extractCapabilities, extractCapabilitySchemas } from './capability.ts'; |
| 5 | +import { makeMethodCapability } from '../../test/make-method-capability.ts'; |
4 | 6 |
|
5 | | -describe('capability', () => { |
6 | | - it('creates a capability with func and schema', () => { |
7 | | - const testCapability = capability(async () => Promise.resolve('test'), { |
8 | | - description: 'a test capability', |
9 | | - args: {}, |
10 | | - }); |
11 | | - expect(testCapability.func).toBeInstanceOf(Function); |
12 | | - expect(testCapability.schema).toStrictEqual({ |
13 | | - description: 'a test capability', |
| 7 | +describe('capability extraction', () => { |
| 8 | + const makeRecord = () => ({ |
| 9 | + ping: makeMethodCapability( |
| 10 | + 'Server', |
| 11 | + 'ping', |
| 12 | + async () => 'pong', |
| 13 | + S.method('Ping', [], S.string()), |
| 14 | + ), |
| 15 | + }); |
| 16 | + |
| 17 | + it('extractCapabilities returns the functions keyed by name', async () => { |
| 18 | + const funcs = extractCapabilities(makeRecord()); |
| 19 | + expect(Object.keys(funcs)).toStrictEqual(['ping']); |
| 20 | + expect(await funcs.ping(undefined as never)).toBe('pong'); |
| 21 | + }); |
| 22 | + |
| 23 | + it('extractCapabilitySchemas returns the schemas keyed by name', () => { |
| 24 | + const schemas = extractCapabilitySchemas(makeRecord()); |
| 25 | + expect(schemas.ping).toStrictEqual({ |
| 26 | + description: 'Ping', |
14 | 27 | args: {}, |
| 28 | + required: [], |
| 29 | + returns: { type: 'string' }, |
15 | 30 | }); |
16 | 31 | }); |
17 | 32 | }); |
0 commit comments