refactor
This commit is contained in:
116
core/racing/domain/entities/League.test.ts
Normal file
116
core/racing/domain/entities/League.test.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { League } from './League';
|
||||
|
||||
describe('League', () => {
|
||||
it('should create a league', () => {
|
||||
const league = League.create({
|
||||
id: 'league1',
|
||||
name: 'Test League',
|
||||
description: 'A test league',
|
||||
ownerId: 'owner1',
|
||||
});
|
||||
|
||||
expect(league.id.toString()).toBe('league1');
|
||||
expect(league.name.toString()).toBe('Test League');
|
||||
expect(league.description.toString()).toBe('A test league');
|
||||
expect(league.ownerId.toString()).toBe('owner1');
|
||||
});
|
||||
|
||||
it('should throw on invalid id', () => {
|
||||
expect(() => League.create({
|
||||
id: '',
|
||||
name: 'Test League',
|
||||
description: 'A test league',
|
||||
ownerId: 'owner1',
|
||||
})).toThrow('League ID cannot be empty');
|
||||
});
|
||||
|
||||
it('should throw on invalid name', () => {
|
||||
expect(() => League.create({
|
||||
id: 'league1',
|
||||
name: '',
|
||||
description: 'A test league',
|
||||
ownerId: 'owner1',
|
||||
})).toThrow('League name cannot be empty');
|
||||
});
|
||||
|
||||
it('should throw on name too long', () => {
|
||||
const longName = 'a'.repeat(101);
|
||||
expect(() => League.create({
|
||||
id: 'league1',
|
||||
name: longName,
|
||||
description: 'A test league',
|
||||
ownerId: 'owner1',
|
||||
})).toThrow('League name cannot exceed 100 characters');
|
||||
});
|
||||
|
||||
it('should throw on invalid description', () => {
|
||||
expect(() => League.create({
|
||||
id: 'league1',
|
||||
name: 'Test League',
|
||||
description: '',
|
||||
ownerId: 'owner1',
|
||||
})).toThrow('League description cannot be empty');
|
||||
});
|
||||
|
||||
it('should throw on description too long', () => {
|
||||
const longDesc = 'a'.repeat(501);
|
||||
expect(() => League.create({
|
||||
id: 'league1',
|
||||
name: 'Test League',
|
||||
description: longDesc,
|
||||
ownerId: 'owner1',
|
||||
})).toThrow('League description cannot exceed 500 characters');
|
||||
});
|
||||
|
||||
it('should throw on invalid ownerId', () => {
|
||||
expect(() => League.create({
|
||||
id: 'league1',
|
||||
name: 'Test League',
|
||||
description: 'A test league',
|
||||
ownerId: '',
|
||||
})).toThrow('League owner ID cannot be empty');
|
||||
});
|
||||
|
||||
it('should create with social links', () => {
|
||||
const league = League.create({
|
||||
id: 'league1',
|
||||
name: 'Test League',
|
||||
description: 'A test league',
|
||||
ownerId: 'owner1',
|
||||
socialLinks: {
|
||||
discordUrl: 'https://discord.gg/test',
|
||||
},
|
||||
});
|
||||
|
||||
expect(league.socialLinks?.discordUrl).toBe('https://discord.gg/test');
|
||||
});
|
||||
|
||||
it('should throw on invalid social links', () => {
|
||||
expect(() => League.create({
|
||||
id: 'league1',
|
||||
name: 'Test League',
|
||||
description: 'A test league',
|
||||
ownerId: 'owner1',
|
||||
socialLinks: {
|
||||
discordUrl: 'invalid-url',
|
||||
},
|
||||
})).toThrow('Invalid Discord URL');
|
||||
});
|
||||
|
||||
it('should update league', () => {
|
||||
const league = League.create({
|
||||
id: 'league1',
|
||||
name: 'Test League',
|
||||
description: 'A test league',
|
||||
ownerId: 'owner1',
|
||||
});
|
||||
|
||||
const updated = league.update({
|
||||
name: 'Updated League',
|
||||
});
|
||||
|
||||
expect(updated.name.toString()).toBe('Updated League');
|
||||
expect(updated.id).toBe(league.id);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user