27 lines
912 B
TypeScript
27 lines
912 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 committedDocument = JSON.parse(content) as Record<string, unknown>;
|
|
const liveDocument = await createOpenApiDocument();
|
|
|
|
expect(committedDocument).toEqual(liveDocument);
|
|
});
|
|
});
|