import { describe, it, expect } from 'vitest';
import { UserSchema, CreateUserSchema } from './user';

describe('UserSchema', () => {
  it('should validate a valid user', () => {
    const user = {
      id: '123e4567-e89b-12d3-a456-426614174000',
      email: 'test@example.com',
      name: 'Test User',
      createdAt: new Date().toISOString(),
      updatedAt: new Date().toISOString(),
    };

    const result = UserSchema.parse(user);
    expect(result).toEqual(user);
  });

  it('should reject invalid email', () => {
    const user = {
      id: '123e4567-e89b-12d3-a456-426614174000',
      email: 'invalid-email',
      name: 'Test User',
      createdAt: new Date().toISOString(),
      updatedAt: new Date().toISOString(),
    };

    expect(() => UserSchema.parse(user)).toThrow();
  });

  it('should reject missing required fields', () => {
    const user = {
      id: '123e4567-e89b-12d3-a456-426614174000',
      email: 'test@example.com',
    };

    expect(() => UserSchema.parse(user)).toThrow();
  });
});

describe('CreateUserSchema', () => {
  it('should validate create user without id and timestamps', () => {
    const user = {
      email: 'test@example.com',
      name: 'Test User',
    };

    const result = CreateUserSchema.parse(user);
    expect(result).toEqual(user);
  });
});

