Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2
3import { elevenlabsEnumModels } from './elevenlabs.ts'
4import type { OpenApiDocument } from './types.ts'
5
6const jsonBody = (schema: unknown) => ({
7 post: { requestBody: { content: { 'application/json': { schema } } } },
8})
9
10const spec = {
11 openapi: '3.1.0',
12 paths: {
13 '/v1/music': jsonBody({ $ref: '#/components/schemas/Music' }),
14 '/v1/text-to-voice/design': jsonBody({
15 type: 'object',
16 properties: {
17 model_id: {
18 type: 'string',
19 enum: ['eleven_multilingual_ttv_v2', 'eleven_ttv_v3'],
20 },
21 },
22 }),
23 '/v1/sound-generation': jsonBody({ $ref: '#/components/schemas/SFX' }),
24 },
25 components: {
26 schemas: {
27 Music: {
28 properties: { model_id: { $ref: '#/components/schemas/MusicModelID' } },
29 },
30 MusicModelID: {
31 type: 'string',
32 enum: ['music_v1', 'music_v2', 'music_v2_5'],
33 'x-fern-enum': { music_v1: { deprecated: true } },
34 },
35 SFX: {
36 properties: { model_id: { $ref: '#/components/schemas/SFXModelId' } },
37 },
38 SFXModelId: { type: 'string', enum: ['eleven_text_to_sound_v2'] },
39 },
40 },
41} as unknown as OpenApiDocument
42
43describe('elevenlabsEnumModels', () => {
44 it('reads model_id enums off each generation route', () => {
45 expect(elevenlabsEnumModels(spec)).toEqual([
46 { rawId: 'music_v1', schemaEndpointId: 'v1/music', deprecated: true },
47 { rawId: 'music_v2', schemaEndpointId: 'v1/music', deprecated: false },
48 { rawId: 'music_v2_5', schemaEndpointId: 'v1/music', deprecated: false },
49 {
50 rawId: 'eleven_multilingual_ttv_v2',
51 schemaEndpointId: 'v1/text-to-voice/design',
52 deprecated: false,
53 },
54 {
55 rawId: 'eleven_ttv_v3',
56 schemaEndpointId: 'v1/text-to-voice/design',
57 deprecated: false,
58 },
59 {
60 rawId: 'eleven_text_to_sound_v2',
61 schemaEndpointId: 'v1/sound-generation',
62 deprecated: false,
63 },
64 ])
65 })
66
67 it('throws when a route loses its enum', () => {
68 const broken = {
69 ...spec,
70 paths: { ...spec.paths, '/v1/sound-generation': jsonBody({}) },
71 } as OpenApiDocument
72 expect(() => elevenlabsEnumModels(broken)).toThrow('v1/sound-generation')
73 })
74})