39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { createBomSchema } from '../src/procurement/bom.schemas';
|
|
import { randomUUID } from 'node:crypto';
|
|
|
|
describe('BOM input', () => {
|
|
const materialId = randomUUID();
|
|
it('accepts a bounded material recipe', () => {
|
|
expect(
|
|
createBomSchema.safeParse({
|
|
outputQuantity: 12,
|
|
lines: [{ materialId, quantity: '0.001' }],
|
|
}).success,
|
|
).toBe(true);
|
|
});
|
|
it('rejects duplicate materials, zero quantities and unknown fields', () => {
|
|
const input = {
|
|
outputQuantity: 1,
|
|
lines: [{ materialId, quantity: '1.000' }],
|
|
};
|
|
expect(
|
|
createBomSchema.safeParse({
|
|
...input,
|
|
lines: [...input.lines, ...input.lines],
|
|
}).success,
|
|
).toBe(false);
|
|
expect(
|
|
createBomSchema.safeParse({
|
|
...input,
|
|
lines: [{ materialId, quantity: '0.000' }],
|
|
}).success,
|
|
).toBe(false);
|
|
expect(createBomSchema.safeParse({ ...input, extra: true }).success).toBe(
|
|
false,
|
|
);
|
|
expect(
|
|
createBomSchema.safeParse({ ...input, outputQuantity: 100001 }).success,
|
|
).toBe(false);
|
|
});
|
|
});
|