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 byDocumentation 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.
ts-jest, keeping the test environment consistent with the production source.
Testing Stack
| Tool | Version | Role |
|---|---|---|
jest | ^29.7.0 | Test runner and assertion library |
ts-jest | ^29.1.1 | TypeScript transformer for Jest |
@nestjs/testing | ^11.0.1 | NestJS TestingModule utilities for DI-aware unit tests |
@types/jest | ^29.5.10 | TypeScript type definitions for Jest globals |
Jest Configuration
The Jest configuration lives insidepackage.json:
rootDir: src— Jest looks for tests only inside thesrc/directory tree.testRegex: .*\.spec\.ts$— any file ending in.spec.tsis treated as a test file.transform—ts-jesthandles TypeScript compilation so tests run without a separate build step.coverageDirectory: ../coverage— HTML and LCOV coverage reports are written to thecoverage/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:watch
Starts Jest in interactive watch mode. Tests re-run automatically when source files change — ideal for test-driven development.
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: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../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 File | Module Under Test | What It Covers |
|---|---|---|
bot.update.spec.ts | BotUpdate | Telegram message handler routing, intent detection, greeting logic |
bot.update.location.spec.ts | BotUpdate | @On('location') handler, proximity search trigger, Yopal geolocation flow |
air-quality.service.spec.ts | AirQualityService | Air quality data retrieval, municipality resolution, chart URL generation |
salud-analitica.service.spec.ts | SaludAnaliticaService | RAG prompt construction, OpenRouter call wiring, response formatting |
antioquia-health.service.spec.ts | AntioquiaHealthService | Provider query, NLP region detection, TypeORM repository interactions |
antioquia-health-precision.spec.ts | AntioquiaHealthService | Edge cases: accent normalization, partial name matching, empty result handling |
mental-health.service.spec.ts | MentalHealthService | CIE-10 diagnosis lookups, age-group aggregations, chart data shaping |
mental-health-questions.service.spec.ts | MentalHealthQuestionsService | Q&A retrieval, keyword matching, fallback responses |
cali-health.service.spec.ts | CaliHealthService | Urgency detection, complexity-level filtering, service-type filtering for Cali |
boyaca-health.service.spec.ts | BoyacaHealthService | Boyacá provider search, municipality filtering, schedule field mapping |
sexual-health.service.spec.ts | SexualHealthService | Sexual health topic routing, answer retrieval, out-of-scope handling |
sexual-health-search.spec.ts | SexualHealthService | Keyword search precision, fuzzy match scenarios |
prediction.service.spec.ts | PredictiveQuestionsService | Risk scoring, event extraction, Holt-Winters series output structure |
salud-publica.service.spec.ts | SaludPublicaService | SIVIGILA query building, comparative analysis, gender/age-group breakdowns |
yopal-health.service.spec.ts | YopalHealthService | Coordinate-based proximity search, radius filtering, provider result mapping |
app.controller.spec.ts | AppController | Root HTTP controller, health-check endpoint |
Writing Tests with @nestjs/testing
NestJS tests useTest.createTestingModule() to instantiate only the providers needed for each spec, with dependencies mocked via jest.fn():
getRepositoryToken:
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 Case | Input Message | Expected Behaviour | Status |
|---|---|---|---|
| Greeting | /start | Personalized 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:| Metric | Target |
|---|---|
| p95 response latency | < 2000 ms |
| Error rate | < 1% |
| Sustained throughput | 10 req/s for 60 s |
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 runningnpm run test:cov, open the HTML report generated in the coverage/ directory: