manicanldes-backend/test/batch-quantity.spec.ts

15 lines
713 B
TypeScript

import { AppError } from '../src/common/errors/app-error';
import { plannedMaterialQuantity } from '../src/production/batch-quantity';
describe('planned material scaling', () => {
it('scales exact three-decimal quantities without floating-point loss', () => {
expect(plannedMaterialQuantity('0.125', 8)).toBe('1.000');
expect(plannedMaterialQuantity('125', 3)).toBe('375.000');
expect(plannedMaterialQuantity('999999999.999', 1)).toBe('999999999.999');
});
it('rejects a quantity that would overflow the database column', () => {
expect(() => plannedMaterialQuantity('999999999.999', 2)).toThrow(AppError);
expect(() => plannedMaterialQuantity('1.000', 0)).toThrow(AppError);
});
});