import { test } from "node:test"; import assert from "node:assert/strict"; import { batchSnapshot, bomEstimate, costRate, costRateInput } from "../src/lib/costing.ts"; const id = "d66c798a-f764-4b88-8d13-ace328ff1010"; const date = "2026-11-14T00:00:00.000Z"; const material = { bomLineId: id, materialId: id, materialCode: "WAX", materialName: "Wax", unit: "GRAM", rateId: id, rateRevision: 2, unitCost: "99999999.9999", }; test("standard rates preserve four input decimals and accept serialized revision history", () => { const input = { currency: "INR", unitCost: "0.1250" }; assert.deepEqual(costRateInput.parse(input), input); assert.equal(costRateInput.safeParse({ ...input, unitCost: "0.0000" }).success, false); assert.equal(costRateInput.safeParse({ ...input, unitCost: "0.125" }).success, false); assert.equal(costRateInput.safeParse({ ...input, currency: "JPY" }).success, false); assert.equal(costRate.parse({ ...input, id, materialId: id, revision: 2, createdAt: date, unitCost: "0.125" }).unitCost, "0.125"); }); test("estimates and snapshots preserve exact backend totals and rate references", () => { const estimate = { bomId: id, kind: "PACKAGING", currency: "USD", outputQuantity: 10, estimatedAt: date, estimatedTotal: "9999999999.99", lines: [{ ...material, quantity: "100.000", estimatedCost: "9999999999.99" }], }; assert.deepEqual(bomEstimate.parse(estimate), estimate); const snapshot = { id, batchId: id, currency: "USD", goodQuantity: 0, createdAt: date, productionTotal: "9999999999.99", packagingTotal: "0.00", total: "9999999999.99", lines: [{ ...material, kind: "PRODUCTION", usedQuantity: "100.000", wastedQuantity: "0.000", lineCost: "9999999999.99" }], }; assert.deepEqual(batchSnapshot.parse(snapshot), snapshot); assert.equal(batchSnapshot.safeParse({ ...snapshot, total: 9999999999.99 }).success, false); });