/** * Unit tests for Rating domain entity */ import { describe, it, expect } from 'vitest'; import { Rating } from './Rating'; import { DriverId } from '../../racing/domain/entities/DriverId'; import { RaceId } from '../../racing/domain/entities/RaceId'; describe('Rating Entity', () => { it('should create a rating with correct properties', () => { // Given const props = { driverId: DriverId.create('d1'), raceId: RaceId.create('r1'), rating: 1200, components: { resultsStrength: 80, consistency: 70, cleanDriving: 90, racecraft: 75, reliability: 85, teamContribution: 60, }, timestamp: new Date('2024-01-01T12:00:00Z'), }; // When const rating = Rating.create(props); // Then expect(rating.driverId).toBe(props.driverId); expect(rating.raceId).toBe(props.raceId); expect(rating.rating).toBe(props.rating); expect(rating.components).toEqual(props.components); expect(rating.timestamp).toEqual(props.timestamp); }); it('should convert to JSON correctly', () => { // Given const props = { driverId: DriverId.create('d1'), raceId: RaceId.create('r1'), rating: 1200, components: { resultsStrength: 80, consistency: 70, cleanDriving: 90, racecraft: 75, reliability: 85, teamContribution: 60, }, timestamp: new Date('2024-01-01T12:00:00Z'), }; const rating = Rating.create(props); // When const json = rating.toJSON(); // Then expect(json).toEqual({ driverId: 'd1', raceId: 'r1', rating: 1200, components: props.components, timestamp: '2024-01-01T12:00:00.000Z', }); }); });