46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { GameConstraints } from './GameConstraints';
|
|
|
|
const sampleConstraints = {
|
|
maxDrivers: 64,
|
|
maxTeams: 32,
|
|
defaultMaxDrivers: 24,
|
|
minDrivers: 2,
|
|
supportsTeams: true,
|
|
supportsMultiClass: true,
|
|
};
|
|
|
|
describe('GameConstraints', () => {
|
|
it('should create', () => {
|
|
const gc = new GameConstraints('iracing', sampleConstraints);
|
|
expect(gc.gameId).toBe('iracing');
|
|
expect(gc.maxDrivers).toBe(64);
|
|
});
|
|
|
|
it('should validate driver count', () => {
|
|
const gc = new GameConstraints('iracing', sampleConstraints);
|
|
expect(gc.validateDriverCount(10)).toEqual({ valid: true });
|
|
expect(gc.validateDriverCount(1)).toEqual({ valid: false, error: 'Minimum 2 drivers required' });
|
|
expect(gc.validateDriverCount(100)).toEqual({ valid: false, error: 'Maximum 64 drivers allowed for IRACING' });
|
|
});
|
|
|
|
it('should validate team count', () => {
|
|
const gc = new GameConstraints('iracing', sampleConstraints);
|
|
expect(gc.validateTeamCount(10)).toEqual({ valid: true });
|
|
expect(gc.validateTeamCount(100)).toEqual({ valid: false, error: 'Maximum 32 teams allowed for IRACING' });
|
|
});
|
|
|
|
it('should not support teams if false', () => {
|
|
const noTeams = { ...sampleConstraints, supportsTeams: false };
|
|
const gc = new GameConstraints('acc', noTeams);
|
|
expect(gc.validateTeamCount(1)).toEqual({ valid: false, error: 'ACC does not support team-based leagues' });
|
|
});
|
|
|
|
it('equals', () => {
|
|
const gc1 = new GameConstraints('iracing', sampleConstraints);
|
|
const gc2 = new GameConstraints('iracing', sampleConstraints);
|
|
const gc3 = new GameConstraints('acc', sampleConstraints);
|
|
expect(gc1.equals(gc2)).toBe(true);
|
|
expect(gc1.equals(gc3)).toBe(false);
|
|
});
|
|
}); |