Skip to main content
Start with tests whose effects you can inspect. The suite below uses the real @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+:
Commit the resulting 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 as commerce.test.mjs:
Success: the runner reports 3 tests, 3 passed, 0 failed, and exits with status 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 expected INSUFFICIENT_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 own Commerce(':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 committing commerce.test.mjs, package.json, and package-lock.json, a GitHub Actions job can run:
This job needs no service credentials. A native-module install failure is a setup failure; fix it before interpreting the result as a commerce behavior regression.

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

Last modified on September 20, 2026