ai-dev-template / nodejs /tests /unit /validators.test.ts
Jordandevlog's picture
Upload nodejs/tests/unit/validators.test.ts
00b4e55 verified
Raw
History Blame Contribute Delete
893 Bytes
/**
* Tests for validators.
* @module validatorTests
*/
import { describe, it, expect } from 'vitest';
import { userCreateSchema } from '../../src/utils/validators';
describe('userCreateSchema', () => {
it('should accept valid user data', () => {
const valid = {
email: 'test@example.com',
password: 'SecurePass123',
name: 'Test User',
};
expect(() => userCreateSchema.parse(valid)).not.toThrow();
});
it('should reject invalid email', () => {
const invalid = {
email: 'not-an-email',
password: 'SecurePass123',
};
expect(() => userCreateSchema.parse(invalid)).toThrow('Invalid email format');
});
it('should reject short password', () => {
const invalid = {
email: 'test@example.com',
password: 'short',
};
expect(() => userCreateSchema.parse(invalid)).toThrow('at least 8 characters');
});
});