@stateset/embedded 1.35.1 package and Node’s built-in test runner to verify stock
reservation, rejection without partial writes, and payment retry identity. It requires no
hosted service, API key, or test framework dependency.
Choose what you are testing
A mocked HTTP response tests your client handling. It does not verify a route, authentication
scope, remote schema, or external side effect. Likewise, completing a local payment record does
not establish that a provider charged a card.
Install the test dependency
Use Node.js 20.20.0+ and npm 10+:package-lock.json in your application and use npm ci in CI. See
SDK installation for native-module and platform troubleshooting.
Run the complete suite
Save this ascommerce.test.mjs:
0.
Timing and output formatting vary by Node version. An assertion failure produces a nonzero
exit code, so CI can fail the build.
Assert what remains unchanged
The rejection test checks three things: the expectedINSUFFICIENT_STOCK code, no created
order, and unchanged stock. Checking only that an exception occurred could pass on an unrelated
error or miss a partial write.
The replay test checks both the returned ID and the stored payment count. A successful second
response alone would not establish that the engine reused the first record.
Keep those assertions when adapting the suite. Add coverage for your own mapping, retry, and
reconciliation decisions, rather than replacing state assertions with log messages.
Keep fixtures isolated
Every test creates its ownCommerce(':memory:'). It does not use your application’s database,
share a mutable customer across tests, or depend on another test running first.
For file-backed persistence tests, allocate a unique temporary directory, use an explicit
database path in each process, and read the record after the writer exits. The
persisted quickstart demonstrates that
second-process check. Its quickstart.db is a teaching filename; do not share one fixed path
among parallel test workers.
Add the suite to CI
After committingcommerce.test.mjs, package.json, and package-lock.json, a GitHub Actions
job can run:
Test a hosted service separately
Use the API directory to select the service’s actual base URL, authentication header, and key. There is no shared sandbox URL or key covering all engines. For a first read check, the developer guide contains JavaScript, Python, and curl requests for the ResponseCX workspace. A successful read verifies access; it does not establish write scope or agent activation. For write tests, use an explicitly selected test workspace and fixtures you own. Save returned IDs, verify persisted fields, and track cleanup according to the endpoint’s supported lifecycle. Check idempotency support per operation before testing retries. Do not wrap an entire test in an automatic retry loop: that can hide the original failure and create additional resources.Troubleshooting
Next steps
- Integration test plan: verify restart recovery and plan hosted and asynchronous checks.
- Error handling and retries: test expected rejections and preserve unexpected failures.
- Customer workflow: test email reuse, explicit updates, and addresses.
- Inventory workflow: verify manual holds and adjustments.
- Payment and refund workflow: add refundable-balance and pending-refund checks.
- Cross-engine errors: use the error contract for the interface you call.