Skip to content

test: extraction middleware, module registry, and event flow test suites#7

Open
maurcarvalho wants to merge 8 commits intomainfrom
feature/extraction-tests
Open

test: extraction middleware, module registry, and event flow test suites#7
maurcarvalho wants to merge 8 commits intomainfrom
feature/extraction-tests

Conversation

@maurcarvalho
Copy link
Owner

Test Suites for L3 Extraction Infrastructure

Adds 29 new tests covering the extraction mechanism introduced in PR #6.

Unit Tests (npm run test:extraction)

Module Registry (9 tests)

  • Registers all 4 module listeners in monolith mode
  • Skips extracted module listeners (orders, payments, etc.)
  • Always registers event store subscriptions regardless of extraction
  • Supports extracting multiple modules simultaneously
  • Handles whitespace, casing, empty string, unknown module names

Extraction Middleware (13 tests)

  • Returns 410 Gone for routes belonging to extracted modules
  • Passes through routes for non-extracted modules
  • Handles multiple extracted modules
  • Includes module name and service reference in response
  • Edge cases: partial prefix matches, unknown modules

Integration Tests (npm run test:events)

Event Flow (7 tests)

  • EventBus delivers to all subscribers
  • Isolates events between subscriber groups
  • Handles async subscribers
  • Cascading events (module A publishes, module B reacts)
  • Multi-step chain: OrderPlaced > InventoryReserved > OrderConfirmed > PaymentProcessed
  • Singleton isolation after reset

Also includes (from PR #6 base)

  • L3 extraction infrastructure (MODULE_REGISTRY, EXTRACTED_MODULES, middleware)
  • Webpack alias fix for Next.js (/internal subpath resolution)
  • stockQuantity column default fix

Test results

Unit:        22 passed
Integration:  7 passed
Existing:   211 passed (unaffected)
Total:      240 tests

Mauricio Carvalho added 8 commits February 24, 2026 16:40
…ain code

- apps/orders-service/src/main.ts: standalone HTTP server using libs/modules/orders
- apps/orders-service/Dockerfile: multi-stage build for the extracted service
- apps/orders-service/tsconfig.json: extends root, includes shared libs
- apps/orders-service/project.json: Nx project config
- Dockerfile (root): monolith build
- docker-compose.l3.yml: both services running (orders-db + main-db + redis)

Zero domain code duplication. The handlers, entities, and value objects are
identical to the monolith. Only infrastructure wiring differs.
The extracted Orders process is a worker that listens for events
and publishes events. The monolith (or API gateway) continues to
serve REST endpoints. An HTTP layer can be added later if the module
needs an independent API surface (separate team, SLA, deployment cadence).
L3 means fully independent: the extracted Orders service serves
its own HTTP API on port 3001, owns its database, and registers
its own event listeners. This is the whole point of extraction.
- Add Next.js middleware: rejects /api/orders/* with 410 Gone when
  EXTRACTED_MODULES=orders is set
- Update register-listeners.ts: skip orders listeners when extracted
- Set EXTRACTED_MODULES=orders in docker-compose.l3.yml monolith service

Extraction is a configuration change, not a code change.
Each module defines its own registerXxxListeners() function.
The orchestrator loops MODULE_REGISTRARS, skipping any module
listed in EXTRACTED_MODULES. Adding or extracting a module is
a one-line change in one place.
…s, stockQuantity default

- next.config.js: add NormalModuleReplacementPlugin for @tiny-store/* paths
  so Next.js webpack resolves /internal subpath imports
- register-listeners.ts: use static imports instead of require() to avoid
  CommonJS/ESM interop issues in Next.js server components
- product.entity.ts: add default:0 to stockQuantity column
New test categories for L3 extraction infrastructure:

Unit tests (tests/unit/):
- module-registry.spec.ts: validates MODULE_REGISTRY skips extracted
  modules, handles whitespace/casing in EXTRACTED_MODULES, always
  registers event store. Uses jest.isolateModules for clean env.
- extraction-middleware.spec.ts: validates 410 Gone for extracted
  module routes, passthrough for others, response shape.

Integration tests (tests/integration/):
- event-flow.spec.ts: EventBus pub/sub, async handlers, event
  cascading (OrderPlaced → InventoryReserved → OrderConfirmed →
  PaymentProcessed), singleton isolation.

Scripts: npm run test:extraction, npm run test:events

Results: 22 unit + 7 integration = 29 new tests, all passing.
Existing 211 tests unaffected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant