The failure
parseInt(value, 10) || null
Zero becomes null. A value such as "12pcs" silently becomes 12, and "1.5" becomes 1.
One small transformation bug can turn an out-of-stock quantity into a missing value. Here is the failing example, a precise correction, and the files to reproduce it.
parseInt(value, 10) || null
Zero becomes null. A value such as "12pcs" silently becomes 12, and "1.5" becomes 1.
Validate the entire quantity, then accept only a nonnegative safe integer. Preserve zero and route ambiguous values for review.
Every input row remains visible. Nothing is sent to a store or external service.
These are the bundled fixture results. The replay command verifies the corrected output against expected.json.
| Synthetic input | Original stock / status | Corrected stock / status |
|---|---|---|
"0" | null / review | 0 / ready |
"12" | 12 / ready | 12 / ready |
"" | null / review | null / review |
"12pcs" | 12 / ready | null / review |
"1.5" | 1 / ready | null / review |
"-1" | -1 / ready | null / review |
4, blank SKU | 4 / review | 4 / review |
Save the files below together in one folder. With Node.js 22 or newer, run:
node --test transform.test.mjs
node demonstrate.mjs
Six tests check the original bug, the complete expected output, integer bounds, invalid shapes, non-mutation and repeatable replay. The example needs no packages, accounts, credentials or external calls.
This example assumes whole, nonnegative inventory quantities. Some businesses need fractions or negative inventory; those rules must be agreed before a patch. This sample does not merge duplicate SKUs or perform an import.
Describe one failing path through the existing private intake