Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/RubenDarioGuerreroNeira/Ecosistema-IA-Colombia/llms.txt

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

Salud IA Bot ships with a comprehensive Jest test suite that covers individual service units, bot update handler logic, geolocation handling, and domain-specific modules for public health, mental health, sexual health, vaccination, and regional providers. Tests are written in TypeScript and compiled on-the-fly by ts-jest, keeping the test environment consistent with the production source.

Testing Stack

ToolVersionRole
jest^29.7.0Test runner and assertion library
ts-jest^29.1.1TypeScript transformer for Jest
@nestjs/testing^11.0.1NestJS TestingModule utilities for DI-aware unit tests
@types/jest^29.5.10TypeScript type definitions for Jest globals

Jest Configuration

The Jest configuration lives inside package.json:
{
  "jest": {
    "moduleFileExtensions": ["js", "json", "ts"],
    "rootDir": "src",
    "testRegex": ".*\\.spec\\.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": ["**/*.(t|j)s"],
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}
Key points:
  • rootDir: src — Jest looks for tests only inside the src/ directory tree.
  • testRegex: .*\.spec\.ts$ — any file ending in .spec.ts is treated as a test file.
  • transformts-jest handles TypeScript compilation so tests run without a separate build step.
  • coverageDirectory: ../coverage — HTML and LCOV coverage reports are written to the coverage/ folder at the project root.
  • testEnvironment: node — tests run in a plain Node.js environment, not a browser emulation.

Available Test Commands

npm run test

Runs the full unit test suite once. Use this for CI pipelines or a quick sanity check before committing.
npm run test

npm run test:watch

Starts Jest in interactive watch mode. Tests re-run automatically when source files change — ideal for test-driven development.
npm run test:watch

npm run test:cov

Runs all tests and generates a coverage report in the coverage/ directory. Open coverage/lcov-report/index.html in a browser for a detailed view.
npm run test:cov

npm run test:debug

Runs Jest with the Node.js inspector (--inspect-brk) and ts-node pre-registered via tsconfig-paths. Attach a debugger (e.g., VS Code) to step through test code.
npm run test:debug
For end-to-end tests, use a separate config:
npm run test:e2e
This runs Jest with ./test/jest-e2e.json as the configuration file, targeting the test/ directory rather than src/.

Test File Index

All unit test files follow the *.spec.ts naming convention and live alongside their source modules inside src/:
Spec FileModule Under TestWhat It Covers
bot.update.spec.tsBotUpdateTelegram message handler routing, intent detection, greeting logic
bot.update.location.spec.tsBotUpdate@On('location') handler, proximity search trigger, Yopal geolocation flow
air-quality.service.spec.tsAirQualityServiceAir quality data retrieval, municipality resolution, chart URL generation
salud-analitica.service.spec.tsSaludAnaliticaServiceRAG prompt construction, OpenRouter call wiring, response formatting
antioquia-health.service.spec.tsAntioquiaHealthServiceProvider query, NLP region detection, TypeORM repository interactions
antioquia-health-precision.spec.tsAntioquiaHealthServiceEdge cases: accent normalization, partial name matching, empty result handling
mental-health.service.spec.tsMentalHealthServiceCIE-10 diagnosis lookups, age-group aggregations, chart data shaping
mental-health-questions.service.spec.tsMentalHealthQuestionsServiceQ&A retrieval, keyword matching, fallback responses
cali-health.service.spec.tsCaliHealthServiceUrgency detection, complexity-level filtering, service-type filtering for Cali
boyaca-health.service.spec.tsBoyacaHealthServiceBoyacá provider search, municipality filtering, schedule field mapping
sexual-health.service.spec.tsSexualHealthServiceSexual health topic routing, answer retrieval, out-of-scope handling
sexual-health-search.spec.tsSexualHealthServiceKeyword search precision, fuzzy match scenarios
prediction.service.spec.tsPredictiveQuestionsServiceRisk scoring, event extraction, Holt-Winters series output structure
salud-publica.service.spec.tsSaludPublicaServiceSIVIGILA query building, comparative analysis, gender/age-group breakdowns
yopal-health.service.spec.tsYopalHealthServiceCoordinate-based proximity search, radius filtering, provider result mapping
app.controller.spec.tsAppControllerRoot HTTP controller, health-check endpoint

Writing Tests with @nestjs/testing

NestJS tests use Test.createTestingModule() to instantiate only the providers needed for each spec, with dependencies mocked via jest.fn():
import { Test, TestingModule } from '@nestjs/testing';
import { AirQualityService } from './air-quality.service';

describe('AirQualityService', () => {
  let service: AirQualityService;

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      providers: [AirQualityService],
    }).compile();

    service = module.get<AirQualityService>(AirQualityService);
  });

  it('should be defined', () => {
    expect(service).toBeDefined();
  });
});
For services with TypeORM repository dependencies, inject a mock repository using getRepositoryToken:
import { getRepositoryToken } from '@nestjs/typeorm';
import { AntioquiaProvider } from '../entities';

providers: [
  AntioquiaHealthService,
  {
    provide: getRepositoryToken(AntioquiaProvider),
    useValue: {
      find: jest.fn(),
      findOne: jest.fn(),
    },
  },
],

Manual Validation Test Cases

In addition to automated unit tests, the following scenarios should be validated manually by sending messages to a live bot instance connected to the seeded database:
Test CaseInput MessageExpected BehaviourStatus
Greeting/startPersonalized welcome message with user’s first name✅ Implemented
Disease query"¿Cuántos casos de dengue hay en Cali?"SIVIGILA statistics for dengue in Cali✅ Implemented
Air quality chart"Graficar aire en Medellín"Chart image of air quality indicators✅ Implemented
Dynamic chart"¿Puedes graficar aire en Andes?"Chart extracted dynamically for any municipality✅ Implemented
Risk prediction"Predecir riesgo de malaria en Antioquia"Composite risk score with BAJO/MEDIO/ALTO/CRÍTICO classification✅ Implemented
Provider search"Hospitales en Tunja"List of health providers in Tunja, Boyacá✅ Implemented
Comparison"Compara tuberculosis en Cali vs Tuluá"Side-by-side comparison table⚠️ Partial

Stress Testing

For load testing the HTTP health endpoint, Artillery can simulate concurrent traffic:
# Simulate 10 requests/sec for 60 seconds
artillery quick -d 60 -r 10 https://your-bot-url.com/health
Target performance thresholds:
MetricTarget
p95 response latency< 2000 ms
Error rate< 1%
Sustained throughput10 req/s for 60 s
These thresholds reflect the expected performance of the better-sqlite3 synchronous query path combined with the NestJS HTTP layer. Complex analytic queries that invoke the OpenRouter API may push p95 latency toward the 2-5 second range documented in the technical specification.

Coverage Report

After running npm run test:cov, open the HTML report generated in the coverage/ directory:
# macOS
open coverage/lcov-report/index.html

# Linux
xdg-open coverage/lcov-report/index.html
The report breaks down statement, branch, function, and line coverage per file, making it easy to identify undertested service methods.
Run npm run test:cov before any deployment to ensure test coverage is maintained. Coverage reports are saved to the coverage/ directory and can be archived as CI artefacts to track coverage trends across releases.

Build docs developers (and LLMs) love