|
1 | | -import { describe, expect, it } from 'vitest'; |
| 1 | +import { describe, expect, it, vi } from 'vitest'; |
2 | 2 |
|
3 | 3 | import { makeDiscoverableExo } from './discoverable.ts'; |
4 | 4 | import type { MethodSchema } from './schema.ts'; |
5 | 5 |
|
| 6 | +const makeExoMock = vi.hoisted(() => |
| 7 | + vi.fn((_name, _interfaceGuard, methods) => methods), |
| 8 | +); |
| 9 | + |
| 10 | +vi.mock('@endo/exo', () => ({ |
| 11 | + makeExo: makeExoMock, |
| 12 | +})); |
| 13 | + |
6 | 14 | describe('makeDiscoverableExo', () => { |
7 | 15 | const greetSchema: MethodSchema = { |
8 | 16 | description: 'Greets a person by name', |
@@ -113,4 +121,37 @@ describe('makeDiscoverableExo', () => { |
113 | 121 | doSomething: schema.doSomething, |
114 | 122 | }); |
115 | 123 | }); |
| 124 | + |
| 125 | + it('throws if describe is already a method', () => { |
| 126 | + const methods = { |
| 127 | + describe: () => 'original describe', |
| 128 | + greet: (name: string) => `Hello, ${name}!`, |
| 129 | + }; |
| 130 | + const schema: Record<keyof typeof methods, MethodSchema> = { |
| 131 | + describe: { |
| 132 | + description: 'Original describe method', |
| 133 | + args: {}, |
| 134 | + returns: { type: 'string', description: 'Original description' }, |
| 135 | + }, |
| 136 | + greet: greetSchema, |
| 137 | + }; |
| 138 | + |
| 139 | + expect(() => { |
| 140 | + makeDiscoverableExo('TestExo', methods, schema); |
| 141 | + }).toThrow('The `describe` method name is reserved for discoverable exos.'); |
| 142 | + }); |
| 143 | + |
| 144 | + it('re-throws errors from makeExo that are not about describe key', () => { |
| 145 | + const testError = new Error('Some other error from makeExo'); |
| 146 | + makeExoMock.mockImplementation(() => { |
| 147 | + throw testError; |
| 148 | + }); |
| 149 | + |
| 150 | + const methods = { greet: (name: string) => `Hello, ${name}!` }; |
| 151 | + const schema = { greet: greetSchema }; |
| 152 | + |
| 153 | + expect(() => { |
| 154 | + makeDiscoverableExo('TestExo', methods, schema); |
| 155 | + }).toThrow('Some other error from makeExo'); |
| 156 | + }); |
116 | 157 | }); |
0 commit comments