32 lines
1.5 KiB
TypeScript
32 lines
1.5 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { invoiceInput, paymentInput } from "../src/lib/supplier-finance.ts";
|
|
|
|
const id = "d66c798a-f764-4b88-8d13-ace328ff1010";
|
|
|
|
test("supplier invoices normalize invoice numbers and retain exact money and quantity strings", () => {
|
|
const line = { purchaseOrderLineId: id, quantity: "0.125" };
|
|
const input = {
|
|
invoiceNumber: " inv/001 ",
|
|
invoiceDate: "2026-11-12",
|
|
taxAmount: "0.01",
|
|
shippingAmount: "0.00",
|
|
lines: [line],
|
|
};
|
|
assert.deepEqual(invoiceInput.parse(input), { ...input, invoiceNumber: "INV/001" });
|
|
assert.equal(invoiceInput.safeParse({ ...input, lines: [line, line] }).success, false);
|
|
assert.equal(invoiceInput.safeParse({ ...input, lines: [{ ...line, quantity: "0.000" }] }).success, false);
|
|
assert.equal(invoiceInput.safeParse({ ...input, taxAmount: "0.001" }).success, false);
|
|
});
|
|
|
|
test("supplier payment input enforces a positive amount, supported method and valid date", () => {
|
|
const input = {
|
|
idempotencyKey: id, reference: " bank/42 ", method: "BANK_TRANSFER",
|
|
amount: "9999999999.99", paidDate: "2026-11-12",
|
|
};
|
|
assert.deepEqual(paymentInput.parse(input), { ...input, reference: "BANK/42" });
|
|
assert.equal(paymentInput.safeParse({ ...input, amount: "0.00" }).success, false);
|
|
assert.equal(paymentInput.safeParse({ ...input, method: "CARD" }).success, false);
|
|
assert.equal(paymentInput.safeParse({ ...input, paidDate: "2026-02-31" }).success, false);
|
|
});
|