Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/J0S3-LEON/pf_pruebasAseguramientoCalid_SDD/llms.txt

Use this file to discover all available pages before exploring further.

MindFlow’s test suite is built around a dual strategy that combines example-based tests with property-based testing (PBT). Example-based tests lock in concrete, known behaviors — a duplicate email returns HTTP 409, a soft-deleted task keeps its micro-objectives — while PBT runs each correctness invariant against hundreds of randomly generated inputs to surface edge cases that hand-written examples cannot anticipate. Together, the two approaches cover every NestJS service, the API gateway envelope, route versioning, serialization round-trips, and the DB writer’s retry and SQL-injection-safety guarantees.

Two-approach overview

Example-based tests

Verify concrete behaviors, known edge cases, and specific error scenarios. Each test uses a carefully chosen fixed input — a duplicate email, an empty task name, a wrong password — and asserts an exact outcome. Faster to write and instantly human-readable, they are the first line of defence against regressions.

Property-based tests (PBT)

Verify universal invariants across hundreds of randomly generated inputs using fast-check. A single property such as “for all valid sessions, deserialize(serialize(session)) == session” exercises the serializer with thousands of UUID combinations, date values, and boolean flags that no human would think to try. fast-check also shrinks any failing input to the minimal counterexample automatically.

Test types matrix

TypeFocusDB requiredTooling
UnitSingle NestJS service in isolation with mocksNoJest 29 + ts-jest, @nestjs/testing
Property-based (PBT)Universal invariants over random inputsNo (in-memory Prisma mock)Jest 29 + fast-check ^3.15.0
IntegrationDB writer latency, Prisma pool config (mocked)NoJest 29 + ts-jest
SmokeDocker config, Prisma schema, route structureNoJest 29 + ts-jest
Route / APIVersioning invariant, response envelopeNo (minimal NestJS test app)Jest 29 + supertest

Test categories

1. Unit tests

Each NestJS service is tested in complete isolation using mocked dependencies. The @nestjs/testing Test.createTestingModule() API wires each service with a partial PrismaService mock so no database connection is ever attempted.
ServiceSpec fileWhat it verifies
AuthServiceauth/__tests__/auth.service.spec.tsDuplicate email → HTTP 409, wrong password → HTTP 401 (generic message), registration response time < 3 s
TaskServicetasks/__tests__/task.service.spec.tsEmpty name → validation error, cross-student access → HTTP 403, soft-delete marks isAuditOnly: true without physical deletion
SessionServicesession/__tests__/session.service.spec.tsEMA prompt text, invalid score → BadRequestException, task-flow transition < 1 s
TaskDecomposerServicetask-decomposer/__tests__/task-decomposer.service.spec.tsshouldDecompose threshold (true iff score ≥ 4), LLM network failure → HTTP 502
DBWriterServicedb-writer/__tests__/db-writer.service.spec.tsSingle retry after 500 ms on PrismaClientKnownRequestError, bootstrap retries PostgreSQL exactly 5 times

2. Property-based tests (PBT)

fast-check generates random inputs for each property and runs the assertion at least 100 times (numRuns: 100). The full catalogue of 27 properties is documented in Property-Based Testing. Key property files:
Spec fileProperties covered
auth/__tests__/auth.property.spec.tsProperties 1–5 (auth round-trip, account uniqueness, JWT 24h expiry, credential rejection, expired JWT)
notification/__tests__/notification.property.spec.tsProperty 18 (exhaustive notification logging)
__tests__/api-gateway.property.spec.tsProperty 22 (response envelope structure)
__tests__/route-versioning.property.spec.tsProperty 23 (all routes under /api/v1/)

3. Integration tests

Integration tests target the DBWriterService and measure write latency and connection pool configuration. The design specification targets an average of 2–3 seconds over 10 consecutive writes under normal load conditions.
  • __tests__/integration/db-writer.latency.spec.ts — measures 10 sequential write operations via a mocked PrismaService and asserts average latency ≤ 3 s; also statically validates Prisma pool settings (connection_limit=10, pool_timeout)
  • Mocked PrismaService resolves immediately — no real database connection is required
  • Can run in parallel with other test suites; --runInBand is not mandatory for this file

4. Smoke tests

Smoke tests are entirely DB-independent and verify static configuration artifacts:
  • __tests__/docker-config.smoke.spec.ts — validates compose.yml: backend and db services defined, no hardcoded JWT_SECRET/AI_SERVICE_API_KEY/DATABASE_URL values, mindflow_pgdata volume declared
  • __tests__/prisma-schema.smoke.spec.ts — validates prisma/schema.prisma: all six Prisma models present, UUID primary keys, FK relations, SmallInt constraints, connection_limit pool setting in prisma.config.ts

5. Route and API tests

Two property spec files bootstrap a minimal NestJS application with the real GlobalExceptionFilter and ResponseInterceptor (no database) and use supertest to fire HTTP requests:
  • __tests__/api-gateway.property.spec.ts — verifies that every response (200, 400, 404, 422, 500) contains the { data, error, status } envelope
  • __tests__/route-versioning.property.spec.ts — introspects the Express router stack after initialisation and asserts that every registered route starts with /api/v1/; random unversioned paths return 404

Test tooling

ToolVersionPurpose
Jest29Test runner for all suites
ts-jestlatestTypeScript compilation for Jest
fast-check^3.15.0Property-based testing library
@nestjs/testingsame as NestJSTest.createTestingModule() for DI isolation
supertestlatestHTTP-level assertions against a live INestApplication
The root jest.config.js is configured in multi-project mode and collects coverage from all workspaces with a 70% minimum threshold on branches, functions, lines, and statements. The backend config sets testTimeout: 60000 to accommodate PBT runs that can take longer than the default 5-second timeout.

Coverage target

Every property must execute with at least 100 iterations:
fc.assert(
  fc.property(/* arbitraries */, (input) => {
    // invariant assertion
  }),
  { numRuns: 100 }
);
Auth and notification PBT suites use a lower numRuns: 5 because each iteration creates a full NestJS TestingModule — the 5-iteration count still covers a wide input space while keeping CI time under 60 seconds per spec file.

Testing scope table

ComponentUnit specPBT specSmoke / Route spec
AuthServiceauth.service.spec.tsauth.property.spec.ts
TaskServicetask.service.spec.ts
SessionServicesession.service.spec.ts
NotificationServicenotification.service.spec.tsnotification.property.spec.ts
TaskDecomposerServicetask-decomposer.service.spec.ts
DBWriterServicedb-writer.service.spec.tsdb-writer.latency.spec.ts
API Gatewayapi-gateway.property.spec.tsroute-versioning.property.spec.ts

Build docs developers (and LLMs) love