Skip to content

Comprehensive Test Suite

Overview

RapidTriageME includes a comprehensive automated test suite that validates all API endpoints, authentication flows, and system functionality. The test suite provides real-time progress tracking, detailed reporting, and visual test results.

Features

🚀 Core Capabilities

  • 41+ Automated Tests covering all critical functionality
  • Real-time Progress Tracking with console progress bars
  • Visual Test Reports with HTML and JSON output
  • Screenshot Capture for failed tests using Puppeteer
  • Expected vs Actual Results comparison
  • Response Header Capture for debugging
  • Category-based Organization for easy navigation

📊 Test Coverage Areas

  1. Authentication (4 tests)
  2. User registration
  3. Login flows
  4. Profile management
  5. Token validation

  6. API Key Management (3 tests)

  7. Key creation
  8. Key listing with pagination
  9. Key revocation

  10. Browser Operations (7 tests)

  11. Screenshot capture (PNG, JPEG, WebP)
  12. Full page screenshots
  13. Custom viewport screenshots
  14. Browser navigation

  15. Debugging Tools (6 tests)

  16. Console log retrieval
  17. Network log analysis
  18. Triage report generation
  19. Log level filtering

  20. Dashboard & Monitoring (3 tests)

  21. Health checks
  22. Metrics collection
  23. Status pages

  24. Error Handling (8 tests)

  25. Invalid credentials
  26. Duplicate registrations
  27. Malformed requests
  28. Token expiration

  29. Documentation (4 tests)

  30. API documentation access
  31. OpenAPI spec (JSON/YAML)
  32. CORS preflight

Running the Test Suite

Basic Execution

# Run all tests
node test-lifecycle.js

# Run with full screenshot capture
CAPTURE_ALL_SCREENSHOTS=true node test-lifecycle.js

# Run against production
TEST_URL=https://api.rapidtriage.me node test-lifecycle.js

Test Output

The test suite provides multiple output formats:

Console Output

  • Real-time progress bar showing test execution
  • Color-coded pass/fail indicators
  • Detailed request/response logging
  • Category-wise progress tracking

HTML Report

  • Interactive visual report
  • Side-by-side expected vs actual results
  • Response headers for each test
  • Screenshot gallery (for failed tests)
  • Category-wise success metrics
  • Execution timeline visualization

JSON Report

  • Machine-readable test results
  • Complete request/response data
  • Timing and performance metrics
  • Suitable for CI/CD integration

Test Report Features

Progress Indicators

Progress: [████████████████████░░░░░░░░░░░░░░░░░░░] 40% (12/30)
  • Real-time console progress bar
  • Visual progress in HTML report
  • Category-wise progress breakdown
  • Execution timeline with timestamps

Expected vs Actual Results

Each test displays: - Expected Result: Status code and description - Actual Result: Real response data - Match Status: Pass/fail determination - Response Headers: Full header capture

Screenshot Capture

  • Automatic screenshots for failed tests
  • Optional full screenshot mode
  • Puppeteer-based browser automation
  • Visual test result cards

Viewing Test Results

Serve HTML Report

# Start report server
node serve-report.js

# View at http://localhost:8080

View Summary

# Display test summary
node view-test-summary.js

Direct File Access

Reports are saved in the reports/ directory: - test-report-TIMESTAMP.html - Visual report - test-report-TIMESTAMP.json - Raw data

Test Categories

Authentication Tests

  • User registration with validation
  • Login with credentials
  • Profile retrieval and updates
  • Token refresh flows

API Key Tests

  • Create keys with permissions
  • List keys with pagination
  • Revoke keys
  • Permission validation

Browser Operation Tests

  • Screenshot capture formats
  • Full page captures
  • Custom viewport sizes
  • Navigation commands

Debugging Tests

  • Console log retrieval
  • Network analysis
  • Error tracking
  • Performance metrics

Error Handling Tests

  • Invalid credentials
  • Duplicate registrations
  • Malformed requests
  • Rate limiting
  • Token expiration

Integration with CI/CD

GitHub Actions

name: API Tests
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
      - run: npm install
      - run: node test-lifecycle.js
      - uses: actions/upload-artifact@v2
        if: always()
        with:
          name: test-reports
          path: reports/

Exit Codes

  • 0 - All tests passed
  • 1 - One or more tests failed
  • 2 - Test suite error

Custom Test Configuration

Environment Variables

# API endpoint
TEST_URL=http://localhost:8787

# Screenshot capture
CAPTURE_ALL_SCREENSHOTS=true

# Test credentials
TEST_EMAIL=[email protected]
TEST_PASSWORD=SecurePass123!

Test Customization

Edit test-lifecycle.js to: - Add new test cases - Modify test categories - Adjust timeouts - Change report formats

Performance Metrics

Typical test execution times: - Full suite: ~1 second - Average per test: 10-15ms - Screenshot capture: 50-100ms - Report generation: <100ms

Troubleshooting

Common Issues

  1. Tests timing out
  2. Check network connectivity
  3. Verify API is running
  4. Increase timeout values

  5. Screenshot failures

  6. Ensure Puppeteer is installed
  7. Check system resources
  8. Verify Chrome/Chromium availability

  9. Report not displaying

  10. Use serve-report.js for proper serving
  11. Check file permissions
  12. Verify browser compatibility

Best Practices

  1. Run tests regularly
  2. Before deployments
  3. After configuration changes
  4. As part of CI/CD pipeline

  5. Monitor trends

  6. Track execution times
  7. Watch for flaky tests
  8. Identify performance regressions

  9. Maintain test data

  10. Use unique test emails
  11. Clean up test artifacts
  12. Rotate API keys

Advanced Features

Parallel Execution

Future enhancement for faster test runs:

// Planned feature
const testRunner = new ParallelTestRunner({
  workers: 4,
  categories: ['auth', 'api', 'browser', 'debug']
});

Custom Reporters

Extend reporting capabilities:

class SlackReporter {
  async report(results) {
    // Send results to Slack
  }
}

Test Data Management

Automated test data cleanup:

async function cleanupTestData() {
  // Remove test users
  // Revoke test API keys
  // Clear test screenshots
}

Summary

The RapidTriageME test suite provides comprehensive validation of all system functionality with advanced reporting and visualization capabilities. Regular test execution ensures system reliability and helps identify issues early in the development cycle.