Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/AllianceBioversityCIAT/onecgiar_pr/llms.txt

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

PRMS uses Jest for unit and integration testing across both the backend and frontend, and Cypress for end-to-end browser testing on the frontend. All coverage thresholds are enforced in CI — failing to meet them blocks a merge.

Backend testing

The backend uses Jest with ts-jest to transpile TypeScript. Test files are co-located with their source files (e.g., bilateral.service.spec.ts sits next to bilateral.service.ts). End-to-end tests live in the test/ directory and use a separate Jest config (test/jest-e2e.json).

Commands

Run all commands from the onecgiar-pr-server/ directory.
# Run all unit tests (force-exits after completion)
npm run test

# Run with watch mode
npm run test:watch

# Run with coverage report
npm run test:cov

# Run end-to-end tests
npm run test:e2e

Coverage thresholds

The following thresholds are enforced globally. If any threshold is not met, the npm run test:cov command exits with a non-zero code and the CI pipeline fails.
MetricThreshold
Branches5%
Functions20%
Lines35%
Statements40%
These are floors, not targets. New modules should aim for substantially higher coverage. A module spec may raise the bar for its own surface area.

What to test (priority order)

Focus testing effort in this order:
  1. Workflow transitionsstatus_id 1 → 2 → 3 (Editing → Quality Assessed → Submitted) and review history writes.
  2. Bilateral and platform-report payload mappers — test against fixtures; do not mock the mapper itself.
  3. Repositories with non-trivial SQL — pagination, joins, search. Avoid mocking TypeORM where the SQL is the test target.
  4. Guards, middleware, interceptors, filtersValidRoleGuard, JwtMiddleware, ResponseInterceptor, HttpExceptionFilter.
  5. RMQ consumers and cron tasks — verify ACK-on-success behavior and idempotency.
  6. DTO validation — confirm that invalid payloads are rejected and that forbidNonWhitelisted behaves as expected.

Excluded from coverage

The Jest configuration explicitly excludes the following from coverage collection:
  • *.spec.ts and *.e2e-spec.ts
  • *.module.ts
  • *.dto.ts
  • *.entity.ts
  • *.enum.ts
  • *.constant.ts
  • *.routes.ts
  • *.interface.ts
  • index.ts and main.ts
  • migrations/**
  • shared/test/**

Shared test helpers

Shared test factories and mocks live in src/shared/test/. Use this location for any cross-module test fixture rather than duplicating helpers across spec files.

Migration check

Before any merge, the pending migration check must pass:
# Local check — fails if entities have drifted from migrations
npm run migration:check

# CI-friendly version — used by the CI pipeline to block merges
npm run migration:check:ci

CI gates

Every pull request must pass all of the following before it can be merged:
GateCommandWhat it checks
Lintnpm run lintESLint rules in both packages
Unit testsnpm run testAll spec files pass
Buildnpm run buildTypeScript compiles without errors
Migration checknpm run migration:check:ciNo pending TypeORM migrations
SonarCloudAutomatedCode quality and security analysis
The migration check (migration:check:ci) is a hard gate. If your branch adds or modifies entities without a corresponding migration, the CI will fail and the PR cannot merge. Always run npm run migration:check locally before pushing.

Build docs developers (and LLMs) love