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