Files
gridpilot.gg/core/identity/domain/value-objects/RatingEventId.test.ts
2025-12-29 22:27:33 +01:00

76 lines
2.6 KiB
TypeScript

import { RatingEventId } from './RatingEventId';
import { IdentityDomainValidationError } from '../errors/IdentityDomainError';
describe('RatingEventId', () => {
describe('create', () => {
it('should create valid UUID v4', () => {
const validUuid = '123e4567-e89b-12d3-a456-426614174000';
const id = RatingEventId.create(validUuid);
expect(id.value).toBe(validUuid);
});
it('should throw for invalid UUID', () => {
expect(() => RatingEventId.create('not-a-uuid')).toThrow(IdentityDomainValidationError);
expect(() => RatingEventId.create('123e4567-e89b-12d3-a456')).toThrow(IdentityDomainValidationError);
expect(() => RatingEventId.create('')).toThrow(IdentityDomainValidationError);
});
it('should throw for empty string', () => {
expect(() => RatingEventId.create('')).toThrow(IdentityDomainValidationError);
});
it('should throw for whitespace', () => {
expect(() => RatingEventId.create(' ')).toThrow(IdentityDomainValidationError);
});
it('should accept UUID with uppercase', () => {
const uuid = '123E4567-E89B-12D3-A456-426614174000';
const id = RatingEventId.create(uuid);
expect(id.value).toBe(uuid);
});
});
describe('generate', () => {
it('should generate a valid UUID', () => {
const id = RatingEventId.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 = RatingEventId.generate();
const id2 = RatingEventId.generate();
expect(id1.equals(id2)).toBe(false);
});
});
describe('equals', () => {
it('should return true for same UUID', () => {
const uuid = '123e4567-e89b-12d3-a456-426614174000';
const id1 = RatingEventId.create(uuid);
const id2 = RatingEventId.create(uuid);
expect(id1.equals(id2)).toBe(true);
});
it('should return false for different UUIDs', () => {
const id1 = RatingEventId.create('123e4567-e89b-12d3-a456-426614174000');
const id2 = RatingEventId.create('123e4567-e89b-12d3-a456-426614174001');
expect(id1.equals(id2)).toBe(false);
});
});
describe('props', () => {
it('should expose props correctly', () => {
const uuid = '123e4567-e89b-12d3-a456-426614174000';
const id = RatingEventId.create(uuid);
expect(id.props.value).toBe(uuid);
});
});
describe('toString', () => {
it('should return string representation', () => {
const uuid = '123e4567-e89b-12d3-a456-426614174000';
const id = RatingEventId.create(uuid);
expect(id.toString()).toBe(uuid);
});
});
});