29 lines
1.5 KiB
TypeScript
29 lines
1.5 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { creditDecisionInput, creditPolicy, creditProposalInput, creditSuspensionInput } from "../src/lib/credit.ts";
|
|
|
|
const id = "d66c798a-f764-4b88-8d13-ace328ff1010";
|
|
const proposal = {
|
|
accountId: id, currency: "INR", creditLimit: "99999999999999.99",
|
|
netDays: 180, rationale: "Established customer", idempotencyKey: id,
|
|
};
|
|
|
|
test("credit terms preserve exact limits and enforce the backend bounds", () => {
|
|
assert.deepEqual(creditProposalInput.parse(proposal), proposal);
|
|
for (const creditLimit of ["100000000000000.00", "0.00", "1.2", "-1.00"]) {
|
|
assert.equal(creditProposalInput.safeParse({ ...proposal, creditLimit }).success, false);
|
|
}
|
|
assert.equal(creditProposalInput.safeParse({ ...proposal, netDays: 0 }).success, false);
|
|
assert.equal(creditProposalInput.safeParse({ ...proposal, netDays: 181 }).success, false);
|
|
assert.equal(creditPolicy.parse({
|
|
...proposal, id, proposedById: id, status: "PROPOSED", createdAt: "2026-11-15T00:00:00Z", events: [],
|
|
}).creditLimit, proposal.creditLimit);
|
|
});
|
|
|
|
test("review and suspension use distinct payloads with a required note", () => {
|
|
const body = { idempotencyKey: id, note: " Reviewed documents " };
|
|
assert.equal(creditDecisionInput.parse({ ...body, decision: "APPROVED" }).note, "Reviewed documents");
|
|
assert.equal(creditSuspensionInput.safeParse({ ...body, decision: "APPROVED" }).success, false);
|
|
assert.equal(creditSuspensionInput.safeParse({ ...body, note: " " }).success, false);
|
|
});
|