import { VersionName } from '../../../../src/domain/value-objects/version-name.vo';
import { DomainException } from '../../../../src/shared/exceptions/domain.exception';

describe('VersionName Value Object', () => {
  describe('create', () => {
    it('should create valid semantic version', () => {
      const versionName = VersionName.create('1.2.3');
      expect(versionName.value).toBe('1.2.3');
      expect(versionName.major).toBe(1);
      expect(versionName.minor).toBe(2);
      expect(versionName.patch).toBe(3);
    });

    it('should create version with zeros', () => {
      const versionName = VersionName.create('0.0.1');
      expect(versionName.value).toBe('0.0.1');
      expect(versionName.major).toBe(0);
      expect(versionName.minor).toBe(0);
      expect(versionName.patch).toBe(1);
    });

    it('should throw error for empty string', () => {
      expect(() => VersionName.create('')).toThrow(DomainException);
      expect(() => VersionName.create('  ')).toThrow(DomainException);
    });

    it('should throw error for invalid format', () => {
      expect(() => VersionName.create('1.2')).toThrow(DomainException);
      expect(() => VersionName.create('1.2.3.4')).toThrow(DomainException);
      expect(() => VersionName.create('v1.2.3')).toThrow(DomainException);
      expect(() => VersionName.create('1.2.x')).toThrow(DomainException);
    });

    it('should trim whitespace', () => {
      const versionName = VersionName.create('  1.2.3  ');
      expect(versionName.value).toBe('1.2.3');
    });
  });

  describe('equals', () => {
    it('should return true for same versions', () => {
      const v1 = VersionName.create('1.2.3');
      const v2 = VersionName.create('1.2.3');

      expect(v1.equals(v2)).toBe(true);
    });

    it('should return false for different versions', () => {
      const v1 = VersionName.create('1.2.3');
      const v2 = VersionName.create('1.2.4');

      expect(v1.equals(v2)).toBe(false);
    });
  });

  describe('toString', () => {
    it('should return string representation', () => {
      const versionName = VersionName.create('1.2.3');
      expect(versionName.toString()).toBe('1.2.3');
    });
  });
});
