Testing
The backend uses three testing layers: Jest unit tests, Jest e2e suites, and live-DB rollback slices (*.e2e.ts in src/). The live-DB slices are the main integration tests because Kysely SQL is best verified against real PostgreSQL.
Jest unit tests
Section titled “Jest unit tests”pnpm test runs Jest against src/**/*.spec.ts.
test/kysely-stub.cjs stubs the ESM-only kysely package so Jest can require it:
class Kysely {}class PostgresDialect {}const sql = () => ({ execute: async () => ({ rows: [] }) });module.exports = { Kysely, PostgresDialect, sql };Unit tests therefore focus on orchestration (services) and pure builders (PDF model builders), not actual SQL.
Jest e2e suite
Section titled “Jest e2e suite”test/jest-e2e.json configures ts-jest with ESM stubs:
{ "testRegex": ".e2e-spec.ts$", "moduleNameMapper": { "^kysely$": "<rootDir>/kysely-stub.cjs", "^puppeteer$": "<rootDir>/puppeteer-stub.cjs" }, "setupFiles": ["<rootDir>/jest-e2e.setup.ts"]}test/jest-e2e.setup.ts disables cron and sets NODE_ENV=test.
Included e2e suites
Section titled “Included e2e suites”test/app.e2e-spec.ts— bootAppModule, verify 401 on/api/v1, 404 on/test/auth.e2e-spec.ts— full auth flow with in-memory repository overrides (login,me, RBAC denial, refresh rotation, logout denylist)
test/puppeteer-stub.cjs prevents Puppeteer from loading in Jest.
Live-DB slices
Section titled “Live-DB slices”Each src/<module>/<module>.e2e.ts is a standalone script run by pnpm db:slice:<module>. They compile a Nest testing module, run operations inside a scope.audit(...) transaction that throws a rollback-marker, then assert the transaction is rolled back.
Slice list
Section titled “Slice list”pnpm db:slice:corepnpm db:slice:clientpnpm db:slice:adminpnpm db:slice:financespnpm db:slice:facturationpnpm db:slice:marketpnpm db:slice:pressingpnpm db:slice:restaurantpnpm db:slice:salle-fetepnpm db:slice:rhpnpm db:slice:auditpnpm db:slice:uploadsSlice pattern
Section titled “Slice pattern”A typical slice:
- Boot
Test.createTestingModule([...]). - Seed test data inside one
scope.audit(actor, async (a, tx) => { ... }). - Read results and assert audit attribution.
- Throw
new Error('rollback-marker'). - Catch the marker and verify nothing persisted.
For example, admin/admin.e2e.ts verifies:
mot_de_passeis not returned by repository readsaudit.journal_auditrows either contain***or do not contain the plaintext password- audit rows are attributed to the acting user
- the test user no longer exists after rollback
Smoke test
Section titled “Smoke test”pnpm db:smoke runs src/db/smoke.ts, which exercises the generated Database type and basic connectivity against a live PostgreSQL instance.
Running the full chain
Section titled “Running the full chain”pnpm db:verifyThis is the recommended command after any schema or backend change. It migrates the sibling database, regenerates types, runs tsc --noEmit, unit tests, smoke tests, and live-DB slices.