@torquedev/test-helpers
v0.1.0
Published
Test mock factories and integration test helpers for Torque bundles
Downloads
82
Maintainers
Readme
@torquedev/test-helpers
Shared test mock factories for Torque bundles. Zero dependencies. ESM-only.
Install
npm install github:torque-framework/torque-test-helpersAPI
createMockData()
In-memory data store that implements the full Torque BundleScopedData contract. Useful for testing bundle logic without a real database.
| Method | Description |
|--------|-------------|
| insert(table, row) | Insert a row (auto-generates id, created_at, updated_at) |
| find(table, id) | Find a row by ID |
| query(table, filters, opts) | Query rows with filters, ordering, offset, and limit |
| update(table, id, changes) | Update a row by ID |
| delete(table, id) | Delete a row by ID |
| count(table, filters) | Count rows matching a filter |
| transaction(fn) | Run a function in a (no-op) transaction |
Access the underlying store via ._store for test assertions.
createMockEvents()
Captures published events for test assertions.
const events = createMockEvents();
events.publish('pipeline.deal.created', { id: 1 });
assert.equal(events._published.length, 1);
assert.equal(events._published[0].name, 'pipeline.deal.created');createMockCoordinator(responses)
Returns canned responses for coordinator.call() in tests.
const coordinator = createMockCoordinator({
'identity.getUser': (args) => ({ id: args.id, name: 'Alice' }),
});
const user = await coordinator.call('identity', 'getUser', { id: '42' });createSpyCoordinator(responses)
Same as createMockCoordinator but also records every call in ._calls for assertions.
const coordinator = createSpyCoordinator({
'orders.list': () => [{ id: 'o-1' }],
});
await coordinator.call('orders', 'list', { userId: '99' });
assert.equal(coordinator._calls.length, 1);
assert.equal(coordinator._calls[0].bundle, 'orders');
assert.equal(coordinator._calls[0].iface, 'list');Usage
import {
createMockData,
createMockEvents,
createMockCoordinator,
createSpyCoordinator,
} from '@torquedev/test-helpers';Run tests:
node --testLicense
MIT -- see LICENSE
