Тесты: часть 1
This commit is contained in:
49
tests/unit/config.test.ts
Normal file
49
tests/unit/config.test.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { describe, test, expect } from 'bun:test';
|
||||
import { validateConfig, type GeneratorConfig } from '../../src/config.js';
|
||||
|
||||
describe('config', () => {
|
||||
describe('validateConfig', () => {
|
||||
test('должен пройти валидацию для корректной конфигурации', () => {
|
||||
const config: Partial<GeneratorConfig> = {
|
||||
inputPath: './openapi.json',
|
||||
outputPath: './output',
|
||||
fileName: 'Api',
|
||||
};
|
||||
|
||||
expect(() => validateConfig(config)).not.toThrow();
|
||||
expect(validateConfig(config)).toBe(true);
|
||||
});
|
||||
|
||||
test('должен пройти валидацию без опционального fileName', () => {
|
||||
const config: Partial<GeneratorConfig> = {
|
||||
inputPath: './openapi.json',
|
||||
outputPath: './output',
|
||||
};
|
||||
|
||||
expect(() => validateConfig(config)).not.toThrow();
|
||||
expect(validateConfig(config)).toBe(true);
|
||||
});
|
||||
|
||||
test('должен выбросить ошибку без inputPath', () => {
|
||||
const config: Partial<GeneratorConfig> = {
|
||||
outputPath: './output',
|
||||
};
|
||||
|
||||
expect(() => validateConfig(config)).toThrow('Input path is required');
|
||||
});
|
||||
|
||||
test('должен выбросить ошибку без outputPath', () => {
|
||||
const config: Partial<GeneratorConfig> = {
|
||||
inputPath: './openapi.json',
|
||||
};
|
||||
|
||||
expect(() => validateConfig(config)).toThrow('Output path is required');
|
||||
});
|
||||
|
||||
test('должен выбросить ошибку без обоих обязательных полей', () => {
|
||||
const config: Partial<GeneratorConfig> = {};
|
||||
|
||||
expect(() => validateConfig(config)).toThrow('Configuration validation failed');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user