refactor
This commit is contained in:
137
core/racing/domain/entities/Track.test.ts
Normal file
137
core/racing/domain/entities/Track.test.ts
Normal file
@@ -0,0 +1,137 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { Track } from './Track';
|
||||
|
||||
describe('Track', () => {
|
||||
it('should create a track', () => {
|
||||
const track = Track.create({
|
||||
id: 'track1',
|
||||
name: 'Monza Circuit',
|
||||
shortName: 'MON',
|
||||
country: 'Italy',
|
||||
category: 'road',
|
||||
difficulty: 'advanced',
|
||||
lengthKm: 5.793,
|
||||
turns: 11,
|
||||
imageUrl: 'https://example.com/monza.jpg',
|
||||
gameId: 'game1',
|
||||
});
|
||||
|
||||
expect(track.id).toBe('track1');
|
||||
expect(track.name.toString()).toBe('Monza Circuit');
|
||||
expect(track.shortName.toString()).toBe('MON');
|
||||
expect(track.country.toString()).toBe('Italy');
|
||||
expect(track.category).toBe('road');
|
||||
expect(track.difficulty).toBe('advanced');
|
||||
expect(track.lengthKm.toNumber()).toBe(5.793);
|
||||
expect(track.turns.toNumber()).toBe(11);
|
||||
expect(track.imageUrl.toString()).toBe('https://example.com/monza.jpg');
|
||||
expect(track.gameId.toString()).toBe('game1');
|
||||
});
|
||||
|
||||
it('should create track with defaults', () => {
|
||||
const track = Track.create({
|
||||
id: 'track1',
|
||||
name: 'Monza Circuit',
|
||||
country: 'Italy',
|
||||
lengthKm: 5.793,
|
||||
turns: 11,
|
||||
gameId: 'game1',
|
||||
});
|
||||
|
||||
expect(track.shortName.toString()).toBe('MON');
|
||||
expect(track.category).toBe('road');
|
||||
expect(track.difficulty).toBe('intermediate');
|
||||
expect(track.imageUrl.toString()).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should create track with generated shortName', () => {
|
||||
const track = Track.create({
|
||||
id: 'track1',
|
||||
name: 'Silverstone',
|
||||
country: 'UK',
|
||||
lengthKm: 5.891,
|
||||
turns: 18,
|
||||
gameId: 'game1',
|
||||
});
|
||||
|
||||
expect(track.shortName.toString()).toBe('SIL');
|
||||
});
|
||||
|
||||
it('should throw on invalid id', () => {
|
||||
expect(() => Track.create({
|
||||
id: '',
|
||||
name: 'Monza Circuit',
|
||||
country: 'Italy',
|
||||
lengthKm: 5.793,
|
||||
turns: 11,
|
||||
gameId: 'game1',
|
||||
})).toThrow('Track ID is required');
|
||||
});
|
||||
|
||||
it('should throw on invalid name', () => {
|
||||
expect(() => Track.create({
|
||||
id: 'track1',
|
||||
name: '',
|
||||
country: 'Italy',
|
||||
lengthKm: 5.793,
|
||||
turns: 11,
|
||||
gameId: 'game1',
|
||||
})).toThrow('Track name is required');
|
||||
});
|
||||
|
||||
it('should throw on invalid country', () => {
|
||||
expect(() => Track.create({
|
||||
id: 'track1',
|
||||
name: 'Monza Circuit',
|
||||
country: '',
|
||||
lengthKm: 5.793,
|
||||
turns: 11,
|
||||
gameId: 'game1',
|
||||
})).toThrow('Track country is required');
|
||||
});
|
||||
|
||||
it('should throw on invalid lengthKm', () => {
|
||||
expect(() => Track.create({
|
||||
id: 'track1',
|
||||
name: 'Monza Circuit',
|
||||
country: 'Italy',
|
||||
lengthKm: 0,
|
||||
turns: 11,
|
||||
gameId: 'game1',
|
||||
})).toThrow('Track length must be positive');
|
||||
});
|
||||
|
||||
it('should throw on negative turns', () => {
|
||||
expect(() => Track.create({
|
||||
id: 'track1',
|
||||
name: 'Monza Circuit',
|
||||
country: 'Italy',
|
||||
lengthKm: 5.793,
|
||||
turns: -1,
|
||||
gameId: 'game1',
|
||||
})).toThrow('Track turns cannot be negative');
|
||||
});
|
||||
|
||||
it('should throw on invalid gameId', () => {
|
||||
expect(() => Track.create({
|
||||
id: 'track1',
|
||||
name: 'Monza Circuit',
|
||||
country: 'Italy',
|
||||
lengthKm: 5.793,
|
||||
turns: 11,
|
||||
gameId: '',
|
||||
})).toThrow('Track game ID cannot be empty');
|
||||
});
|
||||
|
||||
it('should throw on empty imageUrl string', () => {
|
||||
expect(() => Track.create({
|
||||
id: 'track1',
|
||||
name: 'Monza Circuit',
|
||||
country: 'Italy',
|
||||
lengthKm: 5.793,
|
||||
turns: 11,
|
||||
imageUrl: '',
|
||||
gameId: 'game1',
|
||||
})).toThrow('Track image URL cannot be empty string');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user