25 lines
1.5 KiB
TypeScript
25 lines
1.5 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { bomDetail, bomInput, bomSummary } from "../src/lib/bom.ts";
|
|
|
|
const id = "d66c798a-f764-4b88-8d13-ace328ff1010";
|
|
|
|
test("draft BOMs preserve exact quantities and reject duplicate materials and invalid yields", () => {
|
|
const line = { materialId: id, quantity: "0.125" };
|
|
const input = { outputQuantity: 10, lines: [line] };
|
|
assert.deepEqual(bomInput.parse(input), input);
|
|
assert.equal(bomInput.safeParse({ ...input, outputQuantity: 100001 }).success, false);
|
|
assert.equal(bomInput.safeParse({ ...input, lines: [] }).success, false);
|
|
assert.equal(bomInput.safeParse({ ...input, lines: [{ ...line, quantity: "0.000" }] }).success, false);
|
|
assert.equal(bomInput.safeParse({ ...input, lines: [{ ...line, quantity: "0.12" }] }).success, false);
|
|
assert.equal(bomInput.safeParse({ ...input, lines: [line, { ...line, materialId: id.toUpperCase() }] }).success, false);
|
|
});
|
|
|
|
test("revision lists accept metadata without lines and details accept serialized decimal snapshots", () => {
|
|
const metadata = { id, variantId: id, kind: "PACKAGING", status: "DRAFT", revision: 1, outputQuantity: 10, activatedAt: null };
|
|
assert.deepEqual(bomSummary.parse(metadata), metadata);
|
|
assert.equal(bomDetail.safeParse(metadata).success, false);
|
|
const line = { id, materialId: id, materialName: "Label", materialCode: "LABEL", unit: "PIECE", quantity: "10" };
|
|
assert.deepEqual(bomDetail.parse({ ...metadata, lines: [line] }).lines, [line]);
|
|
});
|