Skip to content

Latest commit

Β 

History

History
82 lines (61 loc) Β· 2.2 KB

File metadata and controls

82 lines (61 loc) Β· 2.2 KB

Unit Testing Setup

This project uses Bun's built-in test runner (bun:test) for unit tests.

Quick Start

# Run all tests
bun run test

# Run tests in watch mode
bun run test:watch

# Run tests with coverage
bun run test:coverage

Test Coverage

The tests cover critical utility functions:

Tested Modules (Estimated 29% Coverage)

  • src/utils/messageContentExtractor.ts - Message parsing utilities (100% coverage)
  • src/utils/simpleValidators.ts - Input validation (100% coverage)
  • src/config/env.ts - Environment configuration utilities (60% coverage)

Coverage Breakdown

  • Functions Tested: 15+ core utility functions
  • Test Cases: 71 comprehensive test cases
  • Line Coverage: ~715 lines out of ~24,752 total (~29%)

Key Functions Tested

Message Content Extraction

  • getMessageText() - Extract text from Telegram messages
  • isCommand() - Detect command messages
  • getCommand() - Parse command names
  • getCommandArgs() - Parse command arguments
  • hasTextContent() - Check for text content
  • getMessageTypeInfo() - Message type analysis

Input Validation

  • SimpleInputValidator.validateSummary() - Ticket summary validation
  • SimpleInputValidator.getStats() - Text statistics

Environment Configuration

  • getEnvVar() - Environment variable access
  • isProduction() / isDevelopment() - Environment detection
  • getDefaultTicketPriority() - Priority configuration
  • getCompanyName() - Company name handling
  • getConfiguredBotUsername() - Bot username validation

Test Structure

src/
β”œβ”€β”€ __tests__/
β”‚   β”œβ”€β”€ messageContentExtractor.test.ts
β”‚   β”œβ”€β”€ simpleValidators.test.ts
β”‚   └── env.test.ts
└── [source files...]

Running Tests

# Install dependencies
bun install

# Run tests
bun test

Test Philosophy

These tests focus on:

  • Pure functions - No external dependencies
  • Business logic - Core utility functions
  • Edge cases - Comprehensive input validation
  • Error handling - Proper error scenarios

The tests provide a solid foundation for the project's testing infrastructure and cover the most critical utility functions that power the Telegram bot's core functionality.