47 lines
2.3 KiB
TypeScript
47 lines
2.3 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { materialInput, purchaseOrderInput, supplierInput, supplyTerms, supplyTermsInput } from "../src/lib/procurement.ts";
|
|
|
|
const id = "d66c798a-f764-4b88-8d13-ace328ff1010";
|
|
const terms = {
|
|
supplierSku: "",
|
|
leadTimeDays: 10,
|
|
minOrderQuantity: "0.125",
|
|
unitPrice: "900000000.01",
|
|
currency: "INR",
|
|
active: true,
|
|
};
|
|
|
|
test("supplier directory normalizes business codes and email addresses", () => {
|
|
const value = supplierInput.parse({
|
|
name: " Candle supply ", code: " wax_1 ", contactName: "Supplier contact",
|
|
email: "CONTACT@example.com", phone: "+91 1234567890", active: true,
|
|
});
|
|
assert.equal(value.name, "Candle supply");
|
|
assert.equal(value.code, "WAX_1");
|
|
assert.equal(value.email, "contact@example.com");
|
|
});
|
|
|
|
test("material directory enforces backend material kinds and units", () => {
|
|
const value = { name: "Wax", code: "WAX", kind: "WAX", unit: "GRAM", active: true };
|
|
assert.equal(materialInput.safeParse(value).success, true);
|
|
assert.equal(materialInput.safeParse({ ...value, unit: "BOX" }).success, false);
|
|
});
|
|
|
|
test("supply terms preserve precise string quantities and enforce request scale", () => {
|
|
assert.deepEqual(supplyTermsInput.parse(terms), terms);
|
|
assert.equal(supplyTermsInput.safeParse({ ...terms, minOrderQuantity: "0.000" }).success, false);
|
|
assert.equal(supplyTermsInput.safeParse({ ...terms, unitPrice: "2.1" }).success, false);
|
|
assert.equal(supplyTermsInput.safeParse({ ...terms, leadTimeDays: 366 }).success, false);
|
|
assert.equal(supplyTerms.parse({ ...terms, id, materialId: id, unitPrice: "2", minOrderQuantity: "1.5" }).unitPrice, "2");
|
|
});
|
|
|
|
test("draft orders require distinct materials, exact quantities and a calendar date", () => {
|
|
const line = { materialId: id, quantity: "1.001" };
|
|
const input = { supplierId: id, expectedDeliveryDate: "2026-12-01", lines: [line] };
|
|
assert.deepEqual(purchaseOrderInput.parse(input), input);
|
|
assert.equal(purchaseOrderInput.safeParse({ ...input, lines: [line, { ...line, materialId: id.toUpperCase() }] }).success, false);
|
|
assert.equal(purchaseOrderInput.safeParse({ ...input, expectedDeliveryDate: "2026-02-31" }).success, false);
|
|
assert.equal(purchaseOrderInput.safeParse({ ...input, lines: [] }).success, false);
|
|
});
|