tududi/backend/tests
Chris 4d2ea4212c
Cleanup statuses (#724)
* Cleanup statuses

* Add more statuses

* Hide buttons

* fixup! Hide buttons

* Show subtasks on click

* Fix status button in taskdetails page

* fixup! Fix status button in taskdetails page

* fixup! fixup! Fix status button in taskdetails page

* Fix today planned query
2025-12-19 11:13:27 +02:00
..
helpers Lint and formatting fixes 2025-07-23 12:22:06 +03:00
integration Cleanup statuses (#724) 2025-12-19 11:13:27 +02:00
mocks Add nanoid 2025-08-04 23:50:53 +03:00
unit Feat telegram notifications (#692) 2025-12-09 20:26:53 +02:00
README.md Linting cleanup (#99) 2025-07-01 11:40:09 +03:00

Backend Test Suite

This directory contains the test suite for the tududi backend Express application.

Structure

tests/
├── unit/              # Unit tests for individual components
│   ├── models/        # Model tests
│   ├── middleware/    # Middleware tests
│   └── services/      # Service tests
├── integration/       # Integration tests for API endpoints
├── fixtures/          # Test data fixtures
└── helpers/           # Test utilities and helpers

Running Tests

All Tests

npm test

Unit Tests Only

npm run test:unit

Integration Tests Only

npm run test:integration

Watch Mode (for development)

npm run test:watch

Coverage Report

npm run test:coverage

Test Environment

Tests run in a separate test environment with:

  • In-memory SQLite database (isolated from development data)
  • Test-specific configuration from .env.test
  • Automatic database cleanup between tests

Writing Tests

Unit Tests

  • Test individual functions, models, or middleware in isolation
  • Mock external dependencies
  • Focus on business logic and edge cases

Integration Tests

  • Test complete API endpoints
  • Use authenticated requests where needed
  • Test real database interactions
  • Verify response formats and status codes

Test Utilities

  • tests/helpers/testUtils.js provides utilities for creating test data
  • tests/helpers/setup.js handles database setup and cleanup
  • Use createTestUser() for creating authenticated test users

Best Practices

  1. Isolation: Each test should be independent and not rely on other tests
  2. Cleanup: Database is automatically cleaned between tests
  3. Authentication: Use test utilities for creating authenticated requests
  4. Descriptive Names: Test names should clearly describe what is being tested
  5. Coverage: Aim for high test coverage of critical business logic

Dependencies

  • Jest: Test framework
  • Supertest: HTTP testing library for integration tests
  • cross-env: Cross-platform environment variable setting