29 lines
1.6 KiB
TypeScript
29 lines
1.6 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { materialAdjustment, materialAdjustmentInput, materialTransferInput } from "../src/lib/material-stock.ts";
|
|
|
|
const id = "d66c798a-f764-4b88-8d13-ace328ff1010";
|
|
const warehouseId = "d66c798a-f764-4b88-8d13-ace328ff1011";
|
|
|
|
test("warehouse transfers require distinct locations and positive exact quantities", () => {
|
|
const transfer = { materialId: id, fromWarehouseId: id, toWarehouseId: warehouseId, quantity: "0.125", idempotencyKey: id };
|
|
assert.deepEqual(materialTransferInput.parse(transfer), transfer);
|
|
assert.equal(materialTransferInput.safeParse({ ...transfer, toWarehouseId: id.toUpperCase() }).success, false);
|
|
for (const quantity of ["0.000", "-0.125", "0.12", "01.000"]) {
|
|
assert.equal(materialTransferInput.safeParse({ ...transfer, quantity }).success, false);
|
|
}
|
|
});
|
|
|
|
test("material adjustments preserve exact signed values and require a trimmed reason", () => {
|
|
const input = { materialId: id, warehouseId, delta: "-0.125", reason: " Cycle count ", idempotencyKey: id };
|
|
assert.deepEqual(materialAdjustmentInput.parse(input), { ...input, reason: "Cycle count" });
|
|
for (const delta of ["-0.000", "0.000", "+0.125", "0.1250"]) {
|
|
assert.equal(materialAdjustmentInput.safeParse({ ...input, delta }).success, false);
|
|
}
|
|
assert.equal(materialAdjustmentInput.safeParse({ ...input, reason: " ok " }).success, false);
|
|
const { idempotencyKey: _key, ...record } = input;
|
|
assert.equal(materialAdjustment.parse({
|
|
...record, id, stockItemId: id, createdAt: "2026-11-14T00:00:00.000Z", ledgerEntryId: id,
|
|
}).delta, "-0.125");
|
|
});
|