38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { TypeDeclarationGenerator } from '../src/discovery/type-generator.js'
|
|
import type { TypeRegistry } from '../src/types/index.js'
|
|
|
|
const registry: TypeRegistry = {
|
|
'GET /users': {
|
|
method: 'GET',
|
|
lastSeen: Date.now(),
|
|
samples: [],
|
|
request: {
|
|
type: 'object',
|
|
properties: { id: { type: 'string' } },
|
|
required: ['id']
|
|
},
|
|
response: {
|
|
type: 'array',
|
|
items: {
|
|
type: 'object',
|
|
properties: {
|
|
id: { type: 'string' },
|
|
email: { type: 'string' }
|
|
},
|
|
required: ['id']
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
describe('type generator', () => {
|
|
it('emits request and response aliases', () => {
|
|
const generator = new TypeDeclarationGenerator(registry)
|
|
const snapshot = generator.generate({ namespace: 'API' })
|
|
expect(snapshot).toContain('export type GetUsersRequest')
|
|
expect(snapshot).toContain('declare namespace API')
|
|
expect(snapshot).toContain("'GET /users': { request: GetUsersRequest; response: GetUsersResponse; method: 'GET'; path: '/users' }")
|
|
})
|
|
})
|