20 lines
683 B
TypeScript
20 lines
683 B
TypeScript
import { validateEnv } from './env.schema.js';
|
|||
|
|
|
||
|
|
describe('validateEnv', () => {
|
||
|
|
it('aplica valores por defecto', () => {
|
||
|
|
const env = validateEnv({});
|
||
|
|
expect(env.PORT).toBe(3000);
|
||
|
|
expect(env.CORS_ORIGINS).toEqual([]);
|
||
|
|
expect(env.LOG_LEVEL).toBe('log');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('convierte PORT y separa CORS_ORIGINS', () => {
|
||
|
|
const env = validateEnv({ PORT: '8080', CORS_ORIGINS: 'https://a.local, https://b.local' });
|
||
|
|
expect(env.PORT).toBe(8080);
|
||
|
|
expect(env.CORS_ORIGINS).toEqual(['https://a.local', 'https://b.local']);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('rechaza valores inválidos con un mensaje claro', () => {
|
||
|
|
expect(() => validateEnv({ PORT: 'abc' })).toThrow(/PORT/);
|
||
|
|
});
|
||
|
|
});
|