69 lines
2.6 KiB
TypeScript
69 lines
2.6 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { RacingDomainValidationError } from '../errors/RacingDomainError';
|
|
import { TeamRatingEventId } from './TeamRatingEventId';
|
|
|
|
describe('TeamRatingEventId', () => {
|
|
describe('create', () => {
|
|
it('should create valid UUID', () => {
|
|
const validUuid = '123e4567-e89b-12d3-a456-426614174000';
|
|
const id = TeamRatingEventId.create(validUuid);
|
|
expect(id.value).toBe(validUuid);
|
|
});
|
|
|
|
it('should throw for invalid UUID', () => {
|
|
expect(() => TeamRatingEventId.create('not-a-uuid')).toThrow(RacingDomainValidationError);
|
|
expect(() => TeamRatingEventId.create('123e4567-e89b-12d3-a456')).toThrow(RacingDomainValidationError);
|
|
expect(() => TeamRatingEventId.create('')).toThrow(RacingDomainValidationError);
|
|
});
|
|
|
|
it('should throw for empty string', () => {
|
|
expect(() => TeamRatingEventId.create('')).toThrow(RacingDomainValidationError);
|
|
});
|
|
|
|
it('should throw for whitespace', () => {
|
|
expect(() => TeamRatingEventId.create(' ')).toThrow(RacingDomainValidationError);
|
|
});
|
|
|
|
it('should handle uppercase UUIDs', () => {
|
|
const uuid = '123E4567-E89B-12D3-A456-426614174000';
|
|
const id = TeamRatingEventId.create(uuid);
|
|
expect(id.value).toBe(uuid);
|
|
});
|
|
|
|
it('should generate a valid UUID', () => {
|
|
const id = TeamRatingEventId.generate();
|
|
expect(id.value).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i);
|
|
});
|
|
|
|
it('should generate unique IDs', () => {
|
|
const id1 = TeamRatingEventId.generate();
|
|
const id2 = TeamRatingEventId.generate();
|
|
expect(id1.equals(id2)).toBe(false);
|
|
});
|
|
|
|
it('should return true for same UUID', () => {
|
|
const uuid = '123e4567-e89b-12d3-a456-426614174000';
|
|
const id1 = TeamRatingEventId.create(uuid);
|
|
const id2 = TeamRatingEventId.create(uuid);
|
|
expect(id1.equals(id2)).toBe(true);
|
|
});
|
|
|
|
it('should return false for different UUIDs', () => {
|
|
const id1 = TeamRatingEventId.create('123e4567-e89b-12d3-a456-426614174000');
|
|
const id2 = TeamRatingEventId.create('123e4567-e89b-12d3-a456-426614174001');
|
|
expect(id1.equals(id2)).toBe(false);
|
|
});
|
|
|
|
it('should expose props correctly', () => {
|
|
const uuid = '123e4567-e89b-12d3-a456-426614174000';
|
|
const id = TeamRatingEventId.create(uuid);
|
|
expect(id.props.value).toBe(uuid);
|
|
});
|
|
|
|
it('should return string representation', () => {
|
|
const uuid = '123e4567-e89b-12d3-a456-426614174000';
|
|
const id = TeamRatingEventId.create(uuid);
|
|
expect(id.toString()).toBe(uuid);
|
|
});
|
|
});
|
|
}); |