67 lines
2.4 KiB
TypeScript
67 lines
2.4 KiB
TypeScript
import { TeamRatingValue } from './TeamRatingValue';
|
|
import { RacingDomainValidationError } from '../errors/RacingDomainError';
|
|
|
|
describe('TeamRatingValue', () => {
|
|
describe('create', () => {
|
|
it('should create valid rating values', () => {
|
|
expect(TeamRatingValue.create(0).value).toBe(0);
|
|
expect(TeamRatingValue.create(50).value).toBe(50);
|
|
expect(TeamRatingValue.create(100).value).toBe(100);
|
|
expect(TeamRatingValue.create(75.5).value).toBe(75.5);
|
|
});
|
|
|
|
it('should throw for values below 0', () => {
|
|
expect(() => TeamRatingValue.create(-1)).toThrow(RacingDomainValidationError);
|
|
expect(() => TeamRatingValue.create(-0.1)).toThrow(RacingDomainValidationError);
|
|
});
|
|
|
|
it('should throw for values above 100', () => {
|
|
expect(() => TeamRatingValue.create(100.1)).toThrow(RacingDomainValidationError);
|
|
expect(() => TeamRatingValue.create(101)).toThrow(RacingDomainValidationError);
|
|
});
|
|
|
|
it('should accept decimal values', () => {
|
|
const value = TeamRatingValue.create(75.5);
|
|
expect(value.value).toBe(75.5);
|
|
});
|
|
|
|
it('should throw for non-numeric values', () => {
|
|
expect(() => TeamRatingValue.create('50' as unknown as number)).toThrow();
|
|
expect(() => TeamRatingValue.create(null as unknown as number)).toThrow();
|
|
expect(() => TeamRatingValue.create(undefined as unknown as number)).toThrow();
|
|
});
|
|
|
|
it('should return true for same value', () => {
|
|
const val1 = TeamRatingValue.create(50);
|
|
const val2 = TeamRatingValue.create(50);
|
|
expect(val1.equals(val2)).toBe(true);
|
|
});
|
|
|
|
it('should return false for different values', () => {
|
|
const val1 = TeamRatingValue.create(50);
|
|
const val2 = TeamRatingValue.create(60);
|
|
expect(val1.equals(val2)).toBe(false);
|
|
});
|
|
|
|
it('should handle decimal comparisons', () => {
|
|
const val1 = TeamRatingValue.create(75.5);
|
|
const val2 = TeamRatingValue.create(75.5);
|
|
expect(val1.equals(val2)).toBe(true);
|
|
});
|
|
|
|
it('should expose props correctly', () => {
|
|
const value = TeamRatingValue.create(50);
|
|
expect(value.props.value).toBe(50);
|
|
});
|
|
|
|
it('should return numeric value', () => {
|
|
const value = TeamRatingValue.create(75.5);
|
|
expect(value.toNumber()).toBe(75.5);
|
|
});
|
|
|
|
it('should return string representation', () => {
|
|
const value = TeamRatingValue.create(75.5);
|
|
expect(value.toString()).toBe('75.5');
|
|
});
|
|
});
|
|
}); |