diff --git a/packages/typescript/test/cost-boundaries.test.ts b/packages/typescript/test/cost-boundaries.test.ts new file mode 100644 index 0000000..4b357af --- /dev/null +++ b/packages/typescript/test/cost-boundaries.test.ts @@ -0,0 +1,15 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import {CostObservation} from "../src/index.js"; + +test("cost accepts numeric zero and explicit numeric strings", () => { + for (const amount of [0, "0", 1.25, "1.25"]) { + assert.equal(new CostObservation(amount, "USD", "provider").asEventValue().amount, Number(amount)); + } +}); + +test("cost refuses values that Number would silently coerce", () => { + for (const amount of [true, false, null, [], [1], {}, "", " ", "\t\n"]) { + assert.throws(() => new CostObservation(amount as number, "USD", "provider").asEventValue(), /finite non-negative/); + } +});