Commit aa914e3
committed
feat: refactor testing infrastructure to use test containers and fixtures (#976)
- Rewrite backend/tests/setup/testContainer.ts with full production-ready
test container infrastructure:
* TestContainerManager: full lifecycle (start/stop), in-memory entity store
with seedDatabase, cleanDatabase, createSavepoint/rollbackToSavepoint for
per-test isolation, named takeSnapshot/restoreSnapshot, findById/findAll/
findWhere/upsert/delete/count query helpers
* FixtureLoader: typed factories for all core domain entities (plan, user,
subscription, merchant, invoice) with auto-incrementing IDs, sensible
defaults, and fullSubscriptionScenario() for complete linked graphs
* DatabaseSeeder: fluent builder that inserts in dependency order
(merchants → plans → users → subscriptions → invoices)
* TestClock: deterministic time control with advance/advanceHours/advanceDays
/set/reset for time-sensitive tests
* TestEventBus: in-memory event capture with assertPublished/assertNotPublished
/ofType/last/count for integration assertions without real message brokers
* RedisFixture: tracks keys for automatic cleanup, supports pattern cleanup
* detectFlakyTest: retry-based flakiness detection with pass/fail counts and
error messages
* withTiming + assertWithinMs: performance assertions with configurable limits
* createTestContext: convenience factory wiring all components together
* Exports testContainerManager singleton for backward compatibility
- Expand backend/tests/integration/testContainer.test.ts from 3 smoke tests
to 70+ cases covering all components:
* Lifecycle: start/stop idempotency, initialSeed, data cleared on restart
* Seeding: findById, findAll, findWhere, upsert, delete, count,
cleanDatabase (targeted and full), error on missing id
* Savepoints: rollback restores state, stacking works correctly
* Snapshots: take/restore/getSnapshot, error on unknown id
* FixtureLoader: all factories, overrides, unique IDs, fullSubscriptionScenario
* DatabaseSeeder: dependency ordering, chaining, withRaw
* detectFlakyTest: always-pass, always-fail, intermittent, error capture
* TestClock: advance/hours/days, set, date, iso, reset, chaining
* TestEventBus: publish/ofType/last/count/assert/clear, copy isolation
* RedisFixture: set/get, cleanup, cleanupPattern, trackedCount
* withTiming/assertWithinMs: result passthrough, pass/fail cases
* createTestContext: full lifecycle smoke test
- Update jest.backend.config.js to include backend/tests/**/*.test.ts and
backend/billing/tests/**/*.{test,spec}.ts in testMatch; exclude load/ dir
- Update docs/integration-tests.md with full API reference, usage examples,
per-test isolation pattern, and performance benchmarks
Closes #9761 parent 78d0e80 commit aa914e3
4 files changed
Lines changed: 1510 additions & 142 deletions
File tree
- backend/tests
- integration
- setup
- docs
0 commit comments