110 lines
3.8 KiB
TypeScript
110 lines
3.8 KiB
TypeScript
import { RatingDelta } from './RatingDelta';
|
|
import { IdentityDomainValidationError } from '../errors/IdentityDomainError';
|
|
|
|
describe('RatingDelta', () => {
|
|
describe('create', () => {
|
|
it('should create valid delta values', () => {
|
|
expect(RatingDelta.create(0).value).toBe(0);
|
|
expect(RatingDelta.create(10).value).toBe(10);
|
|
expect(RatingDelta.create(-10).value).toBe(-10);
|
|
expect(RatingDelta.create(100).value).toBe(100);
|
|
expect(RatingDelta.create(-100).value).toBe(-100);
|
|
expect(RatingDelta.create(50.5).value).toBe(50.5);
|
|
expect(RatingDelta.create(-50.5).value).toBe(-50.5);
|
|
});
|
|
|
|
it('should throw for values outside range', () => {
|
|
expect(() => RatingDelta.create(100.1)).toThrow(IdentityDomainValidationError);
|
|
expect(() => RatingDelta.create(-100.1)).toThrow(IdentityDomainValidationError);
|
|
expect(() => RatingDelta.create(101)).toThrow(IdentityDomainValidationError);
|
|
expect(() => RatingDelta.create(-101)).toThrow(IdentityDomainValidationError);
|
|
});
|
|
|
|
it('should accept zero', () => {
|
|
const delta = RatingDelta.create(0);
|
|
expect(delta.value).toBe(0);
|
|
});
|
|
|
|
it('should throw for non-numeric values', () => {
|
|
expect(() => RatingDelta.create('50' as unknown as number)).toThrow();
|
|
expect(() => RatingDelta.create(null as unknown as number)).toThrow();
|
|
expect(() => RatingDelta.create(undefined as unknown as number)).toThrow();
|
|
});
|
|
});
|
|
|
|
describe('equals', () => {
|
|
it('should return true for same value', () => {
|
|
const delta1 = RatingDelta.create(10);
|
|
const delta2 = RatingDelta.create(10);
|
|
expect(delta1.equals(delta2)).toBe(true);
|
|
});
|
|
|
|
it('should return false for different values', () => {
|
|
const delta1 = RatingDelta.create(10);
|
|
const delta2 = RatingDelta.create(-10);
|
|
expect(delta1.equals(delta2)).toBe(false);
|
|
});
|
|
|
|
it('should handle decimal comparisons', () => {
|
|
const delta1 = RatingDelta.create(50.5);
|
|
const delta2 = RatingDelta.create(50.5);
|
|
expect(delta1.equals(delta2)).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('props', () => {
|
|
it('should expose props correctly', () => {
|
|
const delta = RatingDelta.create(10);
|
|
expect(delta.props.value).toBe(10);
|
|
});
|
|
});
|
|
|
|
describe('toNumber', () => {
|
|
it('should return numeric value', () => {
|
|
const delta = RatingDelta.create(50.5);
|
|
expect(delta.toNumber()).toBe(50.5);
|
|
});
|
|
});
|
|
|
|
describe('toString', () => {
|
|
it('should return string representation', () => {
|
|
const delta = RatingDelta.create(50.5);
|
|
expect(delta.toString()).toBe('50.5');
|
|
});
|
|
});
|
|
|
|
describe('isPositive', () => {
|
|
it('should return true for positive deltas', () => {
|
|
expect(RatingDelta.create(1).isPositive()).toBe(true);
|
|
expect(RatingDelta.create(100).isPositive()).toBe(true);
|
|
});
|
|
|
|
it('should return false for zero and negative deltas', () => {
|
|
expect(RatingDelta.create(0).isPositive()).toBe(false);
|
|
expect(RatingDelta.create(-1).isPositive()).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('isNegative', () => {
|
|
it('should return true for negative deltas', () => {
|
|
expect(RatingDelta.create(-1).isNegative()).toBe(true);
|
|
expect(RatingDelta.create(-100).isNegative()).toBe(true);
|
|
});
|
|
|
|
it('should return false for zero and positive deltas', () => {
|
|
expect(RatingDelta.create(0).isNegative()).toBe(false);
|
|
expect(RatingDelta.create(1).isNegative()).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('isZero', () => {
|
|
it('should return true for zero delta', () => {
|
|
expect(RatingDelta.create(0).isZero()).toBe(true);
|
|
});
|
|
|
|
it('should return false for non-zero deltas', () => {
|
|
expect(RatingDelta.create(1).isZero()).toBe(false);
|
|
expect(RatingDelta.create(-1).isZero()).toBe(false);
|
|
});
|
|
});
|
|
}); |