import { UserId } from './UserId';

describe('UserId', () => {
  describe('TDD - Test First', () => {
    it('should create a valid user id from string', () => {
      // Arrange & Act
      const userId = UserId.fromString('user-123');

      // Assert
      expect(userId.value).toBe('user-123');
    });

    it('should trim whitespace', () => {
      // Arrange & Act
      const userId = UserId.fromString('  user-123  ');

      // Assert
      expect(userId.value).toBe('user-123');
    });

    it('should throw error for empty string', () => {
      // Arrange & Act & Assert
      expect(() => UserId.fromString('')).toThrow('User ID cannot be empty');
      expect(() => UserId.fromString('   ')).toThrow('User ID cannot be empty');
    });

    it('should throw error for null or undefined', () => {
      // Arrange & Act & Assert
      expect(() => UserId.fromString(null as unknown as string)).toThrow('User ID cannot be empty');
      expect(() => UserId.fromString(undefined as unknown as string)).toThrow('User ID cannot be empty');
    });

    it('should handle special characters', () => {
      // Arrange & Act
      const userId = UserId.fromString('user-123_test@example');

      // Assert
      expect(userId.value).toBe('user-123_test@example');
    });

    it('should support equals comparison', () => {
      // Arrange
      const userId1 = UserId.fromString('user-123');
      const userId2 = UserId.fromString('user-123');
      const userId3 = UserId.fromString('user-456');

      // Assert
      expect(userId1.equals(userId2)).toBe(true);
      expect(userId1.equals(userId3)).toBe(false);
    });

    it('should support toString', () => {
      // Arrange
      const userId = UserId.fromString('user-123');

      // Assert
      expect(userId.toString()).toBe('user-123');
    });

    it('should handle very long IDs', () => {
      // Arrange
      const longId = 'a'.repeat(1000);

      // Act
      const userId = UserId.fromString(longId);

      // Assert
      expect(userId.value).toBe(longId);
    });

    it('should handle UUID format', () => {
      // Arrange
      const uuid = '550e8400-e29b-41d4-a716-446655440000';

      // Act
      const userId = UserId.fromString(uuid);

      // Assert
      expect(userId.value).toBe(uuid);
    });

    it('should handle numeric string IDs', () => {
      // Arrange & Act
      const userId = UserId.fromString('123456');

      // Assert
      expect(userId.value).toBe('123456');
    });
  });
});