Files
a-share-analysis/server/apps/api/test/openapi.test.ts
T

30 lines
1013 B
TypeScript

import { readFile } from 'node:fs/promises';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
import { createOpenApiDocument } from '../../../tools/export-openapi';
describe('Server OpenAPI 单向发布', () => {
it('从真实 Controller 和 DTO 生成健康接口契约', async () => {
const document = await createOpenApiDocument();
expect(document.paths).toHaveProperty('/api/v1/health');
expect(document.components?.schemas).toHaveProperty('HealthResponseDto');
});
it('仓库内 OpenAPI 文件是可解析的同一契约', async () => {
const content = await readFile(
path.resolve(__dirname, '../../../openapi/openapi.json'),
'utf8',
);
const document = JSON.parse(content) as {
paths: Record<string, unknown>;
components?: { schemas?: Record<string, unknown> };
};
expect(document.paths).toHaveProperty('/api/v1/health');
expect(document.components?.schemas).toHaveProperty('HealthResponseDto');
});
});